@patternfly/quickstarts 6.5.0-prerelease.3 → 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.
@@ -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
  });