Skip to content

Commit 08941f2

Browse files
authored
[UIE-130] Move Environments tests out of FeaturePreviews tests (#4253)
1 parent aacee4c commit 08941f2

File tree

2 files changed

+87
-90
lines changed

2 files changed

+87
-90
lines changed

Diff for: src/analysis/Environments/Environments.test.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
generateTestDiskWithGoogleWorkspace,
1515
generateTestListGoogleRuntime,
1616
} from 'src/analysis/_testData/testData';
17-
import { EnvironmentNavActions, Environments } from 'src/analysis/Environments/Environments';
17+
import { EnvironmentNavActions, Environments, PauseButton } from 'src/analysis/Environments/Environments';
1818
import { defaultComputeZone } from 'src/analysis/utils/runtime-utils';
1919
import { appToolLabels } from 'src/analysis/utils/tool-utils';
2020
import { useWorkspaces } from 'src/components/workspace-utils';
@@ -773,6 +773,35 @@ describe('Environments', () => {
773773
screen.getByText('Delete persistent disk?');
774774
});
775775
});
776+
777+
describe('PauseButton', () => {
778+
it.each([{ app: generateTestAppWithGoogleWorkspace() }, { app: generateTestAppWithAzureWorkspace() }])(
779+
'should enable pause for azure and google',
780+
async ({ app }) => {
781+
// Arrange
782+
const pauseComputeAndRefresh = jest.fn();
783+
784+
await act(async () => {
785+
render(
786+
h(PauseButton, {
787+
computeType: 'app',
788+
cloudEnvironment: app,
789+
currentUser: app.auditInfo.creator,
790+
pauseComputeAndRefresh,
791+
})
792+
);
793+
});
794+
// Act
795+
const pauseButton = screen.getByText('Pause');
796+
// Assert
797+
expect(pauseButton).toBeEnabled();
798+
// Act
799+
await userEvent.click(pauseButton);
800+
// Assert
801+
expect(pauseComputeAndRefresh).toHaveBeenCalled();
802+
}
803+
);
804+
});
776805
});
777806

778807
const getTextContentForColumn = (row, column) => getAllByRole(row, 'cell')[column].textContent;

Diff for: src/pages/FeaturePreviews.test.ts

+57-89
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,79 @@
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';
32
import { h } from 'react-hyperscript-helpers';
4-
import { generateTestAppWithAzureWorkspace, generateTestAppWithGoogleWorkspace } from 'src/analysis/_testData/testData';
5-
import { PauseButton } from 'src/analysis/Environments/Environments';
63
import { isFeaturePreviewEnabled, toggleFeaturePreview, useAvailableFeaturePreviews } from 'src/libs/feature-previews';
74
import { FeaturePreviews } from 'src/pages/FeaturePreviews';
85
import { asMockedFn, renderWithAppContexts as render } from 'src/testing/test-utils';
96

10-
jest.mock('src/libs/ajax');
117
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-
});
348

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,
3629
});
3730

38-
it('should render available feature previews', () => {
39-
const { getAllByRole } = render(h(FeaturePreviews));
40-
const cells = getAllByRole('cell');
31+
asMockedFn(isFeaturePreviewEnabled).mockReturnValue(false);
32+
});
4133

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');
4437

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();
4840

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+
});
5144

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');
5447

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');
5850

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+
});
6254

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');
6558

66-
fireEvent.click(checkboxes[0]);
67-
expect(toggleFeaturePreview).toHaveBeenCalledWith('feature1', false);
68-
});
59+
fireEvent.click(checkboxes[0]);
60+
expect(toggleFeaturePreview).toHaveBeenCalledWith('feature1', true);
6961

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);
8364
});
8465

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+
});
9072

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+
});
11179
});

0 commit comments

Comments
 (0)