Skip to content

Commit 96de7dd

Browse files
committed
tests
1 parent 2839ee9 commit 96de7dd

File tree

12 files changed

+114
-81
lines changed

12 files changed

+114
-81
lines changed

packages/dev/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"i18next-browser-languagedetector": "^6.0.1",
2020
"i18next-parser": "^3.3.0",
2121
"i18next-pseudo": "^2.2.0",
22-
"react-i18next": "^11.7.3"
22+
"react-i18next": "^11.7.3",
23+
"showdown": "1.8.6"
2324
},
2425
"devDependencies": {
2526
"@types/react": "^16.8.0",

packages/dev/src/App.tsx

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ import Demos from "./Demos";
1717
import "./App.css";
1818
import {
1919
QuickStartDrawer,
20-
QuickStartContext,
21-
useValuesForQuickStartContext,
2220
useLocalStorage,
21+
QuickStartContextProvider,
22+
QuickStartContextValues,
23+
LoadingBox
2324
} from "@patternfly/quickstarts";
2425
import { allQuickStarts as yamlQuickStarts } from "./quickstarts-data/quick-start-test-data";
2526
import { loadJSONQuickStarts } from "./quickstarts-data/mas-guides/quickstartLoader";
27+
import i18n from './i18n/i18n';
2628

2729
type AppProps = {
2830
children?: React.ReactNode;
@@ -64,25 +66,6 @@ const App: React.FC<AppProps> = ({ children, showCardFooters }) => {
6466
load();
6567
}, []);
6668

67-
const { pathname: currentPath } = window.location;
68-
const quickStartPath = "/quickstarts";
69-
70-
const valuesForQuickstartContext = useValuesForQuickStartContext({
71-
allQuickStarts,
72-
activeQuickStartID,
73-
setActiveQuickStartID,
74-
allQuickStartStates,
75-
setAllQuickStartStates,
76-
footer: {
77-
show: showCardFooters,
78-
showAllLink: currentPath !== quickStartPath,
79-
onShowAllLinkClick: () => history.push(quickStartPath),
80-
},
81-
text: {
82-
"Start": "Let's goooo"
83-
}
84-
});
85-
8669
if (!initialized) return <div>Loading</div>;
8770

8871
const AppToolbar = (
@@ -120,18 +103,40 @@ const App: React.FC<AppProps> = ({ children, showCardFooters }) => {
120103

121104
const AppSidebar = <PageSidebar isNavOpen nav={AppNav} />;
122105

106+
const { pathname: currentPath } = window.location;
107+
const quickStartPath = "/quickstarts";
108+
109+
const resourceBundle = i18n.getResourceBundle(localStorage.getItem('bridge/language'), 'quickstart');
110+
111+
const valuesForQuickstartContext: QuickStartContextValues = {
112+
allQuickStarts,
113+
activeQuickStartID,
114+
setActiveQuickStartID,
115+
allQuickStartStates,
116+
setAllQuickStartStates,
117+
footer: {
118+
show: showCardFooters,
119+
showAllLink: currentPath !== quickStartPath,
120+
onShowAllLinkClick: () => history.push(quickStartPath),
121+
},
122+
lng: localStorage.getItem('bridge/language'),
123+
resourceBundle: {
124+
...resourceBundle,
125+
"Start": "Let's goooo"
126+
},
127+
useQueryParams: false
128+
};
129+
123130
return (
124-
<React.Suspense fallback={<div>Loading</div>}>
131+
<React.Suspense fallback={<LoadingBox />}>
125132
{allQuickStartsLoaded && (
126-
<QuickStartContext.Provider value={{
127-
...valuesForQuickstartContext
128-
}}>
133+
<QuickStartContextProvider value={valuesForQuickstartContext}>
129134
<QuickStartDrawer>
130-
<Page header={AppHeader} sidebar={AppSidebar} isManagedSidebar>
135+
<Page header={AppHeader} sidebar={AppSidebar} isManagedSidebar>
131136
{children}
132-
</Page>
133-
</QuickStartDrawer>
134-
</QuickStartContext.Provider>
137+
</Page>
138+
</QuickStartDrawer>
139+
</QuickStartContextProvider>
135140
)}
136141
</React.Suspense>
137142
);

packages/dev/src/CustomCatalog.tsx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,23 @@ import {
1212
QUICKSTART_SEARCH_FILTER_KEY,
1313
QUICKSTART_STATUS_FILTER_KEY,
1414
QuickStartCatalogFilterSearchWrapper,
15-
QuickStartCatalogFilterStatusWrapper,
1615
QuickStartCatalogFilterCountWrapper,
1716
clearQuickStartFilters,
1817
QuickStartCatalogHeader,
1918
QuickStartCatalogToolbar,
2019
QuickStartCatalogSection,
2120
} from '@patternfly/quickstarts';
2221
import {
23-
PageSection,
24-
PageSectionVariants,
2522
TextContent,
2623
Text,
2724
Divider,
2825
Gallery,
2926
GalleryItem,
30-
Toolbar,
3127
ToolbarContent,
3228
} from '@patternfly/react-core';
3329

34-
type CustomCatalogProps = {
35-
quickStarts: QuickStart[];
36-
};
37-
38-
export const CustomCatalog: React.FC<CustomCatalogProps> = ({ quickStarts }) => {
39-
const { activeQuickStartID, allQuickStartStates } = React.useContext<QuickStartContextValues>(
30+
export const CustomCatalog: React.FC = () => {
31+
const { activeQuickStartID, allQuickStartStates, allQuickStarts } = React.useContext<QuickStartContextValues>(
4032
QuickStartContext,
4133
);
4234

@@ -50,7 +42,7 @@ export const CustomCatalog: React.FC<CustomCatalogProps> = ({ quickStarts }) =>
5042
const sortFnc = (q1: QuickStart, q2: QuickStart) =>
5143
q1.spec.displayName.localeCompare(q2.spec.displayName);
5244
const initialFilteredQuickStarts = filterQuickStarts(
53-
quickStarts,
45+
allQuickStarts,
5446
initialSearchQuery,
5547
initialStatusFilters,
5648
allQuickStartStates,
@@ -60,12 +52,12 @@ export const CustomCatalog: React.FC<CustomCatalogProps> = ({ quickStarts }) =>
6052
);
6153

6254
const quickStartStatusCount = React.useMemo(
63-
() => getQuickStartStatusCount(allQuickStartStates, quickStarts),
64-
[allQuickStartStates, quickStarts],
55+
() => getQuickStartStatusCount(allQuickStartStates, allQuickStarts),
56+
[allQuickStartStates, allQuickStarts],
6557
);
6658
const onSearchInputChange = (searchValue: string) => {
6759
const result = filterQuickStarts(
68-
quickStarts,
60+
allQuickStarts,
6961
searchValue,
7062
statusFilters,
7163
allQuickStartStates,
@@ -75,7 +67,7 @@ export const CustomCatalog: React.FC<CustomCatalogProps> = ({ quickStarts }) =>
7567
};
7668
const onStatusChange = (statusList: string[]) => {
7769
const result = filterQuickStarts(
78-
quickStarts,
70+
allQuickStarts,
7971
searchInputText,
8072
statusList,
8173
allQuickStartStates,
@@ -92,7 +84,7 @@ export const CustomCatalog: React.FC<CustomCatalogProps> = ({ quickStarts }) =>
9284
<Text component="p">Step-by-step instructions and tasks</Text>
9385
</TextContent>
9486
<Gallery className="co-quick-start-catalog__gallery" hasGutter>
95-
{quickStarts
87+
{allQuickStarts
9688
.filter(
9789
(quickStart) =>
9890
!quickStart.spec.type || quickStart.spec.type.text !== 'Documentation',
@@ -123,7 +115,7 @@ export const CustomCatalog: React.FC<CustomCatalogProps> = ({ quickStarts }) =>
123115
<Text component="p">Technical information for using the service</Text>
124116
</TextContent>
125117
<Gallery className="co-quick-start-catalog__gallery" hasGutter>
126-
{quickStarts
118+
{allQuickStarts
127119
.filter((quickStart) => quickStart.spec.type?.text === 'Documentation')
128120
.map((quickStart) => {
129121
const {
@@ -148,7 +140,7 @@ export const CustomCatalog: React.FC<CustomCatalogProps> = ({ quickStarts }) =>
148140
const clearFilters = () => {
149141
clearQuickStartFilters();
150142
setFilteredQuickStarts(
151-
quickStarts.sort((q1, q2) => q1.spec.displayName.localeCompare(q2.spec.displayName)),
143+
allQuickStarts.sort((q1, q2) => q1.spec.displayName.localeCompare(q2.spec.displayName)),
152144
);
153145
};
154146

@@ -169,7 +161,7 @@ export const CustomCatalog: React.FC<CustomCatalogProps> = ({ quickStarts }) =>
169161
<Divider component="div" />
170162
{filteredQuickStarts.length === 0 ? (
171163
<QuickStartCatalogEmptyState clearFilters={clearFilters} />
172-
) : filteredQuickStarts.length !== quickStarts.length ? (
164+
) : filteredQuickStarts.length !== allQuickStarts.length ? (
173165
<QuickStartCatalogSection>
174166
<QuickStartCatalog quickStarts={filteredQuickStarts} />
175167
</QuickStartCatalogSection>

packages/dev/src/Home.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from "react";
22
import { Button, PageSection, Stack, StackItem } from "@patternfly/react-core";
33
import {
4-
QuickStartContext,
5-
QuickStartContextValues,
4+
QuickStartContext
65
} from "@patternfly/quickstarts";
76
import i18n from './i18n/i18n';
87
// import {
@@ -15,7 +14,7 @@ import i18n from './i18n/i18n';
1514

1615
export const Home: React.FunctionComponent = () => {
1716
// const [inputValue, setInputValue] = React.useState("");
18-
const qsContext: QuickStartContextValues = React.useContext(QuickStartContext);
17+
const { setLng, setResourceBundle } = React.useContext(QuickStartContext);
1918

2019
// console.log(getQuickStartStatus(qsContext.allQuickStartStates, 'managing-business-central-data-sources-proc'));
2120
// console.log(getQuickStartStatusCount(qsContext.allQuickStartStates, qsContext.allQuickStarts));
@@ -50,7 +49,9 @@ export const Home: React.FunctionComponent = () => {
5049
const changeLanguage = (lng: string) => {
5150
i18n.changeLanguage(lng);
5251
localStorage.setItem('bridge/language', lng);
53-
// qsContext.setText(i18n.getResourceBundle(lng, 'quickstart'));
52+
const resourceBundle = i18n.getResourceBundle(lng, 'quickstart');
53+
setLng(lng);
54+
setResourceBundle(resourceBundle);
5455
}
5556

5657
return (

packages/dev/src/index.tsx

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
99
import './i18n/i18n';
1010
import App from "./App";
1111
import {
12-
QuickStartsLoader,
1312
QuickStartCatalogPage,
1413
QuickStart,
1514
LoadingBox,
@@ -27,32 +26,15 @@ ReactDOM.render(
2726
</Route>
2827
<Route exact path="/quickstarts">
2928
<App showCardFooters={false}>
30-
<QuickStartsLoader>
31-
{(quickStarts: QuickStart[], loaded: boolean) =>
32-
loaded ? (
33-
<QuickStartCatalogPage
34-
quickStarts={quickStarts}
35-
showFilter
36-
hint="Learn how to create, import, and run applications with step-by-step instructions and tasks."
37-
/>
38-
) : (
39-
<LoadingBox />
40-
)
41-
}
42-
</QuickStartsLoader>
29+
<QuickStartCatalogPage
30+
showFilter
31+
hint="Learn how to create, import, and run applications with step-by-step instructions and tasks."
32+
/>
4333
</App>
4434
</Route>
4535
<Route exact path="/custom-catalog">
4636
<App showCardFooters>
47-
<QuickStartsLoader>
48-
{(quickStarts: QuickStart[], loaded: boolean) =>
49-
loaded ? (
50-
<CustomCatalog quickStarts={quickStarts} />
51-
) : (
52-
<LoadingBox />
53-
)
54-
}
55-
</QuickStartsLoader>
37+
<CustomCatalog />
5638
</App>
5739
</Route>
5840
</Switch>

packages/module/src/ConsoleShared/src/components/popper/Popper.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
2-
import PopperJS, { PopperOptions } from 'popper.js/dist/esm/popper.min.js';
2+
// popper.js/dist/esm/popper.min.js for smaller bundle? but jest won't like it
3+
import PopperJS, { PopperOptions } from 'popper.js';
34
import { useCombineRefs } from '../../utils/useCombineRefs';
45
import Portal from './Portal';
56

packages/module/src/catalog/__tests__/QuickStartTileDescription.spec.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,24 @@ import { Popover, Text } from '@patternfly/react-core';
44
import QuickStartTileDescription from '../QuickStartTileDescription';
55
import { getQuickStarts } from '../../data/test-utils';
66

7+
jest.mock('react', () => {
8+
const ActualReact = require.requireActual('react');
9+
return {
10+
...ActualReact,
11+
useContext: () => jest.fn(),
12+
};
13+
});
14+
715
describe('QuickStartCatalog', () => {
16+
beforeEach(() => {
17+
spyOn(React, 'useContext').and.returnValue({
18+
activeQuickStartID: '',
19+
startQuickStart: () => {},
20+
restartQuickStart: () => {},
21+
getResource: key => `quickstart~${key}`
22+
});
23+
});
24+
825
it('should show prerequisites only if provided', () => {
926
// this quick start does not have prereqs
1027
const quickStart = getQuickStarts()[0].spec;

packages/module/src/controller/__tests__/QuickStartConclusion.spec.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import QuickStartConclusion from '../QuickStartConclusion';
77
import QuickStartMarkdownView from '../../QuickStartMarkdownView';
88
import { allQuickStarts } from '../../data/quick-start-test-data';
99

10+
jest.mock('react', () => {
11+
const ActualReact = require.requireActual('react');
12+
return {
13+
...ActualReact,
14+
useContext: () => jest.fn(),
15+
};
16+
});
17+
1018
const i18nNS = 'quickstart';
1119

1220
type QuickStartConclusionProps = React.ComponentProps<typeof QuickStartConclusion>;
@@ -25,6 +33,12 @@ const props: QuickStartConclusionProps = {
2533

2634
describe('QuickStartConclusion', () => {
2735
beforeEach(() => {
36+
spyOn(React, 'useContext').and.returnValue({
37+
activeQuickStartID: '',
38+
startQuickStart: () => {},
39+
restartQuickStart: () => {},
40+
getResource: key => `quickstart~${key}`
41+
});
2842
wrapper = shallow(<QuickStartConclusion {...props} />);
2943
});
3044

@@ -46,7 +60,7 @@ describe('QuickStartConclusion', () => {
4660
.find(Button)
4761
.at(0)
4862
.props().children[0],
49-
).toEqual(`${i18nNS}~Start {{nextQSDisplayName}} quick start`);
63+
).toEqual(`${i18nNS}~Start Installing the Pipelines Operator quick start`);
5064
});
5165

5266
it('should not render link for next quick start if nextQuickStart props is not available', () => {

packages/module/src/controller/__tests__/QuickStartFooter.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('QuickStartFooter', () => {
2020
activeQuickStartID: '',
2121
startQuickStart: () => {},
2222
restartQuickStart: () => {},
23+
getResource: key => `quickstart~${key}`
2324
});
2425
});
2526

packages/module/src/controller/__tests__/QuickStartTasks.spec.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import QuickStartTaskReview from '../QuickStartTaskReview';
88
import QuickStartMarkdownView from '../../QuickStartMarkdownView';
99
import { allQuickStarts } from '../../data/quick-start-test-data';
1010

11+
jest.mock('react', () => {
12+
const ActualReact = require.requireActual('react');
13+
return {
14+
...ActualReact,
15+
useContext: () => jest.fn(),
16+
};
17+
});
18+
1119
type QuickStartTaskProps = React.ComponentProps<typeof QuickStartTask>;
1220
let wrapper: ShallowWrapper<QuickStartTaskProps>;
1321
const props: QuickStartTaskProps = {
@@ -24,6 +32,12 @@ const props: QuickStartTaskProps = {
2432

2533
describe('QuickStartTasks', () => {
2634
beforeEach(() => {
35+
spyOn(React, 'useContext').and.returnValue({
36+
activeQuickStartID: '',
37+
startQuickStart: () => {},
38+
restartQuickStart: () => {},
39+
getResource: key => `quickstart~${key}`
40+
});
2741
wrapper = shallow(<QuickStartTask {...props} />);
2842
});
2943

0 commit comments

Comments
 (0)