Skip to content

Commit ef3a4e4

Browse files
authored
fix: [M3-9986] - Selected Geographical Area state in Distributed Region select (linode#12584)
## Description 📝 Fix selected Geographical Area persistence issue when switching between Core and Distributed Region tabs ## How to test 🧪 ### Prerequisites (How to setup test environment) - Ensure gecko feature flag is enabled and your account has gecko customer tags (reach out for more info) ### Verification steps (How to verify changes) - [ ] Checkout this branch or preview link and go to the Linode Create page - [ ] Click on the Distributed Region tab, select a value other than All, click on the Core Region tab, switch back to the Distributed tab - [ ] You should see the Geographical Area persist the value you selected before switching and the Regions are still filtered accordingly
1 parent a0b6aa5 commit ef3a4e4

File tree

3 files changed

+63
-55
lines changed

3 files changed

+63
-55
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Fixed
3+
---
4+
5+
Geographical Area state in Distributed Region select in Linode Create flow ([#12584](https://github.com/linode/manager/pull/12584))
Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { screen } from '@testing-library/react';
12
import { userEvent } from '@testing-library/user-event';
23
import React from 'react';
34

@@ -6,36 +7,14 @@ import { renderWithThemeAndHookFormContext } from 'src/utilities/testHelpers';
67

78
import { TwoStepRegion } from './TwoStepRegion';
89

9-
const queryMocks = vi.hoisted(() => ({
10-
useNavigate: vi.fn(),
11-
useParams: vi.fn(),
12-
useSearch: vi.fn(),
13-
}));
14-
15-
vi.mock('@tanstack/react-router', async () => {
16-
const actual = await vi.importActual('@tanstack/react-router');
17-
return {
18-
...actual,
19-
useNavigate: queryMocks.useNavigate,
20-
useSearch: queryMocks.useSearch,
21-
useParams: queryMocks.useParams,
22-
};
23-
});
24-
2510
describe('TwoStepRegion', () => {
26-
beforeEach(() => {
27-
queryMocks.useNavigate.mockReturnValue(vi.fn());
28-
queryMocks.useSearch.mockReturnValue({});
29-
queryMocks.useParams.mockReturnValue({});
30-
});
31-
3211
it('should render a heading and docs link', () => {
33-
const { getAllByText, getByText } = renderWithThemeAndHookFormContext({
12+
renderWithThemeAndHookFormContext({
3413
component: <TwoStepRegion onChange={vi.fn()} />,
3514
});
3615

37-
const heading = getAllByText('Region')[0];
38-
const link = getByText(DOCS_LINK_LABEL_DC_PRICING);
16+
const heading = screen.getAllByText('Region')[0];
17+
const link = screen.getByText(DOCS_LINK_LABEL_DC_PRICING);
3918

4019
expect(heading).toBeVisible();
4120
expect(heading.tagName).toBe('H2');
@@ -46,73 +25,94 @@ describe('TwoStepRegion', () => {
4625
});
4726

4827
it('should render two tabs, Core and Distributed', () => {
49-
const { getAllByRole } = renderWithThemeAndHookFormContext({
28+
renderWithThemeAndHookFormContext({
5029
component: <TwoStepRegion onChange={vi.fn()} />,
5130
});
5231

53-
const tabs = getAllByRole('tab');
54-
expect(tabs[0]).toHaveTextContent('Core');
55-
expect(tabs[1]).toHaveTextContent('Distributed');
32+
const [coreTab, distributedTab] = screen.getAllByRole('tab');
33+
34+
expect(coreTab).toHaveTextContent('Core');
35+
expect(distributedTab).toHaveTextContent('Distributed');
5636
});
5737

5838
it('should render a Region Select for the Core tab', () => {
59-
const { getByPlaceholderText } = renderWithThemeAndHookFormContext({
39+
renderWithThemeAndHookFormContext({
6040
component: <TwoStepRegion onChange={vi.fn()} />,
6141
});
6242

63-
const select = getByPlaceholderText('Select a Region');
43+
const regionSelect = screen.getByPlaceholderText('Select a Region');
6444

65-
expect(select).toBeVisible();
66-
expect(select).toBeEnabled();
45+
expect(regionSelect).toBeVisible();
46+
expect(regionSelect).toBeEnabled();
6747
});
6848

6949
it('should only display core regions in the Core tab region select', async () => {
70-
const { getByPlaceholderText, getByRole } =
71-
renderWithThemeAndHookFormContext({
72-
component: <TwoStepRegion onChange={vi.fn()} />,
73-
});
50+
renderWithThemeAndHookFormContext({
51+
component: <TwoStepRegion onChange={vi.fn()} />,
52+
});
7453

75-
const select = getByPlaceholderText('Select a Region');
76-
await userEvent.click(select);
54+
const regionSelect = screen.getByPlaceholderText('Select a Region');
55+
await userEvent.click(regionSelect);
7756

78-
const dropdown = getByRole('listbox');
57+
const dropdown = screen.getByRole('listbox');
7958
expect(dropdown.innerHTML).toContain('US, Newark');
8059
expect(dropdown.innerHTML).not.toContain(
8160
'US, Gecko Distributed Region Test'
8261
);
8362
});
8463

8564
it('should only display distributed regions in the Distributed tab region select', async () => {
86-
const { getAllByRole, getByPlaceholderText, getByRole } =
87-
renderWithThemeAndHookFormContext({
88-
component: <TwoStepRegion onChange={vi.fn()} />,
89-
});
65+
renderWithThemeAndHookFormContext({
66+
component: <TwoStepRegion onChange={vi.fn()} />,
67+
});
9068

91-
const tabs = getAllByRole('tab');
92-
await userEvent.click(tabs[1]);
69+
const distributedTab = screen.getByRole('tab', { name: 'Distributed' });
70+
await userEvent.click(distributedTab);
9371

94-
const select = getByPlaceholderText('Select a Region');
95-
await userEvent.click(select);
72+
const regionSelect = screen.getByPlaceholderText('Select a Region');
73+
await userEvent.click(regionSelect);
9674

97-
const dropdown = getByRole('listbox');
75+
const dropdown = screen.getByRole('listbox');
9876
expect(dropdown.innerHTML).toContain('US, Gecko Distributed Region Test');
9977
expect(dropdown.innerHTML).not.toContain('US, Newark');
10078
});
10179

10280
it('should render a Geographical Area select with All pre-selected and a Region Select for the Distributed tab', async () => {
103-
const { getAllByRole } = renderWithThemeAndHookFormContext({
81+
renderWithThemeAndHookFormContext({
10482
component: <TwoStepRegion onChange={vi.fn()} />,
10583
});
10684

107-
const tabs = getAllByRole('tab');
108-
await userEvent.click(tabs[1]);
85+
const [, distributedTab] = screen.getAllByRole('tab');
86+
await userEvent.click(distributedTab);
10987

110-
const inputs = getAllByRole('combobox');
111-
const geographicalAreaSelect = inputs[0];
112-
const regionSelect = inputs[1];
88+
const [geographicalAreaSelect, regionSelect] =
89+
screen.getAllByRole('combobox');
11390

11491
expect(geographicalAreaSelect).toHaveAttribute('value', 'All');
11592
expect(regionSelect).toHaveAttribute('placeholder', 'Select a Region');
11693
expect(regionSelect).toBeEnabled();
11794
});
95+
96+
it('should persist the selected Geographical Area when switching between the Core and Distributed tabs', async () => {
97+
renderWithThemeAndHookFormContext({
98+
component: <TwoStepRegion onChange={vi.fn()} />,
99+
});
100+
101+
const [coreTab, distributedTab] = screen.getAllByRole('tab');
102+
await userEvent.click(distributedTab);
103+
104+
const geographicalAreaSelect = screen.getByLabelText('Geographical Area');
105+
// Open the dropdown
106+
await userEvent.click(geographicalAreaSelect);
107+
108+
const lastMonthOption = screen.getByText('North America');
109+
await userEvent.click(lastMonthOption);
110+
expect(geographicalAreaSelect).toHaveAttribute('value', 'North America');
111+
112+
// Geographical area selection should persist after switching tabs
113+
await userEvent.click(coreTab);
114+
await userEvent.click(distributedTab);
115+
const geographicalAreaSelect2 = screen.getByLabelText('Geographical Area');
116+
expect(geographicalAreaSelect2).toHaveAttribute('value', 'North America');
117+
});
118118
});

packages/manager/src/features/Linodes/LinodeCreate/TwoStepRegion.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ export const TwoStepRegion = (props: CombinedProps) => {
140140
}
141141
}}
142142
options={GEOGRAPHICAL_AREA_OPTIONS}
143+
value={GEOGRAPHICAL_AREA_OPTIONS.find(
144+
(option) => option.value === regionFilter
145+
)}
143146
/>
144147
<RegionSelect
145148
currentCapability="Linodes"

0 commit comments

Comments
 (0)