|
1 |
| -import {initializeOrg} from 'sentry-test/initializeOrg'; |
2 | 1 | import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
|
3 | 2 |
|
4 |
| -import {initializeUrlState} from 'sentry/actionCreators/pageFilters'; |
| 3 | +import CodecovQueryParamsProvider from 'sentry/components/codecov/container/codecovParamsProvider'; |
5 | 4 | import {DatePicker} from 'sentry/components/codecov/datePicker/datePicker';
|
6 |
| -import OrganizationStore from 'sentry/stores/organizationStore'; |
7 |
| -import PageFiltersStore from 'sentry/stores/pageFiltersStore'; |
8 |
| - |
9 |
| -const {organization, router} = initializeOrg({ |
10 |
| - router: { |
11 |
| - location: { |
12 |
| - query: {}, |
13 |
| - pathname: '/codecov/tests', |
14 |
| - }, |
15 |
| - params: {}, |
16 |
| - }, |
17 |
| -}); |
18 | 5 |
|
19 | 6 | describe('DatePicker', function () {
|
20 |
| - beforeEach(() => { |
21 |
| - PageFiltersStore.init(); |
22 |
| - OrganizationStore.init(); |
23 |
| - |
24 |
| - OrganizationStore.onUpdate(organization, {replace: true}); |
25 |
| - PageFiltersStore.onInitializeUrlState( |
| 7 | + it('can change period', async function () { |
| 8 | + const {router} = render( |
| 9 | + <CodecovQueryParamsProvider> |
| 10 | + <DatePicker /> |
| 11 | + </CodecovQueryParamsProvider>, |
26 | 12 | {
|
27 |
| - projects: [], |
28 |
| - environments: [], |
29 |
| - datetime: { |
30 |
| - period: '7d', |
31 |
| - start: null, |
32 |
| - end: null, |
33 |
| - utc: false, |
| 13 | + initialRouterConfig: { |
| 14 | + location: { |
| 15 | + pathname: '/codecov/tests', |
| 16 | + query: {codecovPeriod: '7d'}, |
| 17 | + }, |
34 | 18 | },
|
35 |
| - }, |
36 |
| - new Set(['datetime']) |
| 19 | + } |
37 | 20 | );
|
38 |
| - }); |
39 |
| - |
40 |
| - it('can change period', async function () { |
41 |
| - render(<DatePicker />, { |
42 |
| - router, |
43 |
| - deprecatedRouterMocks: true, |
44 |
| - }); |
45 | 21 |
|
46 | 22 | await userEvent.click(screen.getByRole('button', {name: '7D', expanded: false}));
|
47 | 23 | await userEvent.click(screen.getByRole('option', {name: 'Last 30 days'}));
|
48 | 24 |
|
| 25 | + expect(router.location.search).toBe('?codecovPeriod=30d'); |
| 26 | + |
49 | 27 | expect(
|
50 | 28 | screen.getByRole('button', {name: '30D', expanded: false})
|
51 | 29 | ).toBeInTheDocument();
|
52 |
| - expect(router.push).toHaveBeenCalledWith( |
53 |
| - expect.objectContaining({query: {statsPeriod: '30d'}}) |
54 |
| - ); |
55 |
| - expect(PageFiltersStore.getState()).toEqual({ |
56 |
| - isReady: true, |
57 |
| - shouldPersist: true, |
58 |
| - desyncedFilters: new Set(), |
59 |
| - pinnedFilters: new Set(['datetime']), |
60 |
| - selection: { |
61 |
| - datetime: { |
62 |
| - period: '30d', |
63 |
| - end: null, |
64 |
| - start: null, |
65 |
| - utc: false, |
66 |
| - }, |
67 |
| - environments: [], |
68 |
| - projects: [], |
69 |
| - }, |
70 |
| - }); |
71 | 30 | });
|
72 | 31 |
|
73 |
| - it('adjusts period if invalid', async function () { |
74 |
| - PageFiltersStore.reset(); |
75 |
| - PageFiltersStore.onInitializeUrlState( |
| 32 | + it('displays invalid button for invalid values', async function () { |
| 33 | + render( |
| 34 | + <CodecovQueryParamsProvider> |
| 35 | + <DatePicker /> |
| 36 | + </CodecovQueryParamsProvider>, |
76 | 37 | {
|
77 |
| - projects: [], |
78 |
| - environments: [], |
79 |
| - datetime: { |
80 |
| - period: '123d', |
81 |
| - start: null, |
82 |
| - end: null, |
83 |
| - utc: false, |
| 38 | + initialRouterConfig: { |
| 39 | + location: { |
| 40 | + pathname: '/codecov/tests', |
| 41 | + query: {codecovPeriod: '123Dd12'}, |
| 42 | + }, |
84 | 43 | },
|
85 |
| - }, |
86 |
| - new Set(['datetime']) |
| 44 | + } |
87 | 45 | );
|
88 | 46 |
|
89 |
| - render(<DatePicker />, { |
90 |
| - router, |
91 |
| - deprecatedRouterMocks: true, |
| 47 | + const button = await screen.findByRole('button', { |
| 48 | + name: 'Invalid Period', |
| 49 | + expanded: false, |
92 | 50 | });
|
93 |
| - |
94 |
| - // Confirm selection changed to default Codecov period |
95 |
| - const button = await screen.findByRole('button', {name: '24H', expanded: false}); |
96 | 51 | expect(button).toBeInTheDocument();
|
97 |
| - expect(router.push).toHaveBeenCalledWith( |
98 |
| - expect.objectContaining({query: {statsPeriod: '24h'}}) |
99 |
| - ); |
100 |
| - expect(PageFiltersStore.getState()).toEqual({ |
101 |
| - isReady: true, |
102 |
| - shouldPersist: true, |
103 |
| - desyncedFilters: new Set(), |
104 |
| - pinnedFilters: new Set(['datetime']), |
105 |
| - selection: { |
106 |
| - datetime: { |
107 |
| - period: '24h', |
108 |
| - end: null, |
109 |
| - start: null, |
110 |
| - utc: false, |
111 |
| - }, |
112 |
| - environments: [], |
113 |
| - projects: [], |
114 |
| - }, |
115 |
| - }); |
116 |
| - }); |
117 |
| - |
118 |
| - it('displays a desynced state message', async function () { |
119 |
| - const {organization: desyncOrganization, router: desyncRouter} = initializeOrg({ |
120 |
| - router: { |
121 |
| - location: { |
122 |
| - query: {statsPeriod: '7d'}, |
123 |
| - pathname: '/codecov/test', |
124 |
| - }, |
125 |
| - params: {}, |
126 |
| - }, |
127 |
| - }); |
128 |
| - |
129 |
| - PageFiltersStore.reset(); |
130 |
| - initializeUrlState({ |
131 |
| - memberProjects: [], |
132 |
| - nonMemberProjects: [], |
133 |
| - organization: desyncOrganization, |
134 |
| - queryParams: {statsPeriod: '30d'}, |
135 |
| - router: desyncRouter, |
136 |
| - shouldEnforceSingleProject: false, |
137 |
| - }); |
138 |
| - |
139 |
| - render(<DatePicker />, { |
140 |
| - router: desyncRouter, |
141 |
| - organization: desyncOrganization, |
142 |
| - deprecatedRouterMocks: true, |
143 |
| - }); |
144 |
| - |
145 |
| - await userEvent.click(screen.getByRole('button', {name: '30D', expanded: false})); |
146 |
| - expect(screen.getByText('Filters Updated')).toBeInTheDocument(); |
147 |
| - expect( |
148 |
| - screen.getByRole('button', {name: 'Restore Previous Values'}) |
149 |
| - ).toBeInTheDocument(); |
150 |
| - expect(screen.getByRole('button', {name: 'Got It'})).toBeInTheDocument(); |
151 | 52 | });
|
152 | 53 | });
|
0 commit comments