Skip to content

Commit 6382f62

Browse files
committed
refactor(search): centralize pf search, get resources
* options.defaults, refactor for initial pf versions * pf.getResources, api prep, centralize all pf related data * pf.helpers, pf versions from options, disable findClosestPFVersion * pf.search, refactor, centralize pf search
1 parent 1df4434 commit 6382f62

12 files changed

Lines changed: 1189 additions & 30 deletions

jest.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export default {
3232
{
3333
...tsConfig,
3434
diagnostics: {
35-
ignoreCodes: [1343]
35+
// See codes https://github.com/Microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
36+
// 1324 - Dynamic imports only support a second argument when the '--module' option is...
37+
// 1343 - The 'import.meta' meta-property is only allowed when the '--module' option is...
38+
ignoreCodes: [1324, 1343]
3639
},
3740
astTransformers: {
3841
before: [

src/__tests__/__snapshots__/options.defaults.test.ts.snap

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,18 @@ exports[`options defaults should return specific properties: defaults 1`] = `
3434
"availableResourceVersions": [
3535
"6.0.0",
3636
],
37+
"availableSchemasVersions": [
38+
"v6",
39+
],
40+
"availableSearchVersions": [
41+
"current",
42+
"latest",
43+
"v6",
44+
],
3745
"default": {
38-
"defaultVersion": "6.0.0",
46+
"latestSchemasVersion": "v6",
47+
"latestSemVer": "6.0.0",
48+
"latestVersion": "v6",
3949
"versionStrategy": "highest",
4050
"versionWhitelist": [
4151
"@patternfly/react-core",
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`getPatternFlyMcpResources should return multiple organized facets: properties 1`] = `
4+
[
5+
"availableSemVer",
6+
"availableVersions",
7+
"availableSchemasVersions",
8+
"enumeratedVersions",
9+
"envSemVer",
10+
"envVersion",
11+
"latestVersion",
12+
"latestSchemasVersion",
13+
"isEnvTheLatestVersion",
14+
"isEnvTheLatestSchemasVersion",
15+
"resources",
16+
"docsIndex",
17+
"componentsIndex",
18+
"keywordsIndex",
19+
"isFallbackDocumentation",
20+
"pathIndex",
21+
"byPath",
22+
"byUri",
23+
"byVersion",
24+
"byVersionComponentNames",
25+
]
26+
`;
27+
28+
exports[`getPatternFlyReactComponentNames should return multiple organized facets: properties 1`] = `
29+
[
30+
"byVersion",
31+
"componentNamesIndex",
32+
"componentNamesWithSchemasIndex",
33+
"componentNamesWithSchemasMap",
34+
]
35+
`;
36+
37+
exports[`setCategoryDisplayLabel should normalize categories and apply linking markdown, accessibility 1`] = `"Accessibility"`;
38+
39+
exports[`setCategoryDisplayLabel should normalize categories and apply linking markdown, design 1`] = `"Design Guidelines"`;
40+
41+
exports[`setCategoryDisplayLabel should normalize categories and apply linking markdown, empty string 1`] = `"Documentation"`;
42+
43+
exports[`setCategoryDisplayLabel should normalize categories and apply linking markdown, example 1`] = `"Examples"`;
44+
45+
exports[`setCategoryDisplayLabel should normalize categories and apply linking markdown, guidelines 1`] = `"AI Guidance"`;
46+
47+
exports[`setCategoryDisplayLabel should normalize categories and apply linking markdown, null 1`] = `"Documentation"`;
48+
49+
exports[`setCategoryDisplayLabel should normalize categories and apply linking markdown, undefined 1`] = `"Documentation"`;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`filterEnumeratedPatternFlyVersions should attempt to refine a PatternFly versions based on available enumerations, current 1`] = `
4+
[
5+
"v6",
6+
]
7+
`;
8+
9+
exports[`filterEnumeratedPatternFlyVersions should attempt to refine a PatternFly versions based on available enumerations, detected 1`] = `
10+
[
11+
"v6",
12+
]
13+
`;
14+
15+
exports[`filterEnumeratedPatternFlyVersions should attempt to refine a PatternFly versions based on available enumerations, empty 1`] = `
16+
[
17+
"current",
18+
"latest",
19+
"v6",
20+
]
21+
`;
22+
23+
exports[`filterEnumeratedPatternFlyVersions should attempt to refine a PatternFly versions based on available enumerations, exact semver 1`] = `
24+
[
25+
"v6",
26+
]
27+
`;
28+
29+
exports[`filterEnumeratedPatternFlyVersions should attempt to refine a PatternFly versions based on available enumerations, latest 1`] = `
30+
[
31+
"v6",
32+
]
33+
`;
34+
35+
exports[`filterEnumeratedPatternFlyVersions should attempt to refine a PatternFly versions based on available enumerations, null 1`] = `
36+
[
37+
"current",
38+
"latest",
39+
"v6",
40+
]
41+
`;
42+
43+
exports[`filterEnumeratedPatternFlyVersions should attempt to refine a PatternFly versions based on available enumerations, semver 1`] = `
44+
[
45+
"v6",
46+
]
47+
`;
48+
49+
exports[`filterEnumeratedPatternFlyVersions should attempt to refine a PatternFly versions based on available enumerations, tag 1`] = `
50+
[
51+
"v6",
52+
]
53+
`;
54+
55+
exports[`filterEnumeratedPatternFlyVersions should attempt to refine a PatternFly versions based on available enumerations, unavailable exact semver 1`] = `
56+
[
57+
"current",
58+
"latest",
59+
"v6",
60+
]
61+
`;
62+
63+
exports[`filterEnumeratedPatternFlyVersions should attempt to refine a PatternFly versions based on available enumerations, unavailable semver 1`] = `
64+
[
65+
"current",
66+
"latest",
67+
"v6",
68+
]
69+
`;
70+
71+
exports[`filterEnumeratedPatternFlyVersions should attempt to refine a PatternFly versions based on available enumerations, unavailable tag 1`] = `
72+
[
73+
"current",
74+
"latest",
75+
"v6",
76+
]
77+
`;
78+
79+
exports[`filterEnumeratedPatternFlyVersions should attempt to refine a PatternFly versions based on available enumerations, undefined 1`] = `
80+
[
81+
"current",
82+
"latest",
83+
"v6",
84+
]
85+
`;
86+
87+
exports[`getPatternFlyVersionContext should temporarily return option.defaults and latest versions with specific properties: keys 1`] = `
88+
[
89+
"availableSemVer",
90+
"availableVersions",
91+
"availableSchemasVersions",
92+
"enumeratedVersions",
93+
"envSemVer",
94+
"envVersion",
95+
"latestVersion",
96+
"latestSchemasVersion",
97+
"isEnvTheLatestVersion",
98+
"isEnvTheLatestSchemasVersion",
99+
]
100+
`;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`searchPatternFly should attempt to return an array of all available results, all search: keys 1`] = `
4+
[
5+
"isSearchWildCardAll",
6+
"firstExactMatch",
7+
"exactMatches",
8+
]
9+
`;
10+
11+
exports[`searchPatternFly should attempt to return an array of all available results, empty all search: keys 1`] = `
12+
[
13+
"isSearchWildCardAll",
14+
"firstExactMatch",
15+
"exactMatches",
16+
]
17+
`;
18+
19+
exports[`searchPatternFly should attempt to return an array of all available results, wildcard search: keys 1`] = `
20+
[
21+
"isSearchWildCardAll",
22+
"firstExactMatch",
23+
"exactMatches",
24+
]
25+
`;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import {
2+
setCategoryDisplayLabel,
3+
getPatternFlyComponentSchema,
4+
getPatternFlyReactComponentNames,
5+
getPatternFlyMcpResources
6+
} from '../patternFly.getResources';
7+
8+
describe('setCategoryDisplayLabel', () => {
9+
it.each([
10+
{
11+
description: 'empty string',
12+
entry: ''
13+
},
14+
{
15+
description: 'undefined',
16+
entry: undefined
17+
},
18+
{
19+
description: 'null',
20+
entry: null
21+
},
22+
{
23+
description: 'design',
24+
entry: {
25+
displayName: 'Lorem Ipsum',
26+
section: 'components',
27+
category: 'design-guidelines',
28+
path: 'https://www.patternfly.org/v6/components/lorem-ipsum/design-guidelines'
29+
}
30+
},
31+
{
32+
description: 'accessibility',
33+
entry: {
34+
displayName: 'Dolor Sit',
35+
section: 'components',
36+
category: 'accessibility',
37+
path: 'https://www.patternfly.org/v6/components/dolor-sit/accessibility'
38+
}
39+
},
40+
{
41+
description: 'example',
42+
entry: {
43+
displayName: 'Lorem Sit',
44+
section: 'components',
45+
category: 'react',
46+
path: 'https://www.patternfly.org/v6/components/lorem-sit/components'
47+
}
48+
},
49+
{
50+
description: 'guidelines',
51+
entry:
52+
{
53+
displayName: 'Sit Sit',
54+
section: 'guidelines',
55+
category: 'react',
56+
path: 'documentation:components/sit-sit/guidelines.md'
57+
}
58+
}
59+
])('should normalize categories and apply linking markdown, $description', ({ entry }) => {
60+
expect(setCategoryDisplayLabel(entry as any)).toMatchSnapshot();
61+
});
62+
});
63+
64+
describe('getPatternFlyComponentSchema', () => {
65+
it.each([
66+
{
67+
description: 'default',
68+
componentName: 'Button',
69+
expected: true
70+
},
71+
{
72+
description: 'unknown component',
73+
componentName: 'Lorem',
74+
expected: false
75+
}
76+
])('should attempt to return a schema', async ({ componentName, expected }) => {
77+
const output = await getPatternFlyComponentSchema(componentName);
78+
79+
expect(Boolean(output)).toBe(expected);
80+
});
81+
82+
it('should have a memoized property', () => {
83+
expect(getPatternFlyComponentSchema).toHaveProperty('memo');
84+
});
85+
});
86+
87+
describe('getPatternFlyReactComponentNames', () => {
88+
it('should return multiple organized facets', async () => {
89+
const result = await getPatternFlyReactComponentNames();
90+
91+
expect(Object.keys(result)).toMatchSnapshot('properties');
92+
});
93+
94+
it('should have a memoized property', () => {
95+
expect(getPatternFlyReactComponentNames).toHaveProperty('memo');
96+
});
97+
});
98+
99+
describe('getPatternFlyMcpResources', () => {
100+
it('should return multiple organized facets', async () => {
101+
const result = await getPatternFlyMcpResources();
102+
103+
expect(Object.keys(result)).toMatchSnapshot('properties');
104+
});
105+
106+
it('should have a memoized property', async () => {
107+
expect(getPatternFlyMcpResources).toHaveProperty('memo');
108+
});
109+
});

0 commit comments

Comments
 (0)