-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathresource.patternFlyDocsIndex.test.ts
More file actions
81 lines (72 loc) · 2.37 KB
/
resource.patternFlyDocsIndex.test.ts
File metadata and controls
81 lines (72 loc) · 2.37 KB
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
76
77
78
79
80
81
import { patternFlyDocsIndexResource } from '../resource.patternFlyDocsIndex';
import { getLocalDocs } from '../docs.local';
import { isPlainObject } from '../server.helpers';
jest.mock('../docs.local');
jest.mock('../server.caching', () => ({
memo: jest.fn(fn => fn)
}));
jest.mock('../api.client', () => ({
getComponentList: Object.assign(
jest.fn(async () => ['Alert', 'Button', 'Card']),
{ memo: jest.fn(async () => ['Alert', 'Button', 'Card']) }
),
getComponentInfo: Object.assign(
jest.fn(async (name: string) => ({
name,
section: 'components',
page: name.toLowerCase(),
tabs: ['react'],
hasProps: true,
hasCss: false,
exampleCount: 0
})),
{
memo: jest.fn(async (name: string) => ({
name,
section: 'components',
page: name.toLowerCase(),
tabs: ['react'],
hasProps: true,
hasCss: false,
exampleCount: 0
}))
}
)
}));
const mockGetLocalDocs = getLocalDocs as jest.MockedFunction<typeof getLocalDocs>;
describe('patternFlyDocsIndexResource', () => {
beforeEach(() => {
jest.clearAllMocks();
mockGetLocalDocs.mockReturnValue(['[@patternfly/react-guidelines](./guidelines/README.md)']);
});
it('should have a consistent return structure', () => {
const resource = patternFlyDocsIndexResource();
expect({
name: resource[0],
uri: resource[1],
config: isPlainObject(resource[2]),
handler: resource[3]
}).toMatchSnapshot('structure');
});
});
describe('patternFlyDocsIndexResource, callback', () => {
beforeEach(() => {
jest.clearAllMocks();
mockGetLocalDocs.mockReturnValue(['[@patternfly/react-guidelines](./guidelines/README.md)']);
});
it.each([
{
description: 'default',
args: []
}
])('should return context content, $description', async ({ args }) => {
const [_name, _uri, _config, callback] = patternFlyDocsIndexResource();
const result = await callback(...args);
expect(result.contents).toBeDefined();
expect(Object.keys(result.contents[0])).toEqual(['uri', 'mimeType', 'text']);
expect(result.contents[0].text).toContain('[@patternfly/react-guidelines](./guidelines/README.md)');
expect(result.contents[0].text).toContain('Alert');
expect(result.contents[0].text).toContain('Button');
expect(result.contents[0].text).toContain('Card');
});
});