Skip to content

Commit 0d204a9

Browse files
committed
fix frontend bug
1 parent 3b1656e commit 0d204a9

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

contentcuration/contentcuration/frontend/channelEdit/components/sidePanels/SubmitToCommunityLibrarySidePanel/__tests__/SubmitToCommunityLibrarySidePanel.spec.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ async function makeWrapper({ channel, publishedData, latestSubmission }) {
3434
const isLoading = ref(true);
3535
const isFinished = ref(false);
3636

37+
store.state.currentChannel.currentChannelId = channel.id;
38+
store.commit('channel/ADD_CHANNEL', channel);
39+
3740
usePublishedData.mockReturnValue({
3841
isLoading,
3942
isFinished,
@@ -74,9 +77,9 @@ const publishedNonPublicChannel = {
7477
};
7578

7679
const publicChannel = {
77-
id: 'published-non-public-channel',
80+
id: 'public-channel',
7881
version: 2,
79-
name: 'Published Non-Public Channel',
82+
name: 'Public Channel',
8083
published: true,
8184
public: true,
8285
};
@@ -105,6 +108,10 @@ const publishedData = {
105108
const submittedLatestSubmission = { channel_version: 2, status: CommunityLibraryStatus.PENDING };
106109

107110
describe('SubmitToCommunityLibrarySidePanel', () => {
111+
beforeEach(() => {
112+
store.state.currentChannel.currentChannelId = null;
113+
store.state.channel.channelsMap = {};
114+
});
108115
describe('correct warnings are shown', () => {
109116
it('when channel is published, not public and not submitted', async () => {
110117
const wrapper = await makeWrapper({
@@ -377,7 +384,7 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
377384
});
378385

379386
const descriptionTextbox = wrapper.findComponent('.description-textbox');
380-
expect(descriptionTextbox.props('disabled')).toBe(false);
387+
expect(descriptionTextbox.props('disabled')).toBe(true);
381388
});
382389
});
383390

@@ -466,6 +473,7 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
466473
});
467474

468475
it('the panel closes', async () => {
476+
jest.useFakeTimers();
469477
const wrapper = await makeWrapper({
470478
channel: publishedNonPublicChannel,
471479
publishedData,
@@ -479,9 +487,11 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
479487
await submitButton.trigger('click');
480488

481489
expect(wrapper.emitted('close')).toBeTruthy();
490+
jest.useRealTimers();
482491
});
483492

484493
it('a submission snackbar is shown', async () => {
494+
jest.useFakeTimers();
485495
const wrapper = await makeWrapper({
486496
channel: publishedNonPublicChannel,
487497
publishedData,
@@ -493,14 +503,15 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
493503

494504
const submitButton = wrapper.find('[data-test="submit-button"]');
495505
await submitButton.trigger('click');
496-
497-
jest.useFakeTimers();
506+
await wrapper.vm.$nextTick();
498507

499508
expect(store.getters['snackbarIsVisible']).toBe(true);
500509
expect(CommunityLibrarySubmission.create).not.toHaveBeenCalled();
510+
jest.useRealTimers();
501511
});
502512

503513
it('the submission is created after a timeout', async () => {
514+
jest.useFakeTimers();
504515
const wrapper = await makeWrapper({
505516
channel: publishedNonPublicChannel,
506517
publishedData,
@@ -512,20 +523,22 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
512523

513524
const countryField = wrapper.findComponent(CountryField);
514525
await countryField.vm.$emit('input', ['Czech Republic']);
515-
516-
jest.useFakeTimers();
526+
await wrapper.vm.$nextTick();
517527

518528
const submitButton = wrapper.find('[data-test="submit-button"]');
519529
await submitButton.trigger('click');
530+
await wrapper.vm.$nextTick();
520531

521532
jest.runAllTimers();
533+
await wrapper.vm.$nextTick();
522534

523535
expect(CommunityLibrarySubmission.create).toHaveBeenCalledWith({
524536
description: 'Some description',
525537
channel: publishedNonPublicChannel.id,
526538
countries: ['CZ'],
527539
categories: [Categories.SCHOOL],
528540
});
541+
jest.useRealTimers();
529542
});
530543
});
531544

contentcuration/contentcuration/frontend/channelEdit/components/sidePanels/SubmitToCommunityLibrarySidePanel/index.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@
9999
<div class="channel-title">
100100
{{
101101
channelVersion$({
102-
name: currentChannel?.name || '',
103-
version: currentChannel?.version || 0,
102+
name: currentChannel ? currentChannel.name : '',
103+
version: currentChannel ? currentChannel.version : 0,
104104
})
105105
}}
106106
</div>
@@ -158,11 +158,7 @@
158158
:label="confirmReplacementText$()"
159159
data-test="replacement-confirmation-checkbox"
160160
class="replacement-checkbox"
161-
@change="
162-
value => {
163-
replacementConfirmed = value;
164-
}
165-
"
161+
@change="onReplacementChange"
166162
/>
167163
</div>
168164
</template>
@@ -434,6 +430,10 @@
434430
return store.dispatch('showSnackbar', params);
435431
}
436432
433+
function onReplacementChange(value) {
434+
replacementConfirmed.value = value;
435+
}
436+
437437
function onSubmit() {
438438
// It should be possible to undo a submission within a short time window
439439
// in case the user made a mistake and wants to change something.
@@ -477,6 +477,7 @@
477477
countries,
478478
description,
479479
replacementConfirmed,
480+
onReplacementChange,
480481
latestSubmissionIsLoading,
481482
latestSubmissionIsFinished,
482483
latestSubmissionStatus,

0 commit comments

Comments
 (0)