|
1 |
| -import { act, fireEvent, getByText, screen } from '@testing-library/react'; |
2 |
| -import userEvent from '@testing-library/user-event'; |
| 1 | +import { fireEvent, getByText } from '@testing-library/react'; |
3 | 2 | import { h } from 'react-hyperscript-helpers';
|
4 |
| -import { generateTestAppWithAzureWorkspace, generateTestAppWithGoogleWorkspace } from 'src/analysis/_testData/testData'; |
5 |
| -import { PauseButton } from 'src/analysis/Environments/Environments'; |
6 | 3 | import { isFeaturePreviewEnabled, toggleFeaturePreview, useAvailableFeaturePreviews } from 'src/libs/feature-previews';
|
7 | 4 | import { FeaturePreviews } from 'src/pages/FeaturePreviews';
|
8 | 5 | import { asMockedFn, renderWithAppContexts as render } from 'src/testing/test-utils';
|
9 | 6 |
|
10 |
| -jest.mock('src/libs/ajax'); |
11 | 7 | jest.mock('src/libs/feature-previews');
|
12 |
| -describe('Environments', () => { |
13 |
| - describe('FeaturePreviews', () => { |
14 |
| - beforeEach(() => { |
15 |
| - asMockedFn(useAvailableFeaturePreviews).mockReturnValue({ |
16 |
| - featurePreviews: [ |
17 |
| - // @ts-expect-error |
18 |
| - { |
19 |
| - id: 'feature1', |
20 |
| - title: 'Feature #1', |
21 |
| - description: 'A new feature', |
22 |
| - documentationUrl: 'https://example.com/feature-1-docs', |
23 |
| - }, |
24 |
| - // @ts-expect-error |
25 |
| - { |
26 |
| - id: 'feature2', |
27 |
| - title: 'Feature #2', |
28 |
| - description: 'Another new feature', |
29 |
| - feedbackUrl: 'mailto:[email protected]', |
30 |
| - }, |
31 |
| - ], |
32 |
| - loading: false, |
33 |
| - }); |
34 | 8 |
|
35 |
| - asMockedFn(isFeaturePreviewEnabled).mockReturnValue(false); |
| 9 | +describe('FeaturePreviews', () => { |
| 10 | + beforeEach(() => { |
| 11 | + asMockedFn(useAvailableFeaturePreviews).mockReturnValue({ |
| 12 | + featurePreviews: [ |
| 13 | + // @ts-expect-error |
| 14 | + { |
| 15 | + id: 'feature1', |
| 16 | + title: 'Feature #1', |
| 17 | + description: 'A new feature', |
| 18 | + documentationUrl: 'https://example.com/feature-1-docs', |
| 19 | + }, |
| 20 | + // @ts-expect-error |
| 21 | + { |
| 22 | + id: 'feature2', |
| 23 | + title: 'Feature #2', |
| 24 | + description: 'Another new feature', |
| 25 | + feedbackUrl: 'mailto:[email protected]', |
| 26 | + }, |
| 27 | + ], |
| 28 | + loading: false, |
36 | 29 | });
|
37 | 30 |
|
38 |
| - it('should render available feature previews', () => { |
39 |
| - const { getAllByRole } = render(h(FeaturePreviews)); |
40 |
| - const cells = getAllByRole('cell'); |
| 31 | + asMockedFn(isFeaturePreviewEnabled).mockReturnValue(false); |
| 32 | + }); |
41 | 33 |
|
42 |
| - expect(getByText(cells[1], 'Feature #1')).toBeTruthy(); |
43 |
| - expect(getByText(cells[1], 'A new feature')).toBeTruthy(); |
| 34 | + it('should render available feature previews', () => { |
| 35 | + const { getAllByRole } = render(h(FeaturePreviews)); |
| 36 | + const cells = getAllByRole('cell'); |
44 | 37 |
|
45 |
| - expect(getByText(cells[3], 'Feature #2')).toBeTruthy(); |
46 |
| - expect(getByText(cells[3], 'Another new feature')).toBeTruthy(); |
47 |
| - }); |
| 38 | + expect(getByText(cells[1], 'Feature #1')).toBeTruthy(); |
| 39 | + expect(getByText(cells[1], 'A new feature')).toBeTruthy(); |
48 | 40 |
|
49 |
| - it('should render whether features are enabled', () => { |
50 |
| - asMockedFn(isFeaturePreviewEnabled).mockImplementation((id) => id === 'feature1'); |
| 41 | + expect(getByText(cells[3], 'Feature #2')).toBeTruthy(); |
| 42 | + expect(getByText(cells[3], 'Another new feature')).toBeTruthy(); |
| 43 | + }); |
51 | 44 |
|
52 |
| - const { getAllByRole } = render(h(FeaturePreviews)); |
53 |
| - const checkboxes = getAllByRole('checkbox'); |
| 45 | + it('should render whether features are enabled', () => { |
| 46 | + asMockedFn(isFeaturePreviewEnabled).mockImplementation((id) => id === 'feature1'); |
54 | 47 |
|
55 |
| - expect(checkboxes[0].getAttribute('aria-checked')).toBe('true'); |
56 |
| - expect(checkboxes[1].getAttribute('aria-checked')).toBe('false'); |
57 |
| - }); |
| 48 | + const { getAllByRole } = render(h(FeaturePreviews)); |
| 49 | + const checkboxes = getAllByRole('checkbox'); |
58 | 50 |
|
59 |
| - it('checking a checkbox should toggle feature previews', () => { |
60 |
| - const { getAllByRole } = render(h(FeaturePreviews)); |
61 |
| - const checkboxes = getAllByRole('checkbox'); |
| 51 | + expect(checkboxes[0].getAttribute('aria-checked')).toBe('true'); |
| 52 | + expect(checkboxes[1].getAttribute('aria-checked')).toBe('false'); |
| 53 | + }); |
62 | 54 |
|
63 |
| - fireEvent.click(checkboxes[0]); |
64 |
| - expect(toggleFeaturePreview).toHaveBeenCalledWith('feature1', true); |
| 55 | + it('checking a checkbox should toggle feature previews', () => { |
| 56 | + const { getAllByRole } = render(h(FeaturePreviews)); |
| 57 | + const checkboxes = getAllByRole('checkbox'); |
65 | 58 |
|
66 |
| - fireEvent.click(checkboxes[0]); |
67 |
| - expect(toggleFeaturePreview).toHaveBeenCalledWith('feature1', false); |
68 |
| - }); |
| 59 | + fireEvent.click(checkboxes[0]); |
| 60 | + expect(toggleFeaturePreview).toHaveBeenCalledWith('feature1', true); |
69 | 61 |
|
70 |
| - it('should render documentation link if provided', () => { |
71 |
| - const { getAllByText } = render(h(FeaturePreviews)); |
72 |
| - const docLinks = getAllByText('Documentation'); |
73 |
| - expect(docLinks.length).toBe(1); |
74 |
| - expect(docLinks[0].getAttribute('href')).toBe('https://example.com/feature-1-docs'); |
75 |
| - }); |
76 |
| - |
77 |
| - it('should render feedback link if provided', () => { |
78 |
| - const { getAllByText } = render(h(FeaturePreviews)); |
79 |
| - const feedbackLinks = getAllByText('Submit feedback'); |
80 |
| - expect(feedbackLinks.length).toBe(1); |
81 |
| - expect(feedbackLinks[0].getAttribute('href')).toBe('mailto:[email protected]'); |
82 |
| - }); |
| 62 | + fireEvent.click(checkboxes[0]); |
| 63 | + expect(toggleFeaturePreview).toHaveBeenCalledWith('feature1', false); |
83 | 64 | });
|
84 | 65 |
|
85 |
| - it.each([{ app: generateTestAppWithGoogleWorkspace() }, { app: generateTestAppWithAzureWorkspace() }])( |
86 |
| - 'should enable pause for azure and google', |
87 |
| - async ({ app }) => { |
88 |
| - // Arrange |
89 |
| - const pauseComputeAndRefresh = jest.fn(); |
| 66 | + it('should render documentation link if provided', () => { |
| 67 | + const { getAllByText } = render(h(FeaturePreviews)); |
| 68 | + const docLinks = getAllByText('Documentation'); |
| 69 | + expect(docLinks.length).toBe(1); |
| 70 | + expect(docLinks[0].getAttribute('href')).toBe('https://example.com/feature-1-docs'); |
| 71 | + }); |
90 | 72 |
|
91 |
| - await act(async () => { |
92 |
| - render( |
93 |
| - h(PauseButton, { |
94 |
| - computeType: 'app', |
95 |
| - cloudEnvironment: app, |
96 |
| - currentUser: app.auditInfo.creator, |
97 |
| - pauseComputeAndRefresh, |
98 |
| - }) |
99 |
| - ); |
100 |
| - }); |
101 |
| - // Act |
102 |
| - const pauseButton = screen.getByText('Pause'); |
103 |
| - // Assert |
104 |
| - expect(pauseButton).toBeEnabled(); |
105 |
| - // Act |
106 |
| - await userEvent.click(pauseButton); |
107 |
| - // Assert |
108 |
| - expect(pauseComputeAndRefresh).toHaveBeenCalled(); |
109 |
| - } |
110 |
| - ); |
| 73 | + it('should render feedback link if provided', () => { |
| 74 | + const { getAllByText } = render(h(FeaturePreviews)); |
| 75 | + const feedbackLinks = getAllByText('Submit feedback'); |
| 76 | + expect(feedbackLinks.length).toBe(1); |
| 77 | + expect(feedbackLinks[0].getAttribute('href')).toBe('mailto:[email protected]'); |
| 78 | + }); |
111 | 79 | });
|
0 commit comments