Skip to content

Commit 0e9ce29

Browse files
authored
Merge pull request #5341 from learningequality/dependabot/npm_and_yarn/jest-1ecd9637f0
chore(deps-dev): bump the jest group across 1 directory with 4 updates
2 parents e5631c8 + 8bc7f56 commit 0e9ce29

19 files changed

Lines changed: 1680 additions & 271 deletions

File tree

contentcuration/contentcuration/frontend/accounts/pages/AccountsMain.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
import PolicyModals from 'shared/views/policies/PolicyModals';
130130
import { policies } from 'shared/constants';
131131
import LanguageSwitcherList from 'shared/languageSwitcher/LanguageSwitcherList';
132+
import { redirectBrowser } from 'shared/utils/navigation';
132133
133134
export default {
134135
name: 'AccountsMain',
@@ -176,7 +177,7 @@
176177
.then(() => {
177178
this.loginFailedOffline = false;
178179
this.loginFailed = false;
179-
window.location.assign(this.nextParam || window.Urls.channels());
180+
redirectBrowser(this.nextParam || window.Urls.channels());
180181
})
181182
.catch(err => {
182183
this.busy = false;

contentcuration/contentcuration/frontend/accounts/pages/__tests__/accountsMain.spec.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import { render, screen, waitFor } from '@testing-library/vue';
22
import userEvent from '@testing-library/user-event';
33
import VueRouter from 'vue-router';
44
import AccountsMain from '../AccountsMain.vue';
5+
import { redirectBrowser } from 'shared/utils/navigation';
6+
7+
jest.mock('shared/utils/navigation', () => ({
8+
redirectBrowser: jest.fn(),
9+
}));
510

611
window.Urls = {
712
channels: () => '/channels/',
813
};
914

10-
const originalLocation = window.location;
11-
1215
const createRouter = () => {
1316
return new VueRouter({
1417
mode: 'abstract',
@@ -28,12 +31,9 @@ const createRouter = () => {
2831
function makeWrapper({ loginMock = jest.fn(), online = true, nextParam = null } = {}) {
2932
const router = createRouter();
3033

31-
delete window.location;
32-
window.location = {
33-
...originalLocation,
34-
search: nextParam ? `?next=${nextParam}` : '',
35-
assign: jest.fn(),
36-
};
34+
// Use pushState to set search params without triggering jsdom navigation
35+
const url = nextParam ? `http://studio.time/?next=${nextParam}` : 'http://studio.time/';
36+
window.history.pushState({}, '', url);
3737

3838
return {
3939
...render(AccountsMain, {
@@ -64,7 +64,8 @@ describe('AccountsMain', () => {
6464
});
6565

6666
afterEach(() => {
67-
window.location = originalLocation;
67+
jest.clearAllMocks();
68+
window.history.pushState({}, '', 'http://studio.time/');
6869
});
6970

7071
it('should render sign-in form with email, password fields and sign in button', () => {
@@ -112,7 +113,7 @@ describe('AccountsMain', () => {
112113

113114
// User is redirected to channels page
114115
await waitFor(() => {
115-
expect(window.location.assign).toHaveBeenCalledWith('/channels/');
116+
expect(redirectBrowser).toHaveBeenCalledWith('/channels/');
116117
});
117118
});
118119

@@ -133,7 +134,7 @@ describe('AccountsMain', () => {
133134

134135
// User is redirected to next URL
135136
await waitFor(() => {
136-
expect(window.location.assign).toHaveBeenCalledWith(nextUrl);
137+
expect(redirectBrowser).toHaveBeenCalledWith(nextUrl);
137138
});
138139
});
139140

contentcuration/contentcuration/frontend/channelEdit/components/AssessmentEditor/AssessmentEditor.spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ describe('AssessmentEditor', () => {
270270

271271
it('emits delete item event with a correct key', () => {
272272
expect(listeners.deleteItem).toHaveBeenCalledWith(ITEM2);
273-
expect(listeners.updateItems).toBeCalledTimes(1);
273+
expect(listeners.updateItems).toHaveBeenCalledTimes(1);
274274
});
275275

276276
it('emits update item events with updated order of items after the deleted item', () => {
@@ -288,7 +288,7 @@ describe('AssessmentEditor', () => {
288288
order: 2,
289289
},
290290
]);
291-
expect(listeners.updateItems).toBeCalledTimes(1);
291+
expect(listeners.updateItems).toHaveBeenCalledTimes(1);
292292
});
293293
});
294294

@@ -300,7 +300,7 @@ describe('AssessmentEditor', () => {
300300
});
301301

302302
it('emits add item event with a new item with a correct order', () => {
303-
expect(listeners.addItem).toBeCalledWith({
303+
expect(listeners.addItem).toHaveBeenCalledWith({
304304
contentnode: NODE_ID,
305305
question: '',
306306
type: AssessmentItemTypes.SINGLE_SELECTION,
@@ -330,7 +330,7 @@ describe('AssessmentEditor', () => {
330330
order: 4,
331331
},
332332
]);
333-
expect(listeners.updateItems).toBeCalledTimes(1);
333+
expect(listeners.updateItems).toHaveBeenCalledTimes(1);
334334
});
335335
});
336336

@@ -351,7 +351,7 @@ describe('AssessmentEditor', () => {
351351
order: 2,
352352
[DELAYED_VALIDATION]: true,
353353
});
354-
expect(listeners.addItem).toBeCalledTimes(1);
354+
expect(listeners.addItem).toHaveBeenCalledTimes(1);
355355
});
356356

357357
it('emits update item events with updated order of items below the new item', () => {
@@ -373,7 +373,7 @@ describe('AssessmentEditor', () => {
373373
order: 4,
374374
},
375375
]);
376-
expect(listeners.updateItems).toBeCalledTimes(1);
376+
expect(listeners.updateItems).toHaveBeenCalledTimes(1);
377377
});
378378
});
379379

@@ -395,7 +395,7 @@ describe('AssessmentEditor', () => {
395395
order: 1,
396396
},
397397
]);
398-
expect(listeners.updateItems).toBeCalledTimes(1);
398+
expect(listeners.updateItems).toHaveBeenCalledTimes(1);
399399
});
400400
});
401401

@@ -417,7 +417,7 @@ describe('AssessmentEditor', () => {
417417
order: 1,
418418
},
419419
]);
420-
expect(listeners.updateItems).toBeCalledTimes(1);
420+
expect(listeners.updateItems).toHaveBeenCalledTimes(1);
421421
});
422422
});
423423

@@ -427,7 +427,7 @@ describe('AssessmentEditor', () => {
427427
});
428428

429429
it('emits add item event with a new item with a correct order', () => {
430-
expect(listeners.addItem).toBeCalledWith({
430+
expect(listeners.addItem).toHaveBeenCalledWith({
431431
contentnode: NODE_ID,
432432
question: '',
433433
type: AssessmentItemTypes.SINGLE_SELECTION,

contentcuration/contentcuration/frontend/channelList/views/Channel/CatalogList.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
import ChannelStar from './ChannelStar';
186186
import ChannelTokenModal from 'shared/views/channel/ChannelTokenModal';
187187
import Pagination from 'shared/views/Pagination';
188+
import { redirectBrowser } from 'shared/utils/navigation';
188189
import BottomBar from 'shared/views/BottomBar';
189190
import ToolBar from 'shared/views/ToolBar';
190191
import OfflineText from 'shared/views/OfflineText';
@@ -366,7 +367,7 @@
366367
},
367368
onCardClick(channel) {
368369
if (this.loggedIn) {
369-
window.location.assign(window.Urls.channel(channel.id));
370+
redirectBrowser(window.Urls.channel(channel.id));
370371
} else {
371372
this.$router.push(this.getChannelDetailsRoute(channel));
372373
}

contentcuration/contentcuration/frontend/channelList/views/Channel/StudioMyChannels/__tests__/StudioMyChannels.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import VueRouter from 'vue-router';
44
import { Store } from 'vuex';
55
import StudioMyChannels from '../index.vue';
66
import { ChannelListTypes } from 'shared/constants';
7+
import { redirectBrowser } from 'shared/utils/navigation';
78

8-
const originalLocation = window.location;
9+
jest.mock('shared/utils/navigation', () => ({
10+
redirectBrowser: jest.fn(),
11+
}));
912

1013
const router = new VueRouter({
1114
routes: [
@@ -104,7 +107,7 @@ describe('StudioMyChannels', () => {
104107
});
105108

106109
afterEach(() => {
107-
window.location = originalLocation;
110+
jest.restoreAllMocks();
108111
});
109112

110113
it('calls the load channel list action with correct parameters on mount', () => {
@@ -152,14 +155,11 @@ describe('StudioMyChannels', () => {
152155
});
153156

154157
it('navigates to channel via window.location when card clicked', async () => {
155-
delete window.location;
156-
window.location = { ...originalLocation, assign: jest.fn() };
157-
158158
renderComponent();
159159
const cards = await screen.findAllByTestId('channel-card');
160160
await userEvent.click(cards[0]);
161161

162-
expect(window.location.assign).toHaveBeenCalledWith('channel');
162+
expect(redirectBrowser).toHaveBeenCalledWith('channel');
163163
});
164164

165165
describe('cards footer actions', () => {

contentcuration/contentcuration/frontend/channelList/views/Channel/StudioMyChannels/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import DeleteChannelModal from '../DeleteChannelModal';
8585
import ChannelTokenModal from 'shared/views/channel/ChannelTokenModal';
8686
import { ChannelListTypes } from 'shared/constants';
87+
import { redirectBrowser } from 'shared/utils/navigation';
8788
8889
export default {
8990
name: 'StudioMyChannels',
@@ -138,7 +139,7 @@
138139
});
139140
},
140141
onCardClick(channel) {
141-
window.location.assign(window.Urls.channel(channel.id));
142+
redirectBrowser(window.Urls.channel(channel.id));
142143
},
143144
getDropdownItems(channel) {
144145
const items = [

contentcuration/contentcuration/frontend/channelList/views/Channel/StudioStarredChannels/__tests__/StudioStarredChannels.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import VueRouter from 'vue-router';
44
import { Store } from 'vuex';
55
import StudioStarredChannels from '../index';
66
import { ChannelListTypes } from 'shared/constants';
7+
import { redirectBrowser } from 'shared/utils/navigation';
78

8-
const originalLocation = window.location;
9+
jest.mock('shared/utils/navigation', () => ({
10+
redirectBrowser: jest.fn(),
11+
}));
912

1013
const router = new VueRouter({
1114
routes: [
@@ -94,7 +97,7 @@ describe('StudioStarredChannels', () => {
9497
});
9598

9699
afterEach(() => {
97-
window.location = originalLocation;
100+
jest.restoreAllMocks();
98101
});
99102

100103
it('calls the load channel list action with correct parameters on mount', () => {
@@ -121,14 +124,11 @@ describe('StudioStarredChannels', () => {
121124
});
122125

123126
it('navigates to channel via window.location when card clicked', async () => {
124-
delete window.location;
125-
window.location = { ...originalLocation, assign: jest.fn() };
126-
127127
renderComponent();
128128
const cards = await screen.findAllByTestId('channel-card');
129129
await userEvent.click(cards[0]);
130130

131-
expect(window.location.assign).toHaveBeenCalledWith('channel');
131+
expect(redirectBrowser).toHaveBeenCalledWith('channel');
132132
});
133133

134134
describe('cards footer actions', () => {

contentcuration/contentcuration/frontend/channelList/views/Channel/StudioStarredChannels/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import RemoveChannelFromListModal from '../RemoveChannelFromListModal';
7777
import ChannelTokenModal from 'shared/views/channel/ChannelTokenModal';
7878
import { ChannelListTypes } from 'shared/constants';
79+
import { redirectBrowser } from 'shared/utils/navigation';
7980
8081
export default {
8182
name: 'StudioStarredChannels',
@@ -117,7 +118,7 @@
117118
if (!val) this.tokenChannelId = null;
118119
},
119120
onCardClick(channel) {
120-
window.location.assign(window.Urls.channel(channel.id));
121+
redirectBrowser(window.Urls.channel(channel.id));
121122
},
122123
getDropdownItems(channel) {
123124
const items = [];

contentcuration/contentcuration/frontend/channelList/views/Channel/StudioViewOnlyChannels/__tests__/StudioViewOnlyChannels.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import VueRouter from 'vue-router';
44
import { Store } from 'vuex';
55
import StudioViewOnlyChannels from '../index';
66
import { ChannelListTypes } from 'shared/constants';
7+
import { redirectBrowser } from 'shared/utils/navigation';
78

8-
const originalLocation = window.location;
9+
jest.mock('shared/utils/navigation', () => ({
10+
redirectBrowser: jest.fn(),
11+
}));
912

1013
const router = new VueRouter({
1114
routes: [
@@ -103,7 +106,7 @@ describe('StudioViewOnlyChannels', () => {
103106
});
104107

105108
afterEach(() => {
106-
window.location = originalLocation;
109+
jest.restoreAllMocks();
107110
});
108111

109112
it('calls the load channel list action with correct parameters on mount', () => {
@@ -135,14 +138,11 @@ describe('StudioViewOnlyChannels', () => {
135138
});
136139

137140
it('navigates to channel via window.location when card clicked', async () => {
138-
delete window.location;
139-
window.location = { ...originalLocation, assign: jest.fn() };
140-
141141
renderComponent();
142142
const cards = await screen.findAllByTestId('channel-card');
143143
await userEvent.click(cards[0]);
144144

145-
expect(window.location.assign).toHaveBeenCalledWith('channel');
145+
expect(redirectBrowser).toHaveBeenCalledWith('channel');
146146
});
147147

148148
describe('cards footer actions', () => {

contentcuration/contentcuration/frontend/channelList/views/Channel/StudioViewOnlyChannels/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import RemoveChannelFromListModal from '../RemoveChannelFromListModal';
7474
import ChannelTokenModal from 'shared/views/channel/ChannelTokenModal';
7575
import { ChannelListTypes } from 'shared/constants';
76+
import { redirectBrowser } from 'shared/utils/navigation';
7677
7778
export default {
7879
name: 'StudioViewOnlyChannels',
@@ -120,7 +121,7 @@
120121
if (!val) this.tokenChannelId = null;
121122
},
122123
onCardClick(channel) {
123-
window.location.assign(window.Urls.channel(channel.id));
124+
redirectBrowser(window.Urls.channel(channel.id));
124125
},
125126
getDropdownItems(channel) {
126127
const items = [{ label: this.$tr('removeChannel'), icon: 'trash', value: 'remove' }];

0 commit comments

Comments
 (0)