@patternfly/quickstarts 6.5.0-prerelease.4 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,7 +50,7 @@ Quick starts are usually surfaced within a catalog as [clickable cards.](/compon
50
50
  1. **Icon:** An icon associated with the quick start topic. If no specific icon exists, use the rocket icon.
51
51
  1. **Title:** The title (or display name) that briefly identifies the function that the quick start accomplishes. Avoid using the phrase “how to,” and instead begin the title with a gerund (verbs that end in ‘ing’).
52
52
  - Example: “Creating a Jupyter notebook”
53
- 1. **Labels:** [Filled labels](/components/label#filled-labels) communicate the estimated completion time and status of a quick start. If the quick start is presented in a mixed catalog of resources, a label can indicate the type of resource.
53
+ 1. **Labels:** [Filled labels](/components/label#filled-labels) should be placed in a card to identify quick start experiences and communicate a few high-level details, like estimated completion time and completion status. To signify that a card is linked to a quick start, use a "Quick start" [nonstatus green label](/components/label/design-guidelines#nonstatus-labels).
54
54
  1. **Description:** A description that summarizes the quick start outcome in 4 lines or fewer, without truncating. Begin the description with an action verb.
55
55
  - Example: “Connect to Red Hat OpenShift Streams for Apache Kafka from a Jupyter notebook.”
56
56
  1. **Prerequisites (optional):** A bulleted list of prerequisites, displayed in a popover, which outlines permissions needed to complete the tasks, and anything that must be pre-configured before starting the quick start. Avoid phrasing prerequisites as questions. The total number of prerequisites is listed in parentheses on the quick start card.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/quickstarts",
3
- "version": "6.5.0-prerelease.4",
3
+ "version": "6.5.0",
4
4
  "description": "PatternFly quick starts",
5
5
  "files": [
6
6
  "src",
@@ -51,7 +51,7 @@
51
51
  "react-dom": "^17 || ^18 || ^19"
52
52
  },
53
53
  "dependencies": {
54
- "dompurify": "^3.2.4",
54
+ "dompurify": "^3.3.2",
55
55
  "history": "^5.0.0"
56
56
  },
57
57
  "devDependencies": {
@@ -66,10 +66,9 @@
66
66
  "@rollup/plugin-commonjs": "^17.0.0",
67
67
  "@rollup/plugin-json": "^4.1.0",
68
68
  "@rollup/plugin-node-resolve": "^11.1.0",
69
+ "@testing-library/jest-dom": "^6.9.1",
69
70
  "@testing-library/react": "^13.4.0",
70
71
  "@types/dompurify": "^3.0.5",
71
- "@types/enzyme": "^3.10.7",
72
- "@types/enzyme-adapter-react-16": "^1.0.6",
73
72
  "@types/history": "^4.7.8",
74
73
  "@types/node": "^14.14.35",
75
74
  "@types/react": "^18.2.79",
@@ -77,9 +76,6 @@
77
76
  "clean-css-cli": "^4.3.0",
78
77
  "concat-files": "^0.1.1",
79
78
  "dart-sass": "^1.25.0",
80
- "enzyme": "^3.7.0",
81
- "enzyme-adapter-react-16": "^1.15.5",
82
- "enzyme-to-json": "^3.6.1",
83
79
  "monaco-editor": "0.34.1",
84
80
  "node-sass-glob-importer": "^5.3.2",
85
81
  "prettier": "^2.8.8",
@@ -1,24 +1,38 @@
1
- import { shallow } from 'enzyme';
2
- import MarkdownCopyClipboard, { CopyClipboard } from '../MarkdownCopyClipboard';
1
+ import { render } from '@testing-library/react';
2
+ import {
3
+ QuickStartContext,
4
+ QuickStartContextDefaults,
5
+ } from '@quickstarts/utils/quick-start-context';
6
+ import MarkdownCopyClipboard from '../MarkdownCopyClipboard';
7
+ import { MARKDOWN_COPY_BUTTON_ID } from '../const';
3
8
  import { htmlDocumentForCopyClipboard } from './test-data';
4
9
 
10
+ const contextValues = {
11
+ ...QuickStartContextDefaults,
12
+ getResource: (key: string) => key,
13
+ };
14
+
5
15
  describe('MarkdownCopyClipboard', () => {
6
16
  beforeAll(() => {
7
17
  document.body.innerHTML = htmlDocumentForCopyClipboard;
8
18
  });
19
+
9
20
  it('should render null if no element is found', () => {
10
- const wrapper = shallow(
11
- <MarkdownCopyClipboard docContext={document} rootSelector="#copy-markdown-3" />,
21
+ const { container } = render(
22
+ <QuickStartContext.Provider value={contextValues}>
23
+ <MarkdownCopyClipboard docContext={document} rootSelector="#copy-markdown-3" />
24
+ </QuickStartContext.Provider>,
12
25
  );
13
- expect(wrapper.isEmptyRender()).toBe(true);
14
- expect(wrapper.find(CopyClipboard).exists()).toBe(false);
26
+ expect(container.firstChild).toBeNull();
15
27
  });
16
28
 
17
- it('should render null if no element is found', () => {
18
- const wrapper = shallow(
19
- <MarkdownCopyClipboard docContext={document} rootSelector="#copy-markdown-1" />,
29
+ it('should render copy targets when rootSelector matches buttons in the document', () => {
30
+ render(
31
+ <QuickStartContext.Provider value={contextValues}>
32
+ <MarkdownCopyClipboard docContext={document} rootSelector="#copy-markdown-1" />
33
+ </QuickStartContext.Provider>,
20
34
  );
21
- expect(wrapper.isEmptyRender()).toBe(false);
22
- expect(wrapper.find(CopyClipboard).exists()).toBe(true);
35
+ const elements = document.querySelectorAll(`#copy-markdown-1 [${MARKDOWN_COPY_BUTTON_ID}]`);
36
+ expect(elements).toHaveLength(2);
23
37
  });
24
38
  });
@@ -1,34 +1,39 @@
1
- import { Gallery, Card } from '@patternfly/react-core';
2
- import { shallow } from 'enzyme';
3
- import { EmptyBox } from '@console/internal/components/utils';
1
+ import { render, screen, waitFor } from '@testing-library/react';
4
2
  import { getQuickStarts } from '../../data/test-utils';
5
- import { QuickStartCatalogPage } from '../../QuickStartCatalogPage';
3
+ import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
6
4
  import QuickStartCatalog from '../QuickStartCatalog';
7
5
 
8
- jest.mock('@console/shared', () => {
9
- const ActualShared = require.requireActual('@console/shared');
10
- return {
11
- ...ActualShared,
12
- useQueryParams: () => new Map(),
13
- };
14
- });
6
+ const contextValues = {
7
+ ...QuickStartContextDefaults,
8
+ activeQuickStartID: '',
9
+ allQuickStartStates: {},
10
+ getResource: (key: string) => key,
11
+ };
12
+
13
+ const renderWithContext = (props: any) =>
14
+ render(
15
+ <QuickStartContext.Provider value={contextValues}>
16
+ <QuickStartCatalog {...props} />
17
+ </QuickStartContext.Provider>,
18
+ );
15
19
 
16
20
  describe('QuickStartCatalog', () => {
17
- it('should load an emptybox if no QS exist', () => {
18
- const QuickStartCatalogProps = { quickStarts: [], onClick: jest.fn() };
19
- const QuickStartCatalogWrapper = shallow(<QuickStartCatalogPage {...QuickStartCatalogProps} />);
20
- expect(QuickStartCatalogWrapper.find(EmptyBox).exists()).toBeTruthy();
21
+ it('should render an empty state if no QS exist', () => {
22
+ renderWithContext({ quickStarts: [] });
23
+ // When no quickstarts, the catalog renders no cards
24
+ expect(screen.queryByRole('article')).not.toBeInTheDocument();
21
25
  });
22
- it('should load a gallery if QS exist', () => {
23
- const QuickStartCatalogProps = { quickStarts: getQuickStarts(), onClick: jest.fn() };
24
- const QuickStartCatalogWrapper = shallow(<QuickStartCatalog {...QuickStartCatalogProps} />);
25
- expect(QuickStartCatalogWrapper.find(Gallery).exists()).toBeTruthy();
26
- });
27
- xit('should load galleryItems equal to the number of QS', () => {
28
- const QuickStartCatalogProps = { quickStarts: getQuickStarts(), onClick: jest.fn() };
29
- const QuickStartCatalogWrapper = shallow(<QuickStartCatalog {...QuickStartCatalogProps} />);
30
- const galleryItems = QuickStartCatalogWrapper.find(Card);
31
- expect(galleryItems.exists()).toBeTruthy();
32
- expect(galleryItems.length).toEqual(getQuickStarts().length);
26
+
27
+ it('should load a gallery if QS exist', async () => {
28
+ const quickStarts = getQuickStarts();
29
+ renderWithContext({ quickStarts });
30
+ // Each tile exposes the quick start display name as the title control (link-styled button)
31
+ await waitFor(() => {
32
+ quickStarts.forEach((qs) => {
33
+ expect(
34
+ screen.getByRole('button', { name: qs.spec.displayName }),
35
+ ).toBeInTheDocument();
36
+ });
37
+ });
33
38
  });
34
39
  });
@@ -1,37 +1,56 @@
1
- import { Card } from '@patternfly/react-core';
2
- import { shallow } from 'enzyme';
1
+ import { render, screen, waitFor } from '@testing-library/react';
3
2
  import { getQuickStarts } from '../../data/test-utils';
4
3
  import { QuickStartStatus } from '../../utils/quick-start-types';
4
+ import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
5
5
  import QuickStartTile from '../QuickStartTile';
6
6
 
7
- describe('QuickStartTile', () => {
8
- const quickstarts = getQuickStarts();
7
+ const contextValues = {
8
+ ...QuickStartContextDefaults,
9
+ activeQuickStartID: '',
10
+ setActiveQuickStart: jest.fn(),
11
+ getResource: (key: string) => key,
12
+ };
13
+
14
+ const quickstarts = getQuickStarts();
9
15
 
10
- it('should load proper catalog tile without featured property', () => {
11
- const wrapper = shallow(
12
- <QuickStartTile
13
- quickStart={quickstarts[0]}
14
- status={QuickStartStatus.NOT_STARTED}
15
- onClick={jest.fn()}
16
- isActive={false}
17
- />,
18
- );
19
- const catalogTile = wrapper.find(Card);
20
- expect(catalogTile.exists()).toBeTruthy();
21
- expect(catalogTile.hasClass('pf-m-current')).toBe(false);
16
+ const renderWithContext = (props: any) =>
17
+ render(
18
+ <QuickStartContext.Provider value={contextValues}>
19
+ <QuickStartTile {...props} />
20
+ </QuickStartContext.Provider>,
21
+ );
22
+
23
+ describe('QuickStartTile', () => {
24
+ it('should load proper catalog tile without featured property', async () => {
25
+ const quickStart = quickstarts[0];
26
+ renderWithContext({
27
+ quickStart,
28
+ status: QuickStartStatus.NOT_STARTED,
29
+ onClick: jest.fn(),
30
+ isActive: false,
31
+ });
32
+ await waitFor(() => {
33
+ expect(
34
+ screen.getByRole('button', { name: quickStart.spec.displayName }),
35
+ ).toBeInTheDocument();
36
+ });
37
+ // Status label is omitted for not-started tiles
38
+ expect(screen.queryByText('In progress')).not.toBeInTheDocument();
22
39
  });
23
40
 
24
- it('should load proper catalog tile with featured property', () => {
25
- const wrapper = shallow(
26
- <QuickStartTile
27
- quickStart={quickstarts[1]}
28
- status={QuickStartStatus.IN_PROGRESS}
29
- onClick={jest.fn()}
30
- isActive
31
- />,
32
- );
33
- const catalogTile = wrapper.find(Card);
34
- expect(catalogTile.exists()).toBeTruthy();
35
- expect(catalogTile.hasClass('pf-m-current')).toBe(true);
41
+ it('should load proper catalog tile with featured property', async () => {
42
+ const quickStart = quickstarts[1];
43
+ renderWithContext({
44
+ quickStart,
45
+ status: QuickStartStatus.IN_PROGRESS,
46
+ onClick: jest.fn(),
47
+ isActive: true,
48
+ });
49
+ await waitFor(() => {
50
+ expect(
51
+ screen.getByRole('button', { name: quickStart.spec.displayName }),
52
+ ).toBeInTheDocument();
53
+ });
54
+ expect(screen.getByText('In progress')).toBeInTheDocument();
36
55
  });
37
56
  });
@@ -1,43 +1,44 @@
1
- import { Popover } from '@patternfly/react-core';
2
- import { shallow } from 'enzyme';
1
+ import { render, screen, waitFor } from '@testing-library/react';
3
2
  import { getQuickStarts } from '../../data/test-utils';
3
+ import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
4
4
  import QuickStartTileDescription from '../QuickStartTileDescription';
5
5
 
6
- jest.mock('react', () => {
7
- const ActualReact = require.requireActual('react');
8
- return {
9
- ...ActualReact,
10
- useContext: () => jest.fn(),
11
- };
12
- });
6
+ const contextValues = {
7
+ ...QuickStartContextDefaults,
8
+ activeQuickStartID: '',
9
+ startQuickStart: jest.fn(),
10
+ restartQuickStart: jest.fn(),
11
+ getResource: (key: string) => key,
12
+ };
13
13
 
14
- xdescribe('QuickStartCatalog', () => {
15
- beforeEach(() => {
16
- spyOn(React, 'useContext').and.returnValue({
17
- activeQuickStartID: '',
18
- startQuickStart: () => {},
19
- restartQuickStart: () => {},
20
- getResource: (key) => `quickstart~${key}`,
21
- });
22
- });
14
+ const renderWithContext = (props: any) =>
15
+ render(
16
+ <QuickStartContext.Provider value={contextValues}>
17
+ <QuickStartTileDescription {...props} />
18
+ </QuickStartContext.Provider>,
19
+ );
23
20
 
24
- it('should show prerequisites only if provided', () => {
25
- // this quick start does not have prereqs
21
+ describe('QuickStartTileDescription', () => {
22
+ it('should show prerequisites only if provided', async () => {
26
23
  const quickStart = getQuickStarts()[0].spec;
27
- const QuickStartTileDescriptionWrapper = shallow(
28
- <QuickStartTileDescription description={quickStart.description} />,
29
- );
30
- expect(QuickStartTileDescriptionWrapper.find(Text)).toHaveLength(0);
24
+ renderWithContext({ description: quickStart.description });
25
+ await waitFor(() => {
26
+ expect(
27
+ screen.queryByRole('button', { name: 'Show prerequisites' }),
28
+ ).not.toBeInTheDocument();
29
+ });
31
30
  });
32
31
 
33
- it('shoould render prerequisites inside a popover', () => {
32
+ it('should render prerequisites trigger when prerequisite list is non-empty', async () => {
34
33
  const quickStart = getQuickStarts()[2].spec;
35
- const QuickStartTileDescriptionWrapper = shallow(
36
- <QuickStartTileDescription
37
- description={quickStart.description}
38
- prerequisites={quickStart.prerequisites}
39
- />,
40
- );
41
- expect(QuickStartTileDescriptionWrapper.find(Popover)).toHaveLength(1);
34
+ renderWithContext({
35
+ description: quickStart.description,
36
+ prerequisites: quickStart.prerequisites,
37
+ });
38
+ await waitFor(() => {
39
+ expect(
40
+ screen.getByRole('button', { name: 'Show prerequisites' }),
41
+ ).toBeInTheDocument();
42
+ });
42
43
  });
43
44
  });
@@ -1,25 +1,19 @@
1
- import { ComponentProps } from 'react';
2
- import { Button } from '@patternfly/react-core';
3
- import { ShallowWrapper, shallow } from 'enzyme';
1
+ import { render, waitFor } from '@testing-library/react';
4
2
  import { allQuickStarts } from '../../data/quick-start-test-data';
5
- import QuickStartMarkdownView from '../../QuickStartMarkdownView';
6
3
  import { QuickStartTaskStatus } from '../../utils/quick-start-types';
4
+ import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
7
5
  import { getQuickStartByName } from '../../utils/quick-start-utils';
8
6
  import QuickStartConclusion from '../QuickStartConclusion';
9
7
 
10
- jest.mock('react', () => {
11
- const ActualReact = require.requireActual('react');
12
- return {
13
- ...ActualReact,
14
- useContext: () => jest.fn(),
15
- };
16
- });
17
-
18
- const i18nNS = 'quickstart';
8
+ const contextValues = {
9
+ ...QuickStartContextDefaults,
10
+ activeQuickStartID: '',
11
+ startQuickStart: jest.fn(),
12
+ restartQuickStart: jest.fn(),
13
+ getResource: (key: string) => key,
14
+ };
19
15
 
20
- type QuickStartConclusionProps = ComponentProps<typeof QuickStartConclusion>;
21
- let wrapper: ShallowWrapper<QuickStartConclusionProps>;
22
- const props: QuickStartConclusionProps = {
16
+ const defaultProps = {
23
17
  tasks: getQuickStartByName('explore-pipelines', allQuickStarts).spec.tasks,
24
18
  allTaskStatuses: [
25
19
  QuickStartTaskStatus.SUCCESS,
@@ -31,52 +25,56 @@ const props: QuickStartConclusionProps = {
31
25
  onQuickStartChange: jest.fn(),
32
26
  };
33
27
 
34
- xdescribe('QuickStartConclusion', () => {
28
+ const renderWithContext = (props = {}) =>
29
+ render(
30
+ <QuickStartContext.Provider value={contextValues}>
31
+ <QuickStartConclusion {...defaultProps} {...props} />
32
+ </QuickStartContext.Provider>,
33
+ );
34
+
35
+ describe('QuickStartConclusion', () => {
35
36
  beforeEach(() => {
36
- spyOn(React, 'useContext').and.returnValue({
37
- activeQuickStartID: '',
38
- startQuickStart: () => {},
39
- restartQuickStart: () => {},
40
- getResource: (key) => `quickstart~${key}`,
41
- });
42
- wrapper = shallow(<QuickStartConclusion {...props} />);
37
+ jest.clearAllMocks();
43
38
  });
44
39
 
45
- it('should render conclusion if there are no failed tasks', () => {
46
- expect(wrapper.find(QuickStartMarkdownView).first().props().content).toEqual('conclusion');
40
+ it('should render conclusion if there are no failed tasks', async () => {
41
+ renderWithContext();
42
+ await waitFor(() => {
43
+ expect(document.body.textContent).toMatch(/conclusion/);
44
+ });
47
45
  });
48
46
 
49
- it('should render link for next quick start if nextQuickStart prop is available and there are no failed tasks', () => {
50
- wrapper = shallow(
51
- <QuickStartConclusion
52
- {...props}
53
- nextQuickStarts={[getQuickStartByName('explore-pipelines', allQuickStarts)]}
54
- />,
55
- );
56
- expect(wrapper.find(Button).at(0).props().children).toEqual(
57
- `${i18nNS}~Start Installing the Pipelines Operator quick start`,
58
- );
47
+ it('should render link for next quick start if nextQuickStart prop is available and there are no failed tasks', async () => {
48
+ renderWithContext({
49
+ nextQuickStarts: [getQuickStartByName('explore-pipelines', allQuickStarts)],
50
+ });
51
+ await waitFor(() => {
52
+ expect(document.body.textContent).toMatch(
53
+ /Start Installing the Pipelines Operator quick start/,
54
+ );
55
+ });
59
56
  });
60
57
 
61
- it('should not render link for next quick start if nextQuickStart props is not available', () => {
62
- expect(wrapper.find(Button).length).toBe(0);
58
+ it('should not render link for next quick start if nextQuickStart props is not available', async () => {
59
+ renderWithContext();
60
+ await waitFor(() => {
61
+ expect(document.body.textContent).toMatch(/conclusion/);
62
+ });
63
+ expect(document.body.textContent).not.toMatch(/Start .* quick start/);
63
64
  });
64
65
 
65
- it('should not render conclusion, link for next quick start and should render message for retrying if there are failed tasks', () => {
66
- wrapper = shallow(
67
- <QuickStartConclusion
68
- {...props}
69
- nextQuickStarts={[getQuickStartByName('explore-pipelines', allQuickStarts)]}
70
- allTaskStatuses={[
71
- QuickStartTaskStatus.FAILED,
72
- QuickStartTaskStatus.SUCCESS,
73
- QuickStartTaskStatus.SUCCESS,
74
- ]}
75
- />,
76
- );
77
- expect(wrapper.find(QuickStartMarkdownView).first().props().content).toEqual(
78
- `${i18nNS}~One or more verifications did not pass during this quick start. Revisit the tasks or the help links, and then try again.`,
79
- );
80
- expect(wrapper.find(Button).length).toBe(0);
66
+ it('should not render conclusion and should render message for retrying if there are failed tasks', async () => {
67
+ renderWithContext({
68
+ nextQuickStarts: [getQuickStartByName('explore-pipelines', allQuickStarts)],
69
+ allTaskStatuses: [
70
+ QuickStartTaskStatus.FAILED,
71
+ QuickStartTaskStatus.SUCCESS,
72
+ QuickStartTaskStatus.SUCCESS,
73
+ ],
74
+ });
75
+ await waitFor(() => {
76
+ expect(document.body.textContent).toMatch(/One or more verifications did not pass/);
77
+ });
78
+ expect(document.body.textContent).not.toMatch(/Start .* quick start/);
81
79
  });
82
80
  });
@@ -1,52 +1,71 @@
1
- import { ComponentProps } from 'react';
2
- import { ShallowWrapper, shallow } from 'enzyme';
1
+ import { render, waitFor } from '@testing-library/react';
3
2
  import { allQuickStarts } from '../../data/quick-start-test-data';
4
3
  import { QuickStartTaskStatus } from '../../utils/quick-start-types';
4
+ import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
5
5
  import { getQuickStartByName } from '../../utils/quick-start-utils';
6
- import QuickStartConclusion from '../QuickStartConclusion';
7
6
  import QuickStartContent from '../QuickStartContent';
8
- import QuickStartIntroduction from '../QuickStartIntroduction';
9
- import QuickStartTasks from '../QuickStartTasks';
10
7
 
11
- type QuickStartContentProps = ComponentProps<typeof QuickStartContent>;
8
+ const contextValues = {
9
+ ...QuickStartContextDefaults,
10
+ getResource: (key: string) => key,
11
+ };
12
12
 
13
- let wrapper: ShallowWrapper<QuickStartContentProps>;
13
+ const quickStart = getQuickStartByName('explore-serverless', allQuickStarts);
14
+ const totalTasks = quickStart.spec.tasks.length;
14
15
 
15
- const props: QuickStartContentProps = {
16
- quickStart: getQuickStartByName('explore-serverless', allQuickStarts),
17
- allTaskStatuses: [
18
- QuickStartTaskStatus.INIT,
19
- QuickStartTaskStatus.INIT,
20
- QuickStartTaskStatus.INIT,
21
- ],
16
+ const defaultProps = {
17
+ quickStart,
18
+ allTaskStatuses: [QuickStartTaskStatus.INIT, QuickStartTaskStatus.INIT],
22
19
  taskNumber: -1,
23
20
  onTaskReview: jest.fn(),
24
21
  onTaskSelect: jest.fn(),
25
22
  onQuickStartChange: jest.fn(),
26
23
  };
27
24
 
25
+ const renderWithContext = (props = {}) =>
26
+ render(
27
+ <QuickStartContext.Provider value={contextValues}>
28
+ <QuickStartContent {...defaultProps} {...props} />
29
+ </QuickStartContext.Provider>,
30
+ );
31
+
28
32
  describe('QuickStartContent', () => {
29
33
  beforeEach(() => {
30
- wrapper = shallow(<QuickStartContent {...props} />);
34
+ jest.clearAllMocks();
31
35
  });
32
36
 
33
- it('should render QuickStartIntroduction when the tour status is Not Started', () => {
34
- expect(wrapper.find(QuickStartIntroduction).length).toBe(1);
35
- expect(wrapper.find(QuickStartTasks).length).toBe(0);
36
- expect(wrapper.find(QuickStartConclusion).length).toBe(0);
37
+ it('should render QuickStartIntroduction when the tour status is Not Started', async () => {
38
+ renderWithContext();
39
+ await waitFor(() => {
40
+ expect(document.body.textContent).toMatch(
41
+ new RegExp(`In this quick start, you will complete ${totalTasks} task`),
42
+ );
43
+ });
44
+ expect(document.body.textContent).not.toMatch(/Your Serverless Operator is ready/);
37
45
  });
38
46
 
39
- it('should render QuickStartTasks when the tour is In Progress', () => {
40
- wrapper = shallow(<QuickStartContent {...props} taskNumber={1} />);
41
- expect(wrapper.find(QuickStartIntroduction).length).toBe(0);
42
- expect(wrapper.find(QuickStartTasks).length).toBe(1);
43
- expect(wrapper.find(QuickStartConclusion).length).toBe(0);
47
+ it('should render QuickStartTasks when the tour is In Progress', async () => {
48
+ // taskNumber is 0-based index into spec.tasks; first task visible and active when non-INIT
49
+ renderWithContext({
50
+ taskNumber: 0,
51
+ allTaskStatuses: [QuickStartTaskStatus.VISITED, QuickStartTaskStatus.INIT],
52
+ });
53
+ await waitFor(() => {
54
+ expect(document.body.textContent).toMatch(/Install the OpenShift Serverless Operator/);
55
+ });
56
+ expect(document.body.textContent).not.toMatch(
57
+ new RegExp(`In this quick start, you will complete ${totalTasks} task`),
58
+ );
44
59
  });
45
60
 
46
- it('should render QuickStartConclusion when the tour is Complete', () => {
47
- wrapper = shallow(<QuickStartContent {...props} taskNumber={2} />);
48
- expect(wrapper.find(QuickStartIntroduction).length).toBe(0);
49
- expect(wrapper.find(QuickStartTasks).length).toBe(0);
50
- expect(wrapper.find(QuickStartConclusion).length).toBe(1);
61
+ it('should render QuickStartConclusion when the tour is Complete', async () => {
62
+ renderWithContext({ taskNumber: totalTasks });
63
+ await waitFor(() => {
64
+ expect(document.body.textContent).toMatch(/Your Serverless Operator is ready/);
65
+ });
66
+ // Conclusion still lists task headers; intro copy is not shown
67
+ expect(document.body.textContent).not.toMatch(
68
+ /In this quick start, you will complete \d+ task/,
69
+ );
51
70
  });
52
71
  });
@@ -1,103 +1,87 @@
1
- import * as React from 'react';
2
- import { Button } from '@patternfly/react-core';
3
- import { shallow } from 'enzyme';
1
+ import { render, screen, waitFor } from '@testing-library/react';
4
2
  import { QuickStartStatus } from '../../utils/quick-start-types';
3
+ import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
5
4
  import QuickStartFooter from '../QuickStartFooter';
6
5
 
7
- jest.mock('react', () => {
8
- const ActualReact = require.requireActual('react');
9
- return {
10
- ...ActualReact,
11
- useContext: () => jest.fn(),
12
- };
13
- });
6
+ const contextValues = {
7
+ ...QuickStartContextDefaults,
8
+ activeQuickStartID: '',
9
+ startQuickStart: jest.fn(),
10
+ restartQuickStart: jest.fn(),
11
+ getResource: (key: string) => key,
12
+ };
14
13
 
15
- describe('QuickStartFooter', () => {
16
- type QuickStartFooterProps = React.ComponentProps<typeof QuickStartFooter>;
17
- let quickStartFooterProps: QuickStartFooterProps;
18
- beforeEach(() => {
19
- spyOn(React, 'useContext').and.returnValue({
20
- activeQuickStartID: '',
21
- startQuickStart: () => {},
22
- restartQuickStart: () => {},
23
- getResource: (key) => `quickstart~${key}`,
24
- });
25
- });
14
+ const renderWithContext = (props: any) =>
15
+ render(
16
+ <QuickStartContext.Provider value={contextValues}>
17
+ <QuickStartFooter {...props} />
18
+ </QuickStartContext.Provider>,
19
+ );
26
20
 
27
- it('should load Start button for not started tours', () => {
28
- quickStartFooterProps = {
21
+ describe('QuickStartFooter', () => {
22
+ it('should load Start button for not started tours', async () => {
23
+ renderWithContext({
29
24
  status: QuickStartStatus.NOT_STARTED,
30
25
  footerClass: 'test',
31
26
  quickStartId: 'test-quickstart',
32
- onNext: () => null,
33
- onBack: () => null,
27
+ onNext: jest.fn(),
28
+ onBack: jest.fn(),
34
29
  totalTasks: 4,
35
30
  taskNumber: -1,
36
- };
37
-
38
- const quickStartFooterWrapper = shallow(<QuickStartFooter {...quickStartFooterProps} />);
39
- const footerButtons = quickStartFooterWrapper.find(Button);
40
- expect(footerButtons.exists()).toBeTruthy();
41
- expect(footerButtons.length).toEqual(1);
42
- expect(footerButtons.at(0).childAt(0).text()).toBe('quickstart~Start');
31
+ });
32
+ await waitFor(() => {
33
+ expect(screen.getByRole('button', { name: 'Start' })).toBeInTheDocument();
34
+ });
35
+ expect(screen.queryByRole('button', { name: 'Back' })).not.toBeInTheDocument();
43
36
  });
44
37
 
45
- it('should load Continue and Restart buttons for in progress tours at into page', () => {
46
- quickStartFooterProps = {
38
+ it('should load Continue and Restart buttons for in progress tours at intro page', async () => {
39
+ renderWithContext({
47
40
  status: QuickStartStatus.IN_PROGRESS,
48
41
  footerClass: 'test',
49
42
  quickStartId: 'test-quickstart',
50
- onNext: () => null,
51
- onBack: () => null,
43
+ onNext: jest.fn(),
44
+ onBack: jest.fn(),
52
45
  totalTasks: 4,
53
46
  taskNumber: -1,
54
- };
55
-
56
- const quickStartFooterWrapper = shallow(<QuickStartFooter {...quickStartFooterProps} />);
57
- const footerButtons = quickStartFooterWrapper.find(Button);
58
- expect(footerButtons.exists()).toBeTruthy();
59
- expect(footerButtons.length).toEqual(2);
60
- expect(footerButtons.at(0).childAt(0).text()).toBe('quickstart~Continue');
61
- expect(footerButtons.at(1).childAt(0).text()).toBe('quickstart~Restart');
47
+ });
48
+ await waitFor(() => {
49
+ expect(screen.getByRole('button', { name: 'Continue' })).toBeInTheDocument();
50
+ });
51
+ expect(screen.getByRole('button', { name: 'Restart' })).toBeInTheDocument();
62
52
  });
63
53
 
64
- it('should load Next and Back buttons, and Restart link for in progress tours in task page', () => {
65
- quickStartFooterProps = {
54
+ it('should load Next, Back, and Restart buttons for in progress tours in task page', async () => {
55
+ renderWithContext({
66
56
  status: QuickStartStatus.IN_PROGRESS,
67
57
  footerClass: 'test',
68
58
  quickStartId: 'test-quickstart',
69
- onNext: () => null,
70
- onBack: () => null,
59
+ onNext: jest.fn(),
60
+ onBack: jest.fn(),
71
61
  totalTasks: 4,
72
62
  taskNumber: 2,
73
- };
74
-
75
- const quickStartFooterWrapper = shallow(<QuickStartFooter {...quickStartFooterProps} />);
76
- const footerButtons = quickStartFooterWrapper.find(Button);
77
- expect(footerButtons.exists()).toBeTruthy();
78
- expect(footerButtons.length).toEqual(3);
79
- expect(footerButtons.at(0).childAt(0).text()).toBe('quickstart~Next');
80
- expect(footerButtons.at(1).childAt(0).text()).toBe('quickstart~Back');
81
- expect(footerButtons.at(2).childAt(0).text()).toBe('quickstart~Restart');
63
+ });
64
+ await waitFor(() => {
65
+ expect(screen.getByRole('button', { name: 'Next' })).toBeInTheDocument();
66
+ });
67
+ expect(screen.getByRole('button', { name: 'Back' })).toBeInTheDocument();
68
+ expect(screen.getByRole('button', { name: 'Restart' })).toBeInTheDocument();
82
69
  });
83
70
 
84
- it('should load Close, Back and Restart buttons for completed tours in conclusion page', () => {
85
- quickStartFooterProps = {
71
+ it('should load Close, Back and Restart buttons for completed tours in conclusion page', async () => {
72
+ renderWithContext({
86
73
  status: QuickStartStatus.COMPLETE,
87
74
  footerClass: 'test',
88
75
  quickStartId: 'test-quickstart',
89
- onNext: () => null,
90
- onBack: () => null,
76
+ onNext: jest.fn(),
77
+ onBack: jest.fn(),
91
78
  totalTasks: 4,
92
79
  taskNumber: 4,
93
- };
94
-
95
- const quickStartFooterWrapper = shallow(<QuickStartFooter {...quickStartFooterProps} />);
96
- const footerButtons = quickStartFooterWrapper.find(Button);
97
- expect(footerButtons.exists()).toBeTruthy();
98
- expect(footerButtons.length).toEqual(3);
99
- expect(footerButtons.at(0).childAt(0).text()).toBe('quickstart~Close');
100
- expect(footerButtons.at(1).childAt(0).text()).toBe('quickstart~Back');
101
- expect(footerButtons.at(2).childAt(0).text()).toBe('quickstart~Restart');
80
+ });
81
+ await waitFor(() => {
82
+ expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();
83
+ });
84
+ expect(screen.getByRole('button', { name: 'Back' })).toBeInTheDocument();
85
+ expect(screen.getByRole('button', { name: 'Restart' })).toBeInTheDocument();
102
86
  });
103
87
  });
@@ -1,43 +1,47 @@
1
- import { ComponentProps } from 'react';
2
- import { Title, WizardNavItem } from '@patternfly/react-core';
3
- import { ShallowWrapper, shallow } from 'enzyme';
1
+ import { render, screen, waitFor } from '@testing-library/react';
4
2
  import { QuickStartTaskStatus } from '../../utils/quick-start-types';
3
+ import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
5
4
  import QuickStartTaskHeader from '../QuickStartTaskHeader';
6
5
 
7
- type QuickStartTaskHeaderProps = ComponentProps<typeof QuickStartTaskHeader>;
8
- let wrapper: ShallowWrapper<QuickStartTaskHeaderProps>;
9
- const props: QuickStartTaskHeaderProps = {
6
+ const contextValues = {
7
+ ...QuickStartContextDefaults,
8
+ getResource: (key: string) => key,
9
+ };
10
+
11
+ const defaultProps = {
10
12
  title: 'title',
11
13
  taskIndex: 1,
12
14
  subtitle: 'subtitle',
13
15
  taskStatus: QuickStartTaskStatus.INIT,
14
- size: 'lg',
16
+ size: 'lg' as const,
15
17
  isActiveTask: true,
16
18
  onTaskSelect: jest.fn(),
17
19
  };
18
20
 
21
+ const renderWithContext = (props = {}) =>
22
+ render(
23
+ <QuickStartContext.Provider value={contextValues}>
24
+ <QuickStartTaskHeader {...defaultProps} {...props} />
25
+ </QuickStartContext.Provider>,
26
+ );
27
+
19
28
  describe('QuickStartTaskHeader', () => {
20
- beforeEach(() => {
21
- // DOMPurify.addHook = jest.fn();
22
- wrapper = shallow(<QuickStartTaskHeader {...props} />);
29
+ it('should render subtitle for active task', async () => {
30
+ renderWithContext();
31
+ await waitFor(() => {
32
+ expect(
33
+ screen.getByRole('button', {
34
+ name: new RegExp(`${defaultProps.title}.*${defaultProps.subtitle}`),
35
+ }),
36
+ ).toBeInTheDocument();
37
+ });
23
38
  });
24
39
 
25
- it('should render subtitle for active task', () => {
26
- expect(wrapper.find(WizardNavItem).dive().find(Title).length).toBe(1);
27
- expect(
28
- wrapper.find(WizardNavItem).dive().find('[data-test-id="quick-start-task-subtitle"]').props()
29
- .children,
30
- ).toEqual(props.subtitle);
31
- });
32
- it('should not render subtitle if task is not active', () => {
33
- wrapper = shallow(<QuickStartTaskHeader {...props} isActiveTask={false} />);
34
- expect(wrapper.find(WizardNavItem).dive().find(Title).length).toBe(1);
35
- expect(
36
- wrapper
37
- .find(WizardNavItem)
38
- .dive()
39
- .find('[data-test-id="quick-start-task-subtitle"]')
40
- .exists(),
41
- ).toBe(false);
40
+ it('should not render subtitle if task is not active', async () => {
41
+ renderWithContext({ isActiveTask: false });
42
+ await waitFor(() => {
43
+ expect(screen.getByRole('button', { name: defaultProps.title })).toBeInTheDocument();
44
+ });
45
+ expect(screen.queryByText(defaultProps.subtitle)).not.toBeInTheDocument();
42
46
  });
43
47
  });
@@ -1,42 +1,57 @@
1
- import { Alert } from '@patternfly/react-core';
2
- import { ShallowWrapper, shallow } from 'enzyme';
1
+ import { render, screen, waitFor } from '@testing-library/react';
3
2
  import { allQuickStarts } from '../../data/quick-start-test-data';
4
- import QuickStartMarkdownView from '../../QuickStartMarkdownView';
5
3
  import { QuickStartTaskStatus } from '../../utils/quick-start-types';
4
+ import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
6
5
  import { getQuickStartByName } from '../../utils/quick-start-utils';
7
6
  import QuickStartTaskReview from '../QuickStartTaskReview';
8
- import { ComponentProps } from 'react';
9
7
 
10
- type QuickStartTaskReviewProps = ComponentProps<typeof QuickStartTaskReview>;
11
- let wrapper: ShallowWrapper<QuickStartTaskReviewProps>;
12
- const props: QuickStartTaskReviewProps = {
13
- review: getQuickStartByName('explore-serverless', allQuickStarts).spec.tasks[0].review,
8
+ const contextValues = {
9
+ ...QuickStartContextDefaults,
10
+ getResource: (key: string) => key,
11
+ };
12
+
13
+ const review = getQuickStartByName('explore-serverless', allQuickStarts).spec.tasks[0].review;
14
+
15
+ const defaultProps = {
16
+ review,
14
17
  taskStatus: QuickStartTaskStatus.REVIEW,
15
18
  onTaskReview: jest.fn(),
16
19
  };
17
20
 
18
- describe('QuickStartTaskReview', () => {
19
- it('should render alert with info variant when task status is review', () => {
20
- wrapper = shallow(<QuickStartTaskReview {...props} />);
21
- expect(wrapper.find(Alert).props().variant).toBe('info');
22
- });
21
+ const renderWithContext = (props = {}) =>
22
+ render(
23
+ <QuickStartContext.Provider value={contextValues}>
24
+ <QuickStartTaskReview {...defaultProps} {...props} />
25
+ </QuickStartContext.Provider>,
26
+ );
23
27
 
24
- it('should render alert with success variant when task status is success', () => {
25
- props.taskStatus = QuickStartTaskStatus.SUCCESS;
26
- wrapper = shallow(<QuickStartTaskReview {...props} />);
27
- expect(wrapper.find(Alert).props().variant).toBe('success');
28
+ describe('QuickStartTaskReview', () => {
29
+ it('should render review prompt with yes/no while task is in review', async () => {
30
+ renderWithContext();
31
+ await waitFor(() => {
32
+ expect(screen.getByRole('alert')).toBeInTheDocument();
33
+ });
34
+ expect(screen.getByText('Check your work')).toBeInTheDocument();
35
+ expect(screen.getByRole('radio', { name: 'Yes' })).not.toBeChecked();
36
+ expect(screen.getByRole('radio', { name: 'No' })).not.toBeChecked();
28
37
  });
29
38
 
30
- it('should render alert with danger variant when task status is failed', () => {
31
- props.taskStatus = QuickStartTaskStatus.FAILED;
32
- wrapper = shallow(<QuickStartTaskReview {...props} />);
33
- expect(wrapper.find(Alert).props().variant).toBe('danger');
39
+ it('should mark Yes selected when task status is success', async () => {
40
+ renderWithContext({ taskStatus: QuickStartTaskStatus.SUCCESS });
41
+ await waitFor(() => {
42
+ expect(screen.getByRole('radio', { name: 'Yes' })).toBeChecked();
43
+ });
44
+ expect(screen.getByRole('radio', { name: 'No' })).not.toBeChecked();
34
45
  });
35
46
 
36
- it('should render task help in markdown when task status is failed', () => {
37
- wrapper = shallow(<QuickStartTaskReview {...props} />);
38
- expect(wrapper.find(QuickStartMarkdownView).at(1).props().content).toEqual(
39
- props.review.failedTaskHelp,
40
- );
47
+ it('should mark No selected and show failed-task help when task status is failed', async () => {
48
+ renderWithContext({ taskStatus: QuickStartTaskStatus.FAILED });
49
+ await waitFor(() => {
50
+ expect(screen.getByRole('radio', { name: 'No' })).toBeChecked();
51
+ });
52
+ expect(screen.getByRole('radio', { name: 'Yes' })).not.toBeChecked();
53
+ await waitFor(() => {
54
+ expect(document.body.textContent).toMatch(/This task is incomplete/);
55
+ });
41
56
  });
42
57
  });
@@ -1,25 +1,22 @@
1
- import * as React from 'react';
2
- import { ShallowWrapper, shallow } from 'enzyme';
1
+ import { render, screen, waitFor } from '@testing-library/react';
3
2
  import { allQuickStarts } from '../../data/quick-start-test-data';
4
- import QuickStartMarkdownView from '../../QuickStartMarkdownView';
5
3
  import { QuickStartTaskStatus } from '../../utils/quick-start-types';
4
+ import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
6
5
  import { getQuickStartByName } from '../../utils/quick-start-utils';
7
- import TaskHeader from '../QuickStartTaskHeader';
8
- import QuickStartTaskReview from '../QuickStartTaskReview';
9
- import QuickStartTask from '../QuickStartTasks';
6
+ import QuickStartTasks from '../QuickStartTasks';
10
7
 
11
- jest.mock('react', () => {
12
- const ActualReact = require.requireActual('react');
13
- return {
14
- ...ActualReact,
15
- useContext: () => jest.fn(),
16
- };
17
- });
8
+ const contextValues = {
9
+ ...QuickStartContextDefaults,
10
+ activeQuickStartID: '',
11
+ startQuickStart: jest.fn(),
12
+ restartQuickStart: jest.fn(),
13
+ getResource: (key: string) => key,
14
+ };
15
+
16
+ const tasks = getQuickStartByName('monitor-sampleapp', allQuickStarts).spec.tasks;
18
17
 
19
- type QuickStartTaskProps = React.ComponentProps<typeof QuickStartTask>;
20
- let wrapper: ShallowWrapper<QuickStartTaskProps>;
21
- const props: QuickStartTaskProps = {
22
- tasks: getQuickStartByName('monitor-sampleapp', allQuickStarts).spec.tasks,
18
+ const defaultProps = {
19
+ tasks,
23
20
  allTaskStatuses: [
24
21
  QuickStartTaskStatus.SUCCESS,
25
22
  QuickStartTaskStatus.INIT,
@@ -30,49 +27,54 @@ const props: QuickStartTaskProps = {
30
27
  onTaskSelect: jest.fn(),
31
28
  };
32
29
 
30
+ const renderWithContext = (props = {}) =>
31
+ render(
32
+ <QuickStartContext.Provider value={contextValues}>
33
+ <QuickStartTasks {...defaultProps} {...props} />
34
+ </QuickStartContext.Provider>,
35
+ );
36
+
33
37
  describe('QuickStartTasks', () => {
34
38
  beforeEach(() => {
35
- spyOn(React, 'useContext').and.returnValue({
36
- activeQuickStartID: '',
37
- startQuickStart: () => {},
38
- restartQuickStart: () => {},
39
- getResource: (key) => `quickstart~${key}`,
40
- });
41
- wrapper = shallow(<QuickStartTask {...props} />);
39
+ jest.clearAllMocks();
42
40
  });
43
41
 
44
- it('should render correct number of tasks based on currentTaskIndex', () => {
45
- expect(wrapper.find(TaskHeader).length).toBe(1);
42
+ it('should render correct number of tasks based on currentTaskIndex', async () => {
43
+ renderWithContext();
44
+ await waitFor(() => {
45
+ // Only non-INIT tasks are rendered; first task is SUCCESS so it shows
46
+ const taskHeaders = screen.getAllByRole('listitem');
47
+ expect(taskHeaders).toHaveLength(1);
48
+ });
46
49
  });
47
50
 
48
- it('should render SyncMarkdownView with description if a task is active', () => {
49
- wrapper = shallow(
50
- <QuickStartTask
51
- {...props}
52
- allTaskStatuses={[
53
- QuickStartTaskStatus.SUCCESS,
54
- QuickStartTaskStatus.FAILED,
55
- QuickStartTaskStatus.VISITED,
56
- ]}
57
- taskNumber={2}
58
- />,
59
- );
60
- expect(wrapper.find(QuickStartMarkdownView).at(0).props().content).toEqual(
61
- props.tasks[2].description,
62
- );
51
+ it('should render description if a task is active', async () => {
52
+ renderWithContext({
53
+ allTaskStatuses: [
54
+ QuickStartTaskStatus.SUCCESS,
55
+ QuickStartTaskStatus.FAILED,
56
+ QuickStartTaskStatus.VISITED,
57
+ ],
58
+ taskNumber: 2,
59
+ });
60
+ await waitFor(() => {
61
+ // All 3 tasks are non-INIT, so all render
62
+ const taskHeaders = screen.getAllByRole('listitem');
63
+ expect(taskHeaders).toHaveLength(3);
64
+ });
63
65
  });
64
66
 
65
- it('should render review when task is active and in Review state', () => {
66
- wrapper = shallow(
67
- <QuickStartTask
68
- {...props}
69
- allTaskStatuses={[
70
- QuickStartTaskStatus.SUCCESS,
71
- QuickStartTaskStatus.REVIEW,
72
- QuickStartTaskStatus.INIT,
73
- ]}
74
- />,
75
- );
76
- expect(wrapper.find(QuickStartTaskReview).exists()).toBe(true);
67
+ it('should render review when task is active and in Review state', async () => {
68
+ renderWithContext({
69
+ allTaskStatuses: [
70
+ QuickStartTaskStatus.SUCCESS,
71
+ QuickStartTaskStatus.REVIEW,
72
+ QuickStartTaskStatus.INIT,
73
+ ],
74
+ });
75
+ await waitFor(() => {
76
+ // "Check your work" is the alert title for QuickStartTaskReview
77
+ expect(screen.getByText('Check your work')).toBeInTheDocument();
78
+ });
77
79
  });
78
80
  });