generated from RedHatInsights/frontend-starter-app
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjest.setup.ts
75 lines (70 loc) · 1.75 KB
/
jest.setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import '@testing-library/jest-dom';
import 'jest';
import { expect } from '@jest/globals';
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
interface Matchers {
toHaveLoader(): CustomMatcherResult;
}
}
}
const toHaveLoader = (obj: any) => {
if (obj.queryByRole('progressbar')) {
return {
message: () => 'Must have loader with role "progressbar"',
pass: true
};
} else {
return {
message: () => 'Must have loader with role "progressbar"',
pass: false
};
}
};
let mocki = 0;
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
__esModule: true,
default: () => ({
hideGlobalFilter: jest.fn(),
updateDocumentTitle: jest.fn(),
auth: {
getToken: () => Promise.resolve('TOKEN'),
getUser: () =>
Promise.resolve({
identity: {
account_number: '0',
type: 'User',
user: {
is_org_admin: true,
email: '[email protected]'
}
},
entitlements: {
hybrid_cloud: { is_entitled: true },
insights: { is_entitled: true },
openshift: { is_entitled: true },
smart_management: { is_entitled: false }
}
})
},
appAction: jest.fn(),
appObjectId: jest.fn(),
on: jest.fn(),
getUserPermissions: () =>
Promise.resolve([
{ resourceDefinitions: [], permission: 'subscriptions:manifests:read' },
{ resourceDefinitions: [], permission: 'subscriptions:manifests:write' }
]),
getEnvironment: () => {
if (!mocki) {
mocki++;
return 'qa';
}
return null;
}
})
}));
expect.extend({
toHaveLoader
});