From ef892cff81495959597d03c6233f11f324181414 Mon Sep 17 00:00:00 2001
From: ANAS727189
Date: Fri, 3 Oct 2025 21:03:58 +0530
Subject: [PATCH 1/8] feat: Replace MessageDialog with KModal in EditModal
Replace upload progress and save failed dialogs with KModal components.
Maintains existing functionality and adds unit tests.
Fixes #5422
---
.../channelEdit/components/edit/EditModal.vue | 52 +++---
.../edit/__tests__/editModal.kmodal.spec.js | 169 ++++++++++++++++++
2 files changed, 195 insertions(+), 26 deletions(-)
create mode 100644 contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
diff --git a/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue b/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue
index 5217f7ac02..230f0e184c 100644
--- a/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue
+++ b/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue
@@ -193,49 +193,49 @@
-
-
- {{ $tr('uploadInProgressText') }}
+
+
{{ $tr('dismissDialogButton') }}
-
-
+
{{ $tr('cancelUploadsButton') }}
-
+
-
+
-
-
- {{ $tr('saveFailedText') }}
+
+
{{ $tr('okButton') }}
-
-
+
{{ $tr('closeWithoutSavingButton') }}
-
+
-
+
diff --git a/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js b/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
new file mode 100644
index 0000000000..8ef27aaa35
--- /dev/null
+++ b/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
@@ -0,0 +1,169 @@
+/**
+ * Simple integration test to verify KModal dialogs in EditModal work correctly
+ * This test focuses only on the two specific dialogs we migrated from MessageDialog to KModal
+ */
+
+const MockEditModalDialogs = {
+ template: `
+
+
+
{{ uploadInProgressHeader }}
+
{{ uploadInProgressText }}
+
+
+
+
+
+
{{ saveFailedHeader }}
+
{{ saveFailedText }}
+
+
+
+
+ `,
+ data() {
+ return {
+ promptUploading: false,
+ promptFailed: false,
+ uploadInProgressHeader: 'Upload in progress',
+ uploadInProgressText: 'Uploads that are in progress will be lost if you exit',
+ dismissDialogButton: 'Cancel',
+ cancelUploadsButton: 'Exit',
+ saveFailedHeader: 'Save failed',
+ saveFailedText: 'There was a problem saving your content',
+ okButton: 'OK',
+ closeWithoutSavingButton: 'Close without saving',
+ };
+ },
+ methods: {
+ closeModal() {
+ },
+ },
+ };
+
+ import { mount } from '@vue/test-utils';
+
+ function makeWrapper() {
+ return mount(MockEditModalDialogs);
+ }
+
+ describe('EditModal KModal Dialogs', () => {
+ let wrapper;
+
+ beforeEach(() => {
+ wrapper = makeWrapper();
+ jest.clearAllMocks();
+ });
+
+ describe('Upload in progress dialog', () => {
+ it('should not show dialog when promptUploading is false', () => {
+ expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(false);
+ });
+
+ it('should show dialog when promptUploading is true', async () => {
+ await wrapper.setData({ promptUploading: true });
+
+ const dialog = wrapper.find('[data-testid="upload-dialog"]');
+ expect(dialog.exists()).toBe(true);
+ expect(dialog.text()).toContain('Upload in progress');
+ expect(dialog.text()).toContain('Uploads that are in progress will be lost if you exit');
+ });
+
+ it('should have correct buttons with proper functionality', async () => {
+ await wrapper.setData({ promptUploading: true });
+
+ const dialog = wrapper.find('[data-testid="upload-dialog"]');
+ expect(dialog.text()).toContain('Cancel');
+ expect(dialog.text()).toContain('Exit');
+
+ const cancelButton = wrapper.find('[data-test="canceluploads"]');
+ expect(cancelButton.exists()).toBe(true);
+ });
+
+ it('should close dialog when dismiss button is clicked', async () => {
+ await wrapper.setData({ promptUploading: true });
+
+ const buttons = wrapper.findAll('button');
+ const dismissButton = buttons.at(0);
+
+ await dismissButton.trigger('click');
+ expect(wrapper.vm.promptUploading).toBe(false);
+ });
+
+ it('should call closeModal when cancel uploads button is clicked', async () => {
+ const closeModalSpy = jest.spyOn(wrapper.vm, 'closeModal');
+ await wrapper.setData({ promptUploading: true });
+
+ const cancelButton = wrapper.find('[data-test="canceluploads"]');
+ await cancelButton.trigger('click');
+
+ expect(closeModalSpy).toHaveBeenCalled();
+ });
+ });
+
+ describe('Save failed dialog', () => {
+ it('should not show dialog when promptFailed is false', () => {
+ expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(false);
+ });
+
+ it('should show dialog when promptFailed is true', async () => {
+ await wrapper.setData({ promptFailed: true });
+
+ const dialog = wrapper.find('[data-testid="failed-dialog"]');
+ expect(dialog.exists()).toBe(true);
+ expect(dialog.text()).toContain('Save failed');
+ expect(dialog.text()).toContain('There was a problem saving your content');
+ });
+
+ it('should have correct buttons with proper functionality', async () => {
+ await wrapper.setData({ promptFailed: true });
+
+ const dialog = wrapper.find('[data-testid="failed-dialog"]');
+ expect(dialog.text()).toContain('OK');
+ expect(dialog.text()).toContain('Close without saving');
+ });
+
+ it('should close dialog when OK button is clicked', async () => {
+ await wrapper.setData({ promptFailed: true });
+
+ const buttons = wrapper.findAll('button');
+ const okButton = buttons.at(0);
+
+ await okButton.trigger('click');
+ expect(wrapper.vm.promptFailed).toBe(false);
+ });
+
+ it('should call closeModal when close without saving button is clicked', async () => {
+ const closeModalSpy = jest.spyOn(wrapper.vm, 'closeModal');
+ await wrapper.setData({ promptFailed: true });
+
+ const buttons = wrapper.findAll('button');
+ const closeButton = buttons.at(1);
+
+ await closeButton.trigger('click');
+ expect(closeModalSpy).toHaveBeenCalled();
+ });
+ });
+
+ describe('Dialog state management', () => {
+ it('should handle both dialogs independently', async () => {
+ expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(false);
+ expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(false);
+
+
+ await wrapper.setData({ promptUploading: true });
+ expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(true);
+ expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(false);
+
+
+ await wrapper.setData({ promptFailed: true });
+ expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(true);
+ expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(true);
+
+
+ await wrapper.setData({ promptUploading: false });
+ expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(false);
+ expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(true);
+ });
+ });
+});
\ No newline at end of file
From d378592796c0d461e18fb758fc1e4567eef011f2 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci-lite[bot]"
<117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Date: Mon, 6 Oct 2025 13:57:46 +0000
Subject: [PATCH 2/8] [pre-commit.ci lite] apply automatic fixes
---
.../channelEdit/components/edit/EditModal.vue | 8 +-
.../edit/__tests__/editModal.kmodal.spec.js | 268 +++++++++---------
2 files changed, 134 insertions(+), 142 deletions(-)
diff --git a/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue b/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue
index 230f0e184c..7ec9971682 100644
--- a/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue
+++ b/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue
@@ -200,9 +200,7 @@
>
{{ $tr('uploadInProgressText') }}
-
+
{{ $tr('dismissDialogButton') }}
{{ $tr('saveFailedText') }}
-
+
{{ $tr('okButton') }}
{{ uploadInProgressHeader }}
@@ -12,7 +14,7 @@ const MockEditModalDialogs = {
-
+
{{ saveFailedHeader }}
{{ saveFailedText }}
@@ -21,149 +23,143 @@ const MockEditModalDialogs = {
`,
- data() {
- return {
- promptUploading: false,
- promptFailed: false,
- uploadInProgressHeader: 'Upload in progress',
- uploadInProgressText: 'Uploads that are in progress will be lost if you exit',
- dismissDialogButton: 'Cancel',
- cancelUploadsButton: 'Exit',
- saveFailedHeader: 'Save failed',
- saveFailedText: 'There was a problem saving your content',
- okButton: 'OK',
- closeWithoutSavingButton: 'Close without saving',
- };
- },
- methods: {
- closeModal() {
- },
- },
+ data() {
+ return {
+ promptUploading: false,
+ promptFailed: false,
+ uploadInProgressHeader: 'Upload in progress',
+ uploadInProgressText: 'Uploads that are in progress will be lost if you exit',
+ dismissDialogButton: 'Cancel',
+ cancelUploadsButton: 'Exit',
+ saveFailedHeader: 'Save failed',
+ saveFailedText: 'There was a problem saving your content',
+ okButton: 'OK',
+ closeWithoutSavingButton: 'Close without saving',
};
+ },
+ methods: {
+ closeModal() {},
+ },
+};
+
+function makeWrapper() {
+ return mount(MockEditModalDialogs);
+}
+
+describe('EditModal KModal Dialogs', () => {
+ let wrapper;
+
+ beforeEach(() => {
+ wrapper = makeWrapper();
+ jest.clearAllMocks();
+ });
+
+ describe('Upload in progress dialog', () => {
+ it('should not show dialog when promptUploading is false', () => {
+ expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(false);
+ });
+
+ it('should show dialog when promptUploading is true', async () => {
+ await wrapper.setData({ promptUploading: true });
+
+ const dialog = wrapper.find('[data-testid="upload-dialog"]');
+ expect(dialog.exists()).toBe(true);
+ expect(dialog.text()).toContain('Upload in progress');
+ expect(dialog.text()).toContain('Uploads that are in progress will be lost if you exit');
+ });
+
+ it('should have correct buttons with proper functionality', async () => {
+ await wrapper.setData({ promptUploading: true });
+
+ const dialog = wrapper.find('[data-testid="upload-dialog"]');
+ expect(dialog.text()).toContain('Cancel');
+ expect(dialog.text()).toContain('Exit');
+
+ const cancelButton = wrapper.find('[data-test="canceluploads"]');
+ expect(cancelButton.exists()).toBe(true);
+ });
+
+ it('should close dialog when dismiss button is clicked', async () => {
+ await wrapper.setData({ promptUploading: true });
+
+ const buttons = wrapper.findAll('button');
+ const dismissButton = buttons.at(0);
+
+ await dismissButton.trigger('click');
+ expect(wrapper.vm.promptUploading).toBe(false);
+ });
- import { mount } from '@vue/test-utils';
+ it('should call closeModal when cancel uploads button is clicked', async () => {
+ const closeModalSpy = jest.spyOn(wrapper.vm, 'closeModal');
+ await wrapper.setData({ promptUploading: true });
- function makeWrapper() {
- return mount(MockEditModalDialogs);
- }
+ const cancelButton = wrapper.find('[data-test="canceluploads"]');
+ await cancelButton.trigger('click');
- describe('EditModal KModal Dialogs', () => {
- let wrapper;
+ expect(closeModalSpy).toHaveBeenCalled();
+ });
+ });
+
+ describe('Save failed dialog', () => {
+ it('should not show dialog when promptFailed is false', () => {
+ expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(false);
+ });
+
+ it('should show dialog when promptFailed is true', async () => {
+ await wrapper.setData({ promptFailed: true });
+
+ const dialog = wrapper.find('[data-testid="failed-dialog"]');
+ expect(dialog.exists()).toBe(true);
+ expect(dialog.text()).toContain('Save failed');
+ expect(dialog.text()).toContain('There was a problem saving your content');
+ });
+
+ it('should have correct buttons with proper functionality', async () => {
+ await wrapper.setData({ promptFailed: true });
- beforeEach(() => {
- wrapper = makeWrapper();
- jest.clearAllMocks();
+ const dialog = wrapper.find('[data-testid="failed-dialog"]');
+ expect(dialog.text()).toContain('OK');
+ expect(dialog.text()).toContain('Close without saving');
});
- describe('Upload in progress dialog', () => {
- it('should not show dialog when promptUploading is false', () => {
- expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(false);
- });
-
- it('should show dialog when promptUploading is true', async () => {
- await wrapper.setData({ promptUploading: true });
-
- const dialog = wrapper.find('[data-testid="upload-dialog"]');
- expect(dialog.exists()).toBe(true);
- expect(dialog.text()).toContain('Upload in progress');
- expect(dialog.text()).toContain('Uploads that are in progress will be lost if you exit');
- });
-
- it('should have correct buttons with proper functionality', async () => {
- await wrapper.setData({ promptUploading: true });
-
- const dialog = wrapper.find('[data-testid="upload-dialog"]');
- expect(dialog.text()).toContain('Cancel');
- expect(dialog.text()).toContain('Exit');
-
- const cancelButton = wrapper.find('[data-test="canceluploads"]');
- expect(cancelButton.exists()).toBe(true);
- });
-
- it('should close dialog when dismiss button is clicked', async () => {
- await wrapper.setData({ promptUploading: true });
-
- const buttons = wrapper.findAll('button');
- const dismissButton = buttons.at(0);
-
- await dismissButton.trigger('click');
- expect(wrapper.vm.promptUploading).toBe(false);
- });
-
- it('should call closeModal when cancel uploads button is clicked', async () => {
- const closeModalSpy = jest.spyOn(wrapper.vm, 'closeModal');
- await wrapper.setData({ promptUploading: true });
-
- const cancelButton = wrapper.find('[data-test="canceluploads"]');
- await cancelButton.trigger('click');
-
- expect(closeModalSpy).toHaveBeenCalled();
- });
+ it('should close dialog when OK button is clicked', async () => {
+ await wrapper.setData({ promptFailed: true });
+
+ const buttons = wrapper.findAll('button');
+ const okButton = buttons.at(0);
+
+ await okButton.trigger('click');
+ expect(wrapper.vm.promptFailed).toBe(false);
});
- describe('Save failed dialog', () => {
- it('should not show dialog when promptFailed is false', () => {
- expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(false);
- });
-
- it('should show dialog when promptFailed is true', async () => {
- await wrapper.setData({ promptFailed: true });
-
- const dialog = wrapper.find('[data-testid="failed-dialog"]');
- expect(dialog.exists()).toBe(true);
- expect(dialog.text()).toContain('Save failed');
- expect(dialog.text()).toContain('There was a problem saving your content');
- });
-
- it('should have correct buttons with proper functionality', async () => {
- await wrapper.setData({ promptFailed: true });
-
- const dialog = wrapper.find('[data-testid="failed-dialog"]');
- expect(dialog.text()).toContain('OK');
- expect(dialog.text()).toContain('Close without saving');
- });
-
- it('should close dialog when OK button is clicked', async () => {
- await wrapper.setData({ promptFailed: true });
-
- const buttons = wrapper.findAll('button');
- const okButton = buttons.at(0);
-
- await okButton.trigger('click');
- expect(wrapper.vm.promptFailed).toBe(false);
- });
-
- it('should call closeModal when close without saving button is clicked', async () => {
- const closeModalSpy = jest.spyOn(wrapper.vm, 'closeModal');
- await wrapper.setData({ promptFailed: true });
-
- const buttons = wrapper.findAll('button');
- const closeButton = buttons.at(1);
-
- await closeButton.trigger('click');
- expect(closeModalSpy).toHaveBeenCalled();
- });
+ it('should call closeModal when close without saving button is clicked', async () => {
+ const closeModalSpy = jest.spyOn(wrapper.vm, 'closeModal');
+ await wrapper.setData({ promptFailed: true });
+
+ const buttons = wrapper.findAll('button');
+ const closeButton = buttons.at(1);
+
+ await closeButton.trigger('click');
+ expect(closeModalSpy).toHaveBeenCalled();
});
+ });
+
+ describe('Dialog state management', () => {
+ it('should handle both dialogs independently', async () => {
+ expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(false);
+ expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(false);
+
+ await wrapper.setData({ promptUploading: true });
+ expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(true);
+ expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(false);
+
+ await wrapper.setData({ promptFailed: true });
+ expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(true);
+ expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(true);
- describe('Dialog state management', () => {
- it('should handle both dialogs independently', async () => {
- expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(false);
- expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(false);
-
-
- await wrapper.setData({ promptUploading: true });
- expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(true);
- expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(false);
-
-
- await wrapper.setData({ promptFailed: true });
- expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(true);
- expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(true);
-
-
- await wrapper.setData({ promptUploading: false });
- expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(false);
- expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(true);
- });
+ await wrapper.setData({ promptUploading: false });
+ expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(false);
+ expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(true);
});
-});
\ No newline at end of file
+ });
+});
From d0a7c06618c9498488824b1cf625391349cdee37 Mon Sep 17 00:00:00 2001
From: ANAS727189
Date: Mon, 6 Oct 2025 20:59:13 +0530
Subject: [PATCH 3/8] Migrate editModal.kmodal.spec.js to @testing-library/vue
and fix linting issues
---
.../channelEdit/components/edit/EditModal.vue | 8 +-
.../edit/__tests__/editModal.kmodal.spec.js | 368 +++++++++++-------
2 files changed, 219 insertions(+), 157 deletions(-)
diff --git a/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue b/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue
index 230f0e184c..7ec9971682 100644
--- a/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue
+++ b/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue
@@ -200,9 +200,7 @@
>
{{ $tr('uploadInProgressText') }}
-
+
{{ $tr('dismissDialogButton') }}
{{ $tr('saveFailedText') }}
-
+
{{ $tr('okButton') }}
-
-
{{ uploadInProgressHeader }}
-
{{ uploadInProgressText }}
-
-
-
-
-
-
{{ saveFailedHeader }}
-
{{ saveFailedText }}
-
-
-
-
- `,
- data() {
- return {
- promptUploading: false,
- promptFailed: false,
- uploadInProgressHeader: 'Upload in progress',
- uploadInProgressText: 'Uploads that are in progress will be lost if you exit',
- dismissDialogButton: 'Cancel',
- cancelUploadsButton: 'Exit',
- saveFailedHeader: 'Save failed',
- saveFailedText: 'There was a problem saving your content',
- okButton: 'OK',
- closeWithoutSavingButton: 'Close without saving',
- };
- },
- methods: {
- closeModal() {
- },
- },
+ template: `
+
+
+
{{ uploadInProgressHeader }}
+
{{ uploadInProgressText }}
+
+
+
+
+
+
{{ saveFailedHeader }}
+
{{ saveFailedText }}
+
+
+
+
+ `,
+ data() {
+ return {
+ promptUploading: false,
+ promptFailed: false,
+ uploadInProgressHeader: 'Upload in progress',
+ uploadInProgressText: 'Uploads that are in progress will be lost if you exit',
+ dismissDialogButton: 'Cancel',
+ cancelUploadsButton: 'Exit',
+ saveFailedHeader: 'Save failed',
+ saveFailedText: 'There was a problem saving your content',
+ okButton: 'OK',
+ closeWithoutSavingButton: 'Close without saving',
};
+ },
+ methods: {
+ closeModal: jest.fn(),
+ },
+};
+
+describe('EditModal KModal Dialogs', () => {
+ describe('Upload in progress dialog', () => {
+ it('should not show dialog when promptUploading is false', () => {
+ render(MockEditModalDialogs, {
+ routes: new VueRouter(),
+ });
+ expect(screen.queryByTestId('upload-dialog')).not.toBeInTheDocument();
+ });
- import { mount } from '@vue/test-utils';
+ it('should show dialog when promptUploading is true', () => {
+ render(MockEditModalDialogs, {
+ routes: new VueRouter(),
+ data() {
+ return { promptUploading: true };
+ },
+ });
- function makeWrapper() {
- return mount(MockEditModalDialogs);
- }
+ expect(screen.getByTestId('upload-dialog')).toBeInTheDocument();
+ expect(screen.getByText('Upload in progress')).toBeInTheDocument();
+ expect(
+ screen.getByText('Uploads that are in progress will be lost if you exit'),
+ ).toBeInTheDocument();
+ });
- describe('EditModal KModal Dialogs', () => {
- let wrapper;
+ it('should have correct buttons with proper functionality', () => {
+ render(MockEditModalDialogs, {
+ routes: new VueRouter(),
+ data() {
+ return { promptUploading: true };
+ },
+ });
- beforeEach(() => {
- wrapper = makeWrapper();
- jest.clearAllMocks();
+ expect(screen.getByText('Cancel')).toBeInTheDocument();
+ expect(screen.getByText('Exit')).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Exit' })).toBeInTheDocument();
});
- describe('Upload in progress dialog', () => {
- it('should not show dialog when promptUploading is false', () => {
- expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(false);
- });
-
- it('should show dialog when promptUploading is true', async () => {
- await wrapper.setData({ promptUploading: true });
-
- const dialog = wrapper.find('[data-testid="upload-dialog"]');
- expect(dialog.exists()).toBe(true);
- expect(dialog.text()).toContain('Upload in progress');
- expect(dialog.text()).toContain('Uploads that are in progress will be lost if you exit');
- });
-
- it('should have correct buttons with proper functionality', async () => {
- await wrapper.setData({ promptUploading: true });
-
- const dialog = wrapper.find('[data-testid="upload-dialog"]');
- expect(dialog.text()).toContain('Cancel');
- expect(dialog.text()).toContain('Exit');
-
- const cancelButton = wrapper.find('[data-test="canceluploads"]');
- expect(cancelButton.exists()).toBe(true);
- });
-
- it('should close dialog when dismiss button is clicked', async () => {
- await wrapper.setData({ promptUploading: true });
-
- const buttons = wrapper.findAll('button');
- const dismissButton = buttons.at(0);
-
- await dismissButton.trigger('click');
- expect(wrapper.vm.promptUploading).toBe(false);
- });
-
- it('should call closeModal when cancel uploads button is clicked', async () => {
- const closeModalSpy = jest.spyOn(wrapper.vm, 'closeModal');
- await wrapper.setData({ promptUploading: true });
-
- const cancelButton = wrapper.find('[data-test="canceluploads"]');
- await cancelButton.trigger('click');
-
- expect(closeModalSpy).toHaveBeenCalled();
- });
+ it('should close dialog when dismiss button is clicked', async () => {
+ render(MockEditModalDialogs, {
+ routes: new VueRouter(),
+ data() {
+ return { promptUploading: true };
+ },
+ });
+
+ const dismissButton = screen.getByText('Cancel');
+ await fireEvent.click(dismissButton);
+
+ /* After clicking, the dialog should disappear */
+ expect(screen.queryByTestId('upload-dialog')).not.toBeInTheDocument();
});
- describe('Save failed dialog', () => {
- it('should not show dialog when promptFailed is false', () => {
- expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(false);
- });
-
- it('should show dialog when promptFailed is true', async () => {
- await wrapper.setData({ promptFailed: true });
-
- const dialog = wrapper.find('[data-testid="failed-dialog"]');
- expect(dialog.exists()).toBe(true);
- expect(dialog.text()).toContain('Save failed');
- expect(dialog.text()).toContain('There was a problem saving your content');
- });
-
- it('should have correct buttons with proper functionality', async () => {
- await wrapper.setData({ promptFailed: true });
-
- const dialog = wrapper.find('[data-testid="failed-dialog"]');
- expect(dialog.text()).toContain('OK');
- expect(dialog.text()).toContain('Close without saving');
- });
-
- it('should close dialog when OK button is clicked', async () => {
- await wrapper.setData({ promptFailed: true });
-
- const buttons = wrapper.findAll('button');
- const okButton = buttons.at(0);
-
- await okButton.trigger('click');
- expect(wrapper.vm.promptFailed).toBe(false);
- });
-
- it('should call closeModal when close without saving button is clicked', async () => {
- const closeModalSpy = jest.spyOn(wrapper.vm, 'closeModal');
- await wrapper.setData({ promptFailed: true });
-
- const buttons = wrapper.findAll('button');
- const closeButton = buttons.at(1);
-
- await closeButton.trigger('click');
- expect(closeModalSpy).toHaveBeenCalled();
- });
+ it('should call closeModal when cancel uploads button is clicked', async () => {
+ const closeModalSpy = jest.fn();
+ const TestComponent = {
+ ...MockEditModalDialogs,
+ methods: {
+ closeModal: closeModalSpy,
+ },
+ };
+
+ render(TestComponent, {
+ routes: new VueRouter(),
+ data() {
+ return { promptUploading: true };
+ },
+ });
+
+ const cancelButton = screen.getByRole('button', { name: 'Exit' });
+ await fireEvent.click(cancelButton);
+
+ expect(closeModalSpy).toHaveBeenCalled();
+ });
+ });
+
+ describe('Save failed dialog', () => {
+ it('should not show dialog when promptFailed is false', () => {
+ render(MockEditModalDialogs, {
+ routes: new VueRouter(),
+ });
+ expect(screen.queryByTestId('failed-dialog')).not.toBeInTheDocument();
+ });
+
+ it('should show dialog when promptFailed is true', () => {
+ render(MockEditModalDialogs, {
+ routes: new VueRouter(),
+ data() {
+ return { promptFailed: true };
+ },
+ });
+
+ expect(screen.getByTestId('failed-dialog')).toBeInTheDocument();
+ expect(screen.getByText('Save failed')).toBeInTheDocument();
+ expect(screen.getByText('There was a problem saving your content')).toBeInTheDocument();
});
- describe('Dialog state management', () => {
- it('should handle both dialogs independently', async () => {
- expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(false);
- expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(false);
-
-
- await wrapper.setData({ promptUploading: true });
- expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(true);
- expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(false);
-
-
- await wrapper.setData({ promptFailed: true });
- expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(true);
- expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(true);
-
-
- await wrapper.setData({ promptUploading: false });
- expect(wrapper.find('[data-testid="upload-dialog"]').exists()).toBe(false);
- expect(wrapper.find('[data-testid="failed-dialog"]').exists()).toBe(true);
- });
+ it('should have correct buttons with proper functionality', () => {
+ render(MockEditModalDialogs, {
+ routes: new VueRouter(),
+ data() {
+ return { promptFailed: true };
+ },
+ });
+
+ expect(screen.getByText('OK')).toBeInTheDocument();
+ expect(screen.getByText('Close without saving')).toBeInTheDocument();
+ });
+
+ it('should close dialog when OK button is clicked', async () => {
+ render(MockEditModalDialogs, {
+ routes: new VueRouter(),
+ data() {
+ return { promptFailed: true };
+ },
+ });
+
+ const okButton = screen.getByText('OK');
+ await fireEvent.click(okButton);
+
+ /* After clicking, the dialog should disappear */
+ expect(screen.queryByTestId('failed-dialog')).not.toBeInTheDocument();
+ });
+
+ it('should call closeModal when close without saving button is clicked', async () => {
+ const closeModalSpy = jest.fn();
+ const TestComponent = {
+ ...MockEditModalDialogs,
+ methods: {
+ closeModal: closeModalSpy,
+ },
+ };
+
+ render(TestComponent, {
+ routes: new VueRouter(),
+ data() {
+ return { promptFailed: true };
+ },
+ });
+
+ const closeButton = screen.getByText('Close without saving');
+ await fireEvent.click(closeButton);
+
+ expect(closeModalSpy).toHaveBeenCalled();
+ });
+ });
+
+ describe('Dialog state management', () => {
+ it('should handle both dialogs independently', () => {
+ /* Test initial state - both dialogs hidden */
+ const { unmount } = render(MockEditModalDialogs, {
+ routes: new VueRouter(),
+ });
+ expect(screen.queryByTestId('upload-dialog')).not.toBeInTheDocument();
+ expect(screen.queryByTestId('failed-dialog')).not.toBeInTheDocument();
+ unmount();
+
+ /* Test upload dialog */
+ const { unmount: unmount2 } = render(MockEditModalDialogs, {
+ routes: new VueRouter(),
+ data() {
+ return { promptUploading: true };
+ },
+ });
+ expect(screen.getByTestId('upload-dialog')).toBeInTheDocument();
+ expect(screen.queryByTestId('failed-dialog')).not.toBeInTheDocument();
+ unmount2();
+
+ /* Test both dialogs */
+ const { unmount: unmount3 } = render(MockEditModalDialogs, {
+ routes: new VueRouter(),
+ data() {
+ return { promptUploading: true, promptFailed: true };
+ },
+ });
+ expect(screen.getByTestId('upload-dialog')).toBeInTheDocument();
+ expect(screen.getByTestId('failed-dialog')).toBeInTheDocument();
+ unmount3();
+
+ /* Test failed dialog */
+ render(MockEditModalDialogs, {
+ routes: new VueRouter(),
+ data() {
+ return { promptUploading: false, promptFailed: true };
+ },
+ });
+ expect(screen.queryByTestId('upload-dialog')).not.toBeInTheDocument();
+ expect(screen.getByTestId('failed-dialog')).toBeInTheDocument();
});
-});
\ No newline at end of file
+ });
+});
From 2e3fcb10819c86a940e95d473c77b4e35f870752 Mon Sep 17 00:00:00 2001
From: ANAS727189
Date: Wed, 8 Oct 2025 16:20:37 +0530
Subject: [PATCH 4/8] fix: fixed KModal to use its own inbuilt buttons from
docs
---
.../channelEdit/components/edit/EditModal.vue | 29 ++++---------------
1 file changed, 6 insertions(+), 23 deletions(-)
diff --git a/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue b/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue
index 7ec9971682..eccf8fad4e 100644
--- a/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue
+++ b/contentcuration/contentcuration/frontend/channelEdit/components/edit/EditModal.vue
@@ -196,41 +196,24 @@
{{ $tr('uploadInProgressText') }}
-
-
- {{ $tr('dismissDialogButton') }}
-
-
- {{ $tr('cancelUploadsButton') }}
-
-
{{ $tr('saveFailedText') }}
-
-
- {{ $tr('okButton') }}
-
-
- {{ $tr('closeWithoutSavingButton') }}
-
-
From 9655a4a0c58dff2b9068efa4ed8db6a96a01834e Mon Sep 17 00:00:00 2001
From: ANAS727189
Date: Wed, 8 Oct 2025 16:52:37 +0530
Subject: [PATCH 5/8] fix: fixed the test to use actual kmodal for testing
---
.../edit/__tests__/editModal.kmodal.spec.js | 61 ++++++++++++-------
1 file changed, 38 insertions(+), 23 deletions(-)
diff --git a/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js b/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
index f97ea76b2a..68f2a621a6 100644
--- a/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
+++ b/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
@@ -4,23 +4,37 @@
*/
import { render, screen, fireEvent } from '@testing-library/vue';
import VueRouter from 'vue-router';
+import KModal from 'kolibri-design-system/lib/KModal';
const MockEditModalDialogs = {
+ components: {
+ KModal,
+ },
template: `
-
-
{{ uploadInProgressHeader }}
+
{{ uploadInProgressText }}
-
-
-
-
-
-
{{ saveFailedHeader }}
+
+
+
{{ saveFailedText }}
-
-
-
+
`,
data() {
@@ -76,10 +90,11 @@ describe('EditModal KModal Dialogs', () => {
expect(screen.getByText('Cancel')).toBeInTheDocument();
expect(screen.getByText('Exit')).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Exit' })).toBeInTheDocument();
});
- it('should close dialog when dismiss button is clicked', async () => {
+ it('should close dialog when cancel button is clicked', async () => {
render(MockEditModalDialogs, {
routes: new VueRouter(),
data() {
@@ -87,14 +102,14 @@ describe('EditModal KModal Dialogs', () => {
},
});
- const dismissButton = screen.getByText('Cancel');
- await fireEvent.click(dismissButton);
+ const cancelButton = screen.getByRole('button', { name: 'Cancel' });
+ await fireEvent.click(cancelButton);
/* After clicking, the dialog should disappear */
expect(screen.queryByTestId('upload-dialog')).not.toBeInTheDocument();
});
- it('should call closeModal when cancel uploads button is clicked', async () => {
+ it('should call closeModal when submit button is clicked', async () => {
const closeModalSpy = jest.fn();
const TestComponent = {
...MockEditModalDialogs,
@@ -110,8 +125,8 @@ describe('EditModal KModal Dialogs', () => {
},
});
- const cancelButton = screen.getByRole('button', { name: 'Exit' });
- await fireEvent.click(cancelButton);
+ const submitButton = screen.getByRole('button', { name: 'Exit' });
+ await fireEvent.click(submitButton);
expect(closeModalSpy).toHaveBeenCalled();
});
@@ -150,7 +165,7 @@ describe('EditModal KModal Dialogs', () => {
expect(screen.getByText('Close without saving')).toBeInTheDocument();
});
- it('should close dialog when OK button is clicked', async () => {
+ it('should close dialog when cancel button is clicked', async () => {
render(MockEditModalDialogs, {
routes: new VueRouter(),
data() {
@@ -158,14 +173,14 @@ describe('EditModal KModal Dialogs', () => {
},
});
- const okButton = screen.getByText('OK');
- await fireEvent.click(okButton);
+ const cancelButton = screen.getByRole('button', { name: 'OK' });
+ await fireEvent.click(cancelButton);
/* After clicking, the dialog should disappear */
expect(screen.queryByTestId('failed-dialog')).not.toBeInTheDocument();
});
- it('should call closeModal when close without saving button is clicked', async () => {
+ it('should call closeModal when submit button is clicked', async () => {
const closeModalSpy = jest.fn();
const TestComponent = {
...MockEditModalDialogs,
@@ -181,8 +196,8 @@ describe('EditModal KModal Dialogs', () => {
},
});
- const closeButton = screen.getByText('Close without saving');
- await fireEvent.click(closeButton);
+ const submitButton = screen.getByRole('button', { name: 'Close without saving' });
+ await fireEvent.click(submitButton);
expect(closeModalSpy).toHaveBeenCalled();
});
From a37179cf732e8024775bb4ae9ccea880e9949a51 Mon Sep 17 00:00:00 2001
From: ANAS727189
Date: Thu, 9 Oct 2025 00:40:37 +0530
Subject: [PATCH 6/8] fix: Test actual EditModal component instead of mock
components and rewrite the test
---
.../edit/__tests__/editModal.kmodal.spec.js | 670 +++++++++++++-----
1 file changed, 488 insertions(+), 182 deletions(-)
diff --git a/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js b/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
index 68f2a621a6..3e518672a0 100644
--- a/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
+++ b/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
@@ -1,249 +1,555 @@
/**
- * Simple integration test to verify KModal dialogs in EditModal work correctly
- * This test focuses only on the two specific dialogs we migrated from MessageDialog to KModal
+ * Integration tests for KModal dialogs in EditModal
+ * This mounts the actual EditModal component and verifies dialog behavior
*/
-import { render, screen, fireEvent } from '@testing-library/vue';
+
+import { render, screen, fireEvent, waitFor } from '@testing-library/vue';
+import { createLocalVue } from '@vue/test-utils';
+import Vuex from 'vuex';
import VueRouter from 'vue-router';
-import KModal from 'kolibri-design-system/lib/KModal';
+import EditModal from '../EditModal';
-const MockEditModalDialogs = {
- components: {
- KModal,
+/* This is mocking all the constants used in the EditModal component */
+jest.mock('shared/constants', () => ({
+ AssessmentItemTypes: {
+ SINGLE_SELECTION: 'single_selection',
+ MULTIPLE_SELECTION: 'multiple_selection',
+ TRUE_FALSE: 'true_false',
+ INPUT_QUESTION: 'input_question',
+ PERSEUS_QUESTION: 'perseus_question',
+ FREE_RESPONSE: 'free_response',
+ },
+ RouteNames: {
+ CONTENTNODE_DETAILS: 'CONTENTNODE_DETAILS',
+ TREE_VIEW: 'TREE_VIEW',
+ ADD_TOPICS: 'ADD_TOPICS',
+ UPLOAD_FILES: 'UPLOAD_FILES',
+ ADD_EXERCISE: 'ADD_EXERCISE',
+ },
+ TabNames: {
+ DETAILS: 'details',
+ PREVIEW: 'preview',
+ QUESTIONS: 'questions',
+ RELATED: 'related',
+ },
+ DELAYED_VALIDATION: 'delayed_validation',
+ ChannelListTypes: {
+ EDITABLE: 'EDITABLE',
+ VIEW_ONLY: 'VIEW_ONLY',
+ PUBLIC: 'PUBLIC',
+ STARRED: 'STARRED',
+ },
+ ValidationErrors: {
+ TITLE_REQUIRED: 'TITLE_REQUIRED',
+ },
+ AccessibilityCategories: {
+ CAPTIONS_SUBTITLES: 'captions_subtitles',
+ AUDIO_DESCRIPTION: 'audio_description',
+ SIGN_LANGUAGE: 'sign_language',
+ ALT_TEXT: 'alt_text',
+ HIGH_CONTRAST: 'high_contrast',
+ TAGGED_PDF: 'tagged_pdf',
},
- template: `
-
-
- {{ uploadInProgressText }}
-
-
-
- {{ saveFailedText }}
-
-
- `,
- data() {
- return {
- promptUploading: false,
- promptFailed: false,
- uploadInProgressHeader: 'Upload in progress',
- uploadInProgressText: 'Uploads that are in progress will be lost if you exit',
- dismissDialogButton: 'Cancel',
- cancelUploadsButton: 'Exit',
- saveFailedHeader: 'Save failed',
- saveFailedText: 'There was a problem saving your content',
- okButton: 'OK',
- closeWithoutSavingButton: 'Close without saving',
- };
+ ContentKindsNames: {
+ TOPIC: 'topic',
+ VIDEO: 'video',
+ AUDIO: 'audio',
+ EXERCISE: 'exercise',
+ DOCUMENT: 'document',
+ HTML5: 'html5',
+ SLIDESHOW: 'slideshow',
},
- methods: {
- closeModal: jest.fn(),
+}));
+
+// This Mock is of channelEdit/constants to use the mocked shared/constants
+jest.mock('../../../constants', () => {
+ const mockAssessmentItemTypes = {
+ SINGLE_SELECTION: 'single_selection',
+ MULTIPLE_SELECTION: 'multiple_selection',
+ TRUE_FALSE: 'true_false',
+ INPUT_QUESTION: 'input_question',
+ PERSEUS_QUESTION: 'perseus_question',
+ FREE_RESPONSE: 'free_response',
+ };
+
+ return {
+ RouteNames: {
+ TREE_ROOT_VIEW: 'TREE_ROOT_VIEW',
+ TREE_VIEW: 'TREE_VIEW',
+ STAGING_TREE_VIEW: 'STAGING_TREE_VIEW',
+ STAGING_TREE_VIEW_REDIRECT: 'STAGING_TREE_VIEW_REDIRECT',
+ ORIGINAL_SOURCE_NODE_IN_TREE_VIEW: 'ORIGINAL_SOURCE_NODE_IN_TREE_VIEW',
+ CONTENTNODE_DETAILS: 'CONTENTNODE_DETAILS',
+ MULTI_CONTENTNODE_DETAILS: 'MULTI_CONTENTNODE_DETAILS',
+ IMPORT_FROM_CHANNELS: 'IMPORT_FROM_CHANNELS',
+ IMPORT_FROM_CHANNELS_BROWSE: 'IMPORT_FROM_CHANNELS_BROWSE',
+ IMPORT_FROM_CHANNELS_SEARCH: 'IMPORT_FROM_CHANNELS_SEARCH',
+ IMPORT_FROM_CHANNELS_REVIEW: 'IMPORT_FROM_CHANNELS_REVIEW',
+ ADD_TOPICS: 'ADD_TOPICS',
+ ADD_EXERCISE: 'ADD_EXERCISE',
+ UPLOAD_FILES: 'UPLOAD_FILES',
+ TRASH: 'TRASH',
+ ADD_PREVIOUS_STEPS: 'ADD_PREVIOUS_STEPS',
+ ADD_NEXT_STEPS: 'ADD_NEXT_STEPS',
+ },
+ viewModes: {
+ DEFAULT: 'DEFAULT_VIEW',
+ COMFORTABLE: 'COMFORTABLE_VIEW',
+ COMPACT: 'COMPACT_VIEW',
+ },
+ ChannelEditPageErrors: Object.freeze({
+ CHANNEL_NOT_FOUND: 'CHANNEL_EDIT_ERROR_CHANNEL_NOT_FOUND',
+ CHANNEL_DELETED: 'CHANNEL_EDIT_ERROR_CHANNEL_DELETED',
+ }),
+ AssessmentItemToolbarActions: {
+ EDIT_ITEM: 'EDIT_ITEM',
+ MOVE_ITEM_UP: 'MOVE_ITEM_UP',
+ MOVE_ITEM_DOWN: 'MOVE_ITEM_DOWN',
+ DELETE_ITEM: 'DELETE_ITEM',
+ ADD_ITEM_ABOVE: 'ADD_ITEM_ABOVE',
+ ADD_ITEM_BELOW: 'ADD_ITEM_BELOW',
+ },
+ AssessmentItemTypeLabels: {
+ [mockAssessmentItemTypes.SINGLE_SELECTION]: 'questionTypeSingleSelection',
+ [mockAssessmentItemTypes.MULTIPLE_SELECTION]: 'questionTypeMultipleSelection',
+ [mockAssessmentItemTypes.TRUE_FALSE]: 'questionTypeTrueFalse',
+ [mockAssessmentItemTypes.INPUT_QUESTION]: 'questionTypeInput',
+ [mockAssessmentItemTypes.PERSEUS_QUESTION]: 'questionTypePerseus',
+ [mockAssessmentItemTypes.FREE_RESPONSE]: 'questionTypeFreeResponse',
+ },
+ TabNames: {
+ DETAILS: 'details',
+ PREVIEW: 'preview',
+ QUESTIONS: 'questions',
+ RELATED: 'related',
+ },
+ modes: {
+ EDIT: 'EDIT',
+ NEW_TOPIC: 'NEW_TOPIC',
+ NEW_EXERCISE: 'NEW_EXERCISE',
+ UPLOAD: 'UPLOAD',
+ VIEW_ONLY: 'VIEW_ONLY',
+ },
+ DraggableUniverses: {
+ CONTENT_NODES: 'contentNodes',
+ },
+ DraggableRegions: {
+ TREE: 'tree',
+ TOPIC_VIEW: 'topicView',
+ CLIPBOARD: 'clipboard',
+ },
+ ImportSearchPageSize: 10,
+ QuickEditModals: {
+ TITLE_DESCRIPTION: 'TITLE_DESCRIPTION',
+ TAGS: 'TAGS',
+ LANGUAGE: 'LANGUAGE',
+ CATEGORIES: 'CATEGORIES',
+ LEVELS: 'LEVELS',
+ LEARNING_ACTIVITIES: 'LEARNING_ACTIVITIES',
+ SOURCE: 'SOURCE',
+ AUDIENCE: 'AUDIENCE',
+ COMPLETION: 'COMPLETION',
+ WHAT_IS_NEEDED: 'WHAT_IS_NEEDED',
+ },
+ };
+});
+
+jest.mock('shared/views/files/FileStorage', () => ({
+ template: '',
+}));
+
+jest.mock('shared/leUtils/FormatPresets', () => ({
+ __esModule: true,
+ default: new Map(),
+ FormatPresetsList: [],
+ FormatPresetsNames: {
+ AUDIO: 'audio',
+ AUDIO_DEPENDENCY: 'audio_dependency',
+ AUDIO_THUMBNAIL: 'audio_thumbnail',
+ BLOOMPUB: 'bloompub',
+ CHANNEL_THUMBNAIL: 'channel_thumbnail',
+ DOCUMENT: 'document',
+ DOCUMENT_THUMBNAIL: 'document_thumbnail',
+ EPUB: 'epub',
+ EXERCISE: 'exercise',
+ EXERCISE_GRAPHIE: 'exercise_graphie',
+ EXERCISE_IMAGE: 'exercise_image',
+ EXERCISE_THUMBNAIL: 'exercise_thumbnail',
+ H5P: 'h5p',
+ H5P_THUMBNAIL: 'h5p_thumbnail',
+ HIGH_RES_VIDEO: 'high_res_video',
+ HTML5_DEPENDENCY: 'html5_dependency',
+ HTML5_THUMBNAIL: 'html5_thumbnail',
+ HTML5_ZIP: 'html5_zip',
+ IMSCP_ZIP: 'imscp_zip',
+ KPUB: 'kpub',
+ LOW_RES_VIDEO: 'low_res_video',
+ QTI: 'qti',
+ QTI_THUMBNAIL: 'qti_thumbnail',
+ SLIDESHOW_IMAGE: 'slideshow_image',
+ SLIDESHOW_MANIFEST: 'slideshow_manifest',
+ SLIDESHOW_THUMBNAIL: 'slideshow_thumbnail',
+ TOPIC_THUMBNAIL: 'topic_thumbnail',
+ VIDEO_DEPENDENCY: 'video_dependency',
+ VIDEO_SUBTITLE: 'video_subtitle',
+ VIDEO_THUMBNAIL: 'video_thumbnail',
+ ZIM: 'zim',
+ ZIM_THUMBNAIL: 'zim_thumbnail',
},
+}));
+
+jest.mock('shared/leUtils/ContentKinds', () => ({
+ ContentKindLearningActivityDefaults: {},
+}));
+
+jest.mock('shared/utils/validation', () => ({
+ isNodeComplete: jest.fn().mockReturnValue(true),
+}));
+
+
+// Mocking child components
+
+jest.mock('../EditView', () => ({
+ name: 'EditView',
+ template: '',
+}));
+
+jest.mock('../DetailsTabView', () => ({
+ name: 'DetailsTabView',
+ template: '',
+}));
+
+jest.mock('../AccessibilityOptions', () => ({
+ name: 'AccessibilityOptions',
+ template: '',
+}));
+
+
+/* Test setup and configuration */
+
+const localVue = createLocalVue();
+localVue.use(Vuex);
+localVue.use(VueRouter);
+
+/* Vue prototype properties */
+localVue.prototype.$isRTL = false;
+localVue.prototype.$tr = (msg) => msg;
+localVue.prototype.$themeTokens = { textInverted: 'white' };
+localVue.prototype.$analytics = { trackAction: jest.fn() };
+const mockRouter = new VueRouter({
+ routes: [
+ {
+ path: '/',
+ name: 'CONTENTNODE_DETAILS',
+ },
+ {
+ path: '/tree',
+ name: 'TREE_VIEW',
+ },
+ ],
+});
+
+const originalPush = mockRouter.push;
+mockRouter.push = function push(location) {
+ return originalPush.call(this, location).catch(err => {
+ if (err.name === 'NavigationDuplicated') return;
+ throw err;
+ });
};
-describe('EditModal KModal Dialogs', () => {
- describe('Upload in progress dialog', () => {
- it('should not show dialog when promptUploading is false', () => {
- render(MockEditModalDialogs, {
- routes: new VueRouter(),
- });
- expect(screen.queryByTestId('upload-dialog')).not.toBeInTheDocument();
- });
+/* Component stubs */
+const stubs = {
+ VDialog: true,
+ VCard: true,
+ VToolbar: true,
+ VToolbarTitle: true,
+ VSpacer: true,
+ VToolbarItems: true,
+ VContent: true,
+ VLayout: true,
+ VFlex: true,
+ Icon: true,
+ OfflineText: true,
+ ResizableNavigationDrawer: true,
+ FileDropzone: true,
+ ToolBar: true,
+ LoadingText: true,
+ BottomBar: true,
+ SavingIndicator: true,
+ MessageDialog: true,
+ Uploader: true,
+};
- it('should show dialog when promptUploading is true', () => {
- render(MockEditModalDialogs, {
- routes: new VueRouter(),
- data() {
- return { promptUploading: true };
- },
- });
+/* Vuex store configuration */
+const baseModules = {
+ contentNode: {
+ namespaced: true,
+ getters: {
+ getContentNode: () => () => ({
+ title: 'Test Node',
+ complete: true,
+ kind: 'video',
+ }),
+ getContentNodeIsValid: () => () => true,
+ },
+ actions: {
+ loadContentNodes: jest.fn().mockResolvedValue([]),
+ loadRelatedResources: jest.fn().mockResolvedValue([]),
+ loadContentNode: jest.fn().mockResolvedValue({}),
+ updateContentNode: jest.fn().mockResolvedValue({}),
+ },
+ mutations: {
+ ENABLE_VALIDATION_ON_NODES: jest.fn(),
+ },
+ },
+ assessmentItem: {
+ namespaced: true,
+ getters: {
+ getAssessmentItems: () => () => [],
+ },
+ actions: {
+ loadAssessmentItems: jest.fn().mockResolvedValue([]),
+ },
+ },
+ currentChannel: {
+ namespaced: true,
+ getters: {
+ currentChannel: () => ({ id: 'test-channel' }),
+ canEdit: () => true,
+ },
+ },
+ file: {
+ namespaced: true,
+ getters: {
+ contentNodesAreUploading: () => () => false,
+ getContentNodeFiles: () => () => [],
+ },
+ actions: {
+ loadFiles: jest.fn().mockResolvedValue([]),
+ },
+ },
+ connection: {
+ namespaced: true,
+ state: {
+ online: true,
+ },
+ getters: {
+ online: (state) => state.online,
+ },
+ },
+};
- expect(screen.getByTestId('upload-dialog')).toBeInTheDocument();
- expect(screen.getByText('Upload in progress')).toBeInTheDocument();
- expect(
- screen.getByText('Uploads that are in progress will be lost if you exit'),
- ).toBeInTheDocument();
- });
+let store;
- it('should have correct buttons with proper functionality', () => {
- render(MockEditModalDialogs, {
- routes: new VueRouter(),
- data() {
- return { promptUploading: true };
- },
- });
- expect(screen.getByText('Cancel')).toBeInTheDocument();
- expect(screen.getByText('Exit')).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'Exit' })).toBeInTheDocument();
+describe('EditModal KModal Dialogs', () => {
+
+ beforeEach(() => {
+ store = new Vuex.Store({
+ getters: {
+ appendChannelName: jest.fn(name => name),
+ },
+ modules: baseModules,
});
+ mockRouter.push('/');
+ });
- it('should close dialog when cancel button is clicked', async () => {
- render(MockEditModalDialogs, {
- routes: new VueRouter(),
+ /* Upload in progress dialog */
+ describe('Upload in progress dialog', () => {
+
+ it('should show dialog when promptUploading is true', async () => {
+ render(EditModal, {
+ localVue,
+ store,
+ router: mockRouter,
+ stubs,
+ propsData: {
+ detailNodeIds: 'test-node-id',
+ tab: 'details',
+ },
data() {
- return { promptUploading: true };
+ return {
+ loading: false,
+ loadError: false,
+ promptUploading: true,
+ };
},
});
- const cancelButton = screen.getByRole('button', { name: 'Cancel' });
- await fireEvent.click(cancelButton);
-
- /* After clicking, the dialog should disappear */
- expect(screen.queryByTestId('upload-dialog')).not.toBeInTheDocument();
+ await waitFor(() => {
+ expect(
+ screen.getByRole('heading', { name: /uploadInProgressHeader/i })
+ ).toBeInTheDocument();
+ expect(screen.getByText('uploadInProgressText')).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'dismissDialogButton' })).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'cancelUploadsButton' })).toBeInTheDocument();
+ });
});
- it('should call closeModal when submit button is clicked', async () => {
- const closeModalSpy = jest.fn();
- const TestComponent = {
- ...MockEditModalDialogs,
- methods: {
- closeModal: closeModalSpy,
+ it('should close dialog when cancel is clicked', async () => {
+ render(EditModal, {
+ localVue,
+ store,
+ router: mockRouter,
+ stubs,
+ propsData: {
+ detailNodeIds: 'test-node-id',
+ tab: 'details',
},
- };
-
- render(TestComponent, {
- routes: new VueRouter(),
data() {
- return { promptUploading: true };
+ return {
+ loading: false,
+ loadError: false,
+ promptUploading: true,
+ };
},
});
- const submitButton = screen.getByRole('button', { name: 'Exit' });
- await fireEvent.click(submitButton);
+ await waitFor(() => {
+ expect(screen.getByRole('heading', { name: /uploadInProgressHeader/i })).toBeInTheDocument();
+ });
+
+ const cancelButton = screen.getByRole('button', { name: 'dismissDialogButton' });
+ await fireEvent.click(cancelButton);
- expect(closeModalSpy).toHaveBeenCalled();
+ await waitFor(() => {
+ expect(
+ screen.queryByRole('heading', { name: /uploadInProgressHeader/i })
+ ).not.toBeInTheDocument();
+ });
});
});
+ /* Save failed dialog */
describe('Save failed dialog', () => {
- it('should not show dialog when promptFailed is false', () => {
- render(MockEditModalDialogs, {
- routes: new VueRouter(),
- });
- expect(screen.queryByTestId('failed-dialog')).not.toBeInTheDocument();
- });
- it('should show dialog when promptFailed is true', () => {
- render(MockEditModalDialogs, {
- routes: new VueRouter(),
+ it('should show dialog when promptFailed is true', async () => {
+ render(EditModal, {
+ localVue,
+ store,
+ router: mockRouter,
+ stubs,
+ propsData: {
+ detailNodeIds: 'test-node-id',
+ tab: 'details',
+ },
data() {
- return { promptFailed: true };
+ return {
+ loading: false,
+ loadError: false,
+ promptFailed: true,
+ };
},
});
- expect(screen.getByTestId('failed-dialog')).toBeInTheDocument();
- expect(screen.getByText('Save failed')).toBeInTheDocument();
- expect(screen.getByText('There was a problem saving your content')).toBeInTheDocument();
+ await waitFor(() => {
+ expect(screen.getByRole('heading', { name: /saveFailedHeader/i })).toBeInTheDocument();
+ expect(screen.getByText('saveFailedText')).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'okButton' })).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'closeWithoutSavingButton' })).toBeInTheDocument();
+ });
});
- it('should have correct buttons with proper functionality', () => {
- render(MockEditModalDialogs, {
- routes: new VueRouter(),
+ it('should close dialog when OK is clicked', async () => {
+ render(EditModal, {
+ localVue,
+ store,
+ router: mockRouter,
+ stubs,
+ propsData: {
+ detailNodeIds: 'test-node-id',
+ tab: 'details',
+ },
data() {
- return { promptFailed: true };
+ return {
+ loading: false,
+ loadError: false,
+ promptFailed: true,
+ };
},
});
- expect(screen.getByText('OK')).toBeInTheDocument();
- expect(screen.getByText('Close without saving')).toBeInTheDocument();
- });
-
- it('should close dialog when cancel button is clicked', async () => {
- render(MockEditModalDialogs, {
- routes: new VueRouter(),
- data() {
- return { promptFailed: true };
- },
+ await waitFor(() => {
+ expect(screen.getByRole('heading', { name: /saveFailedHeader/i })).toBeInTheDocument();
});
- const cancelButton = screen.getByRole('button', { name: 'OK' });
- await fireEvent.click(cancelButton);
+ const okButton = screen.getByRole('button', { name: 'okButton' });
+ await fireEvent.click(okButton);
- /* After clicking, the dialog should disappear */
- expect(screen.queryByTestId('failed-dialog')).not.toBeInTheDocument();
+ await waitFor(() => {
+ expect(
+ screen.queryByRole('heading', { name: /saveFailedHeader/i })
+ ).not.toBeInTheDocument();
+ });
});
- it('should call closeModal when submit button is clicked', async () => {
- const closeModalSpy = jest.fn();
- const TestComponent = {
- ...MockEditModalDialogs,
- methods: {
- closeModal: closeModalSpy,
+ it('should close dialog when "Close without saving" is clicked', async () => {
+ render(EditModal, {
+ localVue,
+ store,
+ router: mockRouter,
+ stubs,
+ propsData: {
+ detailNodeIds: 'test-node-id',
+ tab: 'details',
},
- };
-
- render(TestComponent, {
- routes: new VueRouter(),
data() {
- return { promptFailed: true };
+ return {
+ loading: false,
+ loadError: false,
+ promptFailed: true,
+ };
},
});
- const submitButton = screen.getByRole('button', { name: 'Close without saving' });
+ await waitFor(() => {
+ expect(screen.getByRole('heading', { name: /saveFailedHeader/i })).toBeInTheDocument();
+ });
+
+ const submitButton = screen.getByRole('button', { name: 'closeWithoutSavingButton' });
await fireEvent.click(submitButton);
- expect(closeModalSpy).toHaveBeenCalled();
+ await waitFor(() => {
+ expect(
+ screen.queryByRole('heading', { name: /saveFailedHeader/i })
+ ).not.toBeInTheDocument();
+ });
});
});
- describe('Dialog state management', () => {
- it('should handle both dialogs independently', () => {
- /* Test initial state - both dialogs hidden */
- const { unmount } = render(MockEditModalDialogs, {
- routes: new VueRouter(),
- });
- expect(screen.queryByTestId('upload-dialog')).not.toBeInTheDocument();
- expect(screen.queryByTestId('failed-dialog')).not.toBeInTheDocument();
- unmount();
-
- /* Test upload dialog */
- const { unmount: unmount2 } = render(MockEditModalDialogs, {
- routes: new VueRouter(),
+ /* Upload in progress dialog submit action */
+ describe('Upload in progress dialog submit action', () => {
+ it('should close dialog when "Exit" is clicked', async () => {
+ render(EditModal, {
+ localVue,
+ store,
+ router: mockRouter,
+ stubs,
+ propsData: {
+ detailNodeIds: 'test-node-id',
+ tab: 'details',
+ },
data() {
- return { promptUploading: true };
+ return {
+ loading: false,
+ loadError: false,
+ promptUploading: true,
+ };
},
});
- expect(screen.getByTestId('upload-dialog')).toBeInTheDocument();
- expect(screen.queryByTestId('failed-dialog')).not.toBeInTheDocument();
- unmount2();
- /* Test both dialogs */
- const { unmount: unmount3 } = render(MockEditModalDialogs, {
- routes: new VueRouter(),
- data() {
- return { promptUploading: true, promptFailed: true };
- },
+ await waitFor(() => {
+ expect(screen.getByRole('heading', { name: /uploadInProgressHeader/i })).toBeInTheDocument();
});
- expect(screen.getByTestId('upload-dialog')).toBeInTheDocument();
- expect(screen.getByTestId('failed-dialog')).toBeInTheDocument();
- unmount3();
- /* Test failed dialog */
- render(MockEditModalDialogs, {
- routes: new VueRouter(),
- data() {
- return { promptUploading: false, promptFailed: true };
- },
+ const exitButton = screen.getByRole('button', { name: 'cancelUploadsButton' });
+ await fireEvent.click(exitButton);
+
+ await waitFor(() => {
+ expect(
+ screen.queryByRole('heading', { name: /uploadInProgressHeader/i })
+ ).not.toBeInTheDocument();
});
- expect(screen.queryByTestId('upload-dialog')).not.toBeInTheDocument();
- expect(screen.getByTestId('failed-dialog')).toBeInTheDocument();
});
});
});
From 75f582270b3b3c3fb4777ebda8b61efb1b35f7f0 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci-lite[bot]"
<117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Date: Thu, 9 Oct 2025 07:03:42 +0000
Subject: [PATCH 7/8] [pre-commit.ci lite] apply automatic fixes
---
.../edit/__tests__/editModal.kmodal.spec.js | 42 +++++++++----------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js b/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
index 3e518672a0..e2feff464e 100644
--- a/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
+++ b/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
@@ -26,7 +26,7 @@ jest.mock('shared/constants', () => ({
UPLOAD_FILES: 'UPLOAD_FILES',
ADD_EXERCISE: 'ADD_EXERCISE',
},
- TabNames: {
+ TabNames: {
DETAILS: 'details',
PREVIEW: 'preview',
QUESTIONS: 'questions',
@@ -42,7 +42,7 @@ jest.mock('shared/constants', () => ({
ValidationErrors: {
TITLE_REQUIRED: 'TITLE_REQUIRED',
},
- AccessibilityCategories: {
+ AccessibilityCategories: {
CAPTIONS_SUBTITLES: 'captions_subtitles',
AUDIO_DESCRIPTION: 'audio_description',
SIGN_LANGUAGE: 'sign_language',
@@ -160,7 +160,7 @@ jest.mock('shared/views/files/FileStorage', () => ({
jest.mock('shared/leUtils/FormatPresets', () => ({
__esModule: true,
- default: new Map(),
+ default: new Map(),
FormatPresetsList: [],
FormatPresetsNames: {
AUDIO: 'audio',
@@ -206,7 +206,6 @@ jest.mock('shared/utils/validation', () => ({
isNodeComplete: jest.fn().mockReturnValue(true),
}));
-
// Mocking child components
jest.mock('../EditView', () => ({
@@ -224,7 +223,6 @@ jest.mock('../AccessibilityOptions', () => ({
template: '',
}));
-
/* Test setup and configuration */
const localVue = createLocalVue();
@@ -233,7 +231,7 @@ localVue.use(VueRouter);
/* Vue prototype properties */
localVue.prototype.$isRTL = false;
-localVue.prototype.$tr = (msg) => msg;
+localVue.prototype.$tr = msg => msg;
localVue.prototype.$themeTokens = { textInverted: 'white' };
localVue.prototype.$analytics = { trackAction: jest.fn() };
const mockRouter = new VueRouter({
@@ -285,8 +283,8 @@ const baseModules = {
contentNode: {
namespaced: true,
getters: {
- getContentNode: () => () => ({
- title: 'Test Node',
+ getContentNode: () => () => ({
+ title: 'Test Node',
complete: true,
kind: 'video',
}),
@@ -334,16 +332,14 @@ const baseModules = {
online: true,
},
getters: {
- online: (state) => state.online,
+ online: state => state.online,
},
},
};
let store;
-
describe('EditModal KModal Dialogs', () => {
-
beforeEach(() => {
store = new Vuex.Store({
getters: {
@@ -356,7 +352,6 @@ describe('EditModal KModal Dialogs', () => {
/* Upload in progress dialog */
describe('Upload in progress dialog', () => {
-
it('should show dialog when promptUploading is true', async () => {
render(EditModal, {
localVue,
@@ -378,7 +373,7 @@ describe('EditModal KModal Dialogs', () => {
await waitFor(() => {
expect(
- screen.getByRole('heading', { name: /uploadInProgressHeader/i })
+ screen.getByRole('heading', { name: /uploadInProgressHeader/i }),
).toBeInTheDocument();
expect(screen.getByText('uploadInProgressText')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'dismissDialogButton' })).toBeInTheDocument();
@@ -406,7 +401,9 @@ describe('EditModal KModal Dialogs', () => {
});
await waitFor(() => {
- expect(screen.getByRole('heading', { name: /uploadInProgressHeader/i })).toBeInTheDocument();
+ expect(
+ screen.getByRole('heading', { name: /uploadInProgressHeader/i }),
+ ).toBeInTheDocument();
});
const cancelButton = screen.getByRole('button', { name: 'dismissDialogButton' });
@@ -414,7 +411,7 @@ describe('EditModal KModal Dialogs', () => {
await waitFor(() => {
expect(
- screen.queryByRole('heading', { name: /uploadInProgressHeader/i })
+ screen.queryByRole('heading', { name: /uploadInProgressHeader/i }),
).not.toBeInTheDocument();
});
});
@@ -422,7 +419,6 @@ describe('EditModal KModal Dialogs', () => {
/* Save failed dialog */
describe('Save failed dialog', () => {
-
it('should show dialog when promptFailed is true', async () => {
render(EditModal, {
localVue,
@@ -446,7 +442,9 @@ describe('EditModal KModal Dialogs', () => {
expect(screen.getByRole('heading', { name: /saveFailedHeader/i })).toBeInTheDocument();
expect(screen.getByText('saveFailedText')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'okButton' })).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'closeWithoutSavingButton' })).toBeInTheDocument();
+ expect(
+ screen.getByRole('button', { name: 'closeWithoutSavingButton' }),
+ ).toBeInTheDocument();
});
});
@@ -478,7 +476,7 @@ describe('EditModal KModal Dialogs', () => {
await waitFor(() => {
expect(
- screen.queryByRole('heading', { name: /saveFailedHeader/i })
+ screen.queryByRole('heading', { name: /saveFailedHeader/i }),
).not.toBeInTheDocument();
});
});
@@ -511,7 +509,7 @@ describe('EditModal KModal Dialogs', () => {
await waitFor(() => {
expect(
- screen.queryByRole('heading', { name: /saveFailedHeader/i })
+ screen.queryByRole('heading', { name: /saveFailedHeader/i }),
).not.toBeInTheDocument();
});
});
@@ -539,7 +537,9 @@ describe('EditModal KModal Dialogs', () => {
});
await waitFor(() => {
- expect(screen.getByRole('heading', { name: /uploadInProgressHeader/i })).toBeInTheDocument();
+ expect(
+ screen.getByRole('heading', { name: /uploadInProgressHeader/i }),
+ ).toBeInTheDocument();
});
const exitButton = screen.getByRole('button', { name: 'cancelUploadsButton' });
@@ -547,7 +547,7 @@ describe('EditModal KModal Dialogs', () => {
await waitFor(() => {
expect(
- screen.queryByRole('heading', { name: /uploadInProgressHeader/i })
+ screen.queryByRole('heading', { name: /uploadInProgressHeader/i }),
).not.toBeInTheDocument();
});
});
From 6d0234e144322a427ef663ad8d6874f6f5e9510b Mon Sep 17 00:00:00 2001
From: ANAS727189
Date: Thu, 9 Oct 2025 15:21:41 +0530
Subject: [PATCH 8/8] chore: remove editModal.kmodal.spec.js from PR as per
review feedback
---
.../edit/__tests__/editModal.kmodal.spec.js | 555 ------------------
1 file changed, 555 deletions(-)
delete mode 100644 contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
diff --git a/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js b/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
deleted file mode 100644
index e2feff464e..0000000000
--- a/contentcuration/contentcuration/frontend/channelEdit/components/edit/__tests__/editModal.kmodal.spec.js
+++ /dev/null
@@ -1,555 +0,0 @@
-/**
- * Integration tests for KModal dialogs in EditModal
- * This mounts the actual EditModal component and verifies dialog behavior
- */
-
-import { render, screen, fireEvent, waitFor } from '@testing-library/vue';
-import { createLocalVue } from '@vue/test-utils';
-import Vuex from 'vuex';
-import VueRouter from 'vue-router';
-import EditModal from '../EditModal';
-
-/* This is mocking all the constants used in the EditModal component */
-jest.mock('shared/constants', () => ({
- AssessmentItemTypes: {
- SINGLE_SELECTION: 'single_selection',
- MULTIPLE_SELECTION: 'multiple_selection',
- TRUE_FALSE: 'true_false',
- INPUT_QUESTION: 'input_question',
- PERSEUS_QUESTION: 'perseus_question',
- FREE_RESPONSE: 'free_response',
- },
- RouteNames: {
- CONTENTNODE_DETAILS: 'CONTENTNODE_DETAILS',
- TREE_VIEW: 'TREE_VIEW',
- ADD_TOPICS: 'ADD_TOPICS',
- UPLOAD_FILES: 'UPLOAD_FILES',
- ADD_EXERCISE: 'ADD_EXERCISE',
- },
- TabNames: {
- DETAILS: 'details',
- PREVIEW: 'preview',
- QUESTIONS: 'questions',
- RELATED: 'related',
- },
- DELAYED_VALIDATION: 'delayed_validation',
- ChannelListTypes: {
- EDITABLE: 'EDITABLE',
- VIEW_ONLY: 'VIEW_ONLY',
- PUBLIC: 'PUBLIC',
- STARRED: 'STARRED',
- },
- ValidationErrors: {
- TITLE_REQUIRED: 'TITLE_REQUIRED',
- },
- AccessibilityCategories: {
- CAPTIONS_SUBTITLES: 'captions_subtitles',
- AUDIO_DESCRIPTION: 'audio_description',
- SIGN_LANGUAGE: 'sign_language',
- ALT_TEXT: 'alt_text',
- HIGH_CONTRAST: 'high_contrast',
- TAGGED_PDF: 'tagged_pdf',
- },
- ContentKindsNames: {
- TOPIC: 'topic',
- VIDEO: 'video',
- AUDIO: 'audio',
- EXERCISE: 'exercise',
- DOCUMENT: 'document',
- HTML5: 'html5',
- SLIDESHOW: 'slideshow',
- },
-}));
-
-// This Mock is of channelEdit/constants to use the mocked shared/constants
-jest.mock('../../../constants', () => {
- const mockAssessmentItemTypes = {
- SINGLE_SELECTION: 'single_selection',
- MULTIPLE_SELECTION: 'multiple_selection',
- TRUE_FALSE: 'true_false',
- INPUT_QUESTION: 'input_question',
- PERSEUS_QUESTION: 'perseus_question',
- FREE_RESPONSE: 'free_response',
- };
-
- return {
- RouteNames: {
- TREE_ROOT_VIEW: 'TREE_ROOT_VIEW',
- TREE_VIEW: 'TREE_VIEW',
- STAGING_TREE_VIEW: 'STAGING_TREE_VIEW',
- STAGING_TREE_VIEW_REDIRECT: 'STAGING_TREE_VIEW_REDIRECT',
- ORIGINAL_SOURCE_NODE_IN_TREE_VIEW: 'ORIGINAL_SOURCE_NODE_IN_TREE_VIEW',
- CONTENTNODE_DETAILS: 'CONTENTNODE_DETAILS',
- MULTI_CONTENTNODE_DETAILS: 'MULTI_CONTENTNODE_DETAILS',
- IMPORT_FROM_CHANNELS: 'IMPORT_FROM_CHANNELS',
- IMPORT_FROM_CHANNELS_BROWSE: 'IMPORT_FROM_CHANNELS_BROWSE',
- IMPORT_FROM_CHANNELS_SEARCH: 'IMPORT_FROM_CHANNELS_SEARCH',
- IMPORT_FROM_CHANNELS_REVIEW: 'IMPORT_FROM_CHANNELS_REVIEW',
- ADD_TOPICS: 'ADD_TOPICS',
- ADD_EXERCISE: 'ADD_EXERCISE',
- UPLOAD_FILES: 'UPLOAD_FILES',
- TRASH: 'TRASH',
- ADD_PREVIOUS_STEPS: 'ADD_PREVIOUS_STEPS',
- ADD_NEXT_STEPS: 'ADD_NEXT_STEPS',
- },
- viewModes: {
- DEFAULT: 'DEFAULT_VIEW',
- COMFORTABLE: 'COMFORTABLE_VIEW',
- COMPACT: 'COMPACT_VIEW',
- },
- ChannelEditPageErrors: Object.freeze({
- CHANNEL_NOT_FOUND: 'CHANNEL_EDIT_ERROR_CHANNEL_NOT_FOUND',
- CHANNEL_DELETED: 'CHANNEL_EDIT_ERROR_CHANNEL_DELETED',
- }),
- AssessmentItemToolbarActions: {
- EDIT_ITEM: 'EDIT_ITEM',
- MOVE_ITEM_UP: 'MOVE_ITEM_UP',
- MOVE_ITEM_DOWN: 'MOVE_ITEM_DOWN',
- DELETE_ITEM: 'DELETE_ITEM',
- ADD_ITEM_ABOVE: 'ADD_ITEM_ABOVE',
- ADD_ITEM_BELOW: 'ADD_ITEM_BELOW',
- },
- AssessmentItemTypeLabels: {
- [mockAssessmentItemTypes.SINGLE_SELECTION]: 'questionTypeSingleSelection',
- [mockAssessmentItemTypes.MULTIPLE_SELECTION]: 'questionTypeMultipleSelection',
- [mockAssessmentItemTypes.TRUE_FALSE]: 'questionTypeTrueFalse',
- [mockAssessmentItemTypes.INPUT_QUESTION]: 'questionTypeInput',
- [mockAssessmentItemTypes.PERSEUS_QUESTION]: 'questionTypePerseus',
- [mockAssessmentItemTypes.FREE_RESPONSE]: 'questionTypeFreeResponse',
- },
- TabNames: {
- DETAILS: 'details',
- PREVIEW: 'preview',
- QUESTIONS: 'questions',
- RELATED: 'related',
- },
- modes: {
- EDIT: 'EDIT',
- NEW_TOPIC: 'NEW_TOPIC',
- NEW_EXERCISE: 'NEW_EXERCISE',
- UPLOAD: 'UPLOAD',
- VIEW_ONLY: 'VIEW_ONLY',
- },
- DraggableUniverses: {
- CONTENT_NODES: 'contentNodes',
- },
- DraggableRegions: {
- TREE: 'tree',
- TOPIC_VIEW: 'topicView',
- CLIPBOARD: 'clipboard',
- },
- ImportSearchPageSize: 10,
- QuickEditModals: {
- TITLE_DESCRIPTION: 'TITLE_DESCRIPTION',
- TAGS: 'TAGS',
- LANGUAGE: 'LANGUAGE',
- CATEGORIES: 'CATEGORIES',
- LEVELS: 'LEVELS',
- LEARNING_ACTIVITIES: 'LEARNING_ACTIVITIES',
- SOURCE: 'SOURCE',
- AUDIENCE: 'AUDIENCE',
- COMPLETION: 'COMPLETION',
- WHAT_IS_NEEDED: 'WHAT_IS_NEEDED',
- },
- };
-});
-
-jest.mock('shared/views/files/FileStorage', () => ({
- template: '',
-}));
-
-jest.mock('shared/leUtils/FormatPresets', () => ({
- __esModule: true,
- default: new Map(),
- FormatPresetsList: [],
- FormatPresetsNames: {
- AUDIO: 'audio',
- AUDIO_DEPENDENCY: 'audio_dependency',
- AUDIO_THUMBNAIL: 'audio_thumbnail',
- BLOOMPUB: 'bloompub',
- CHANNEL_THUMBNAIL: 'channel_thumbnail',
- DOCUMENT: 'document',
- DOCUMENT_THUMBNAIL: 'document_thumbnail',
- EPUB: 'epub',
- EXERCISE: 'exercise',
- EXERCISE_GRAPHIE: 'exercise_graphie',
- EXERCISE_IMAGE: 'exercise_image',
- EXERCISE_THUMBNAIL: 'exercise_thumbnail',
- H5P: 'h5p',
- H5P_THUMBNAIL: 'h5p_thumbnail',
- HIGH_RES_VIDEO: 'high_res_video',
- HTML5_DEPENDENCY: 'html5_dependency',
- HTML5_THUMBNAIL: 'html5_thumbnail',
- HTML5_ZIP: 'html5_zip',
- IMSCP_ZIP: 'imscp_zip',
- KPUB: 'kpub',
- LOW_RES_VIDEO: 'low_res_video',
- QTI: 'qti',
- QTI_THUMBNAIL: 'qti_thumbnail',
- SLIDESHOW_IMAGE: 'slideshow_image',
- SLIDESHOW_MANIFEST: 'slideshow_manifest',
- SLIDESHOW_THUMBNAIL: 'slideshow_thumbnail',
- TOPIC_THUMBNAIL: 'topic_thumbnail',
- VIDEO_DEPENDENCY: 'video_dependency',
- VIDEO_SUBTITLE: 'video_subtitle',
- VIDEO_THUMBNAIL: 'video_thumbnail',
- ZIM: 'zim',
- ZIM_THUMBNAIL: 'zim_thumbnail',
- },
-}));
-
-jest.mock('shared/leUtils/ContentKinds', () => ({
- ContentKindLearningActivityDefaults: {},
-}));
-
-jest.mock('shared/utils/validation', () => ({
- isNodeComplete: jest.fn().mockReturnValue(true),
-}));
-
-// Mocking child components
-
-jest.mock('../EditView', () => ({
- name: 'EditView',
- template: '',
-}));
-
-jest.mock('../DetailsTabView', () => ({
- name: 'DetailsTabView',
- template: '',
-}));
-
-jest.mock('../AccessibilityOptions', () => ({
- name: 'AccessibilityOptions',
- template: '',
-}));
-
-/* Test setup and configuration */
-
-const localVue = createLocalVue();
-localVue.use(Vuex);
-localVue.use(VueRouter);
-
-/* Vue prototype properties */
-localVue.prototype.$isRTL = false;
-localVue.prototype.$tr = msg => msg;
-localVue.prototype.$themeTokens = { textInverted: 'white' };
-localVue.prototype.$analytics = { trackAction: jest.fn() };
-const mockRouter = new VueRouter({
- routes: [
- {
- path: '/',
- name: 'CONTENTNODE_DETAILS',
- },
- {
- path: '/tree',
- name: 'TREE_VIEW',
- },
- ],
-});
-
-const originalPush = mockRouter.push;
-mockRouter.push = function push(location) {
- return originalPush.call(this, location).catch(err => {
- if (err.name === 'NavigationDuplicated') return;
- throw err;
- });
-};
-
-/* Component stubs */
-const stubs = {
- VDialog: true,
- VCard: true,
- VToolbar: true,
- VToolbarTitle: true,
- VSpacer: true,
- VToolbarItems: true,
- VContent: true,
- VLayout: true,
- VFlex: true,
- Icon: true,
- OfflineText: true,
- ResizableNavigationDrawer: true,
- FileDropzone: true,
- ToolBar: true,
- LoadingText: true,
- BottomBar: true,
- SavingIndicator: true,
- MessageDialog: true,
- Uploader: true,
-};
-
-/* Vuex store configuration */
-const baseModules = {
- contentNode: {
- namespaced: true,
- getters: {
- getContentNode: () => () => ({
- title: 'Test Node',
- complete: true,
- kind: 'video',
- }),
- getContentNodeIsValid: () => () => true,
- },
- actions: {
- loadContentNodes: jest.fn().mockResolvedValue([]),
- loadRelatedResources: jest.fn().mockResolvedValue([]),
- loadContentNode: jest.fn().mockResolvedValue({}),
- updateContentNode: jest.fn().mockResolvedValue({}),
- },
- mutations: {
- ENABLE_VALIDATION_ON_NODES: jest.fn(),
- },
- },
- assessmentItem: {
- namespaced: true,
- getters: {
- getAssessmentItems: () => () => [],
- },
- actions: {
- loadAssessmentItems: jest.fn().mockResolvedValue([]),
- },
- },
- currentChannel: {
- namespaced: true,
- getters: {
- currentChannel: () => ({ id: 'test-channel' }),
- canEdit: () => true,
- },
- },
- file: {
- namespaced: true,
- getters: {
- contentNodesAreUploading: () => () => false,
- getContentNodeFiles: () => () => [],
- },
- actions: {
- loadFiles: jest.fn().mockResolvedValue([]),
- },
- },
- connection: {
- namespaced: true,
- state: {
- online: true,
- },
- getters: {
- online: state => state.online,
- },
- },
-};
-
-let store;
-
-describe('EditModal KModal Dialogs', () => {
- beforeEach(() => {
- store = new Vuex.Store({
- getters: {
- appendChannelName: jest.fn(name => name),
- },
- modules: baseModules,
- });
- mockRouter.push('/');
- });
-
- /* Upload in progress dialog */
- describe('Upload in progress dialog', () => {
- it('should show dialog when promptUploading is true', async () => {
- render(EditModal, {
- localVue,
- store,
- router: mockRouter,
- stubs,
- propsData: {
- detailNodeIds: 'test-node-id',
- tab: 'details',
- },
- data() {
- return {
- loading: false,
- loadError: false,
- promptUploading: true,
- };
- },
- });
-
- await waitFor(() => {
- expect(
- screen.getByRole('heading', { name: /uploadInProgressHeader/i }),
- ).toBeInTheDocument();
- expect(screen.getByText('uploadInProgressText')).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'dismissDialogButton' })).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'cancelUploadsButton' })).toBeInTheDocument();
- });
- });
-
- it('should close dialog when cancel is clicked', async () => {
- render(EditModal, {
- localVue,
- store,
- router: mockRouter,
- stubs,
- propsData: {
- detailNodeIds: 'test-node-id',
- tab: 'details',
- },
- data() {
- return {
- loading: false,
- loadError: false,
- promptUploading: true,
- };
- },
- });
-
- await waitFor(() => {
- expect(
- screen.getByRole('heading', { name: /uploadInProgressHeader/i }),
- ).toBeInTheDocument();
- });
-
- const cancelButton = screen.getByRole('button', { name: 'dismissDialogButton' });
- await fireEvent.click(cancelButton);
-
- await waitFor(() => {
- expect(
- screen.queryByRole('heading', { name: /uploadInProgressHeader/i }),
- ).not.toBeInTheDocument();
- });
- });
- });
-
- /* Save failed dialog */
- describe('Save failed dialog', () => {
- it('should show dialog when promptFailed is true', async () => {
- render(EditModal, {
- localVue,
- store,
- router: mockRouter,
- stubs,
- propsData: {
- detailNodeIds: 'test-node-id',
- tab: 'details',
- },
- data() {
- return {
- loading: false,
- loadError: false,
- promptFailed: true,
- };
- },
- });
-
- await waitFor(() => {
- expect(screen.getByRole('heading', { name: /saveFailedHeader/i })).toBeInTheDocument();
- expect(screen.getByText('saveFailedText')).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'okButton' })).toBeInTheDocument();
- expect(
- screen.getByRole('button', { name: 'closeWithoutSavingButton' }),
- ).toBeInTheDocument();
- });
- });
-
- it('should close dialog when OK is clicked', async () => {
- render(EditModal, {
- localVue,
- store,
- router: mockRouter,
- stubs,
- propsData: {
- detailNodeIds: 'test-node-id',
- tab: 'details',
- },
- data() {
- return {
- loading: false,
- loadError: false,
- promptFailed: true,
- };
- },
- });
-
- await waitFor(() => {
- expect(screen.getByRole('heading', { name: /saveFailedHeader/i })).toBeInTheDocument();
- });
-
- const okButton = screen.getByRole('button', { name: 'okButton' });
- await fireEvent.click(okButton);
-
- await waitFor(() => {
- expect(
- screen.queryByRole('heading', { name: /saveFailedHeader/i }),
- ).not.toBeInTheDocument();
- });
- });
-
- it('should close dialog when "Close without saving" is clicked', async () => {
- render(EditModal, {
- localVue,
- store,
- router: mockRouter,
- stubs,
- propsData: {
- detailNodeIds: 'test-node-id',
- tab: 'details',
- },
- data() {
- return {
- loading: false,
- loadError: false,
- promptFailed: true,
- };
- },
- });
-
- await waitFor(() => {
- expect(screen.getByRole('heading', { name: /saveFailedHeader/i })).toBeInTheDocument();
- });
-
- const submitButton = screen.getByRole('button', { name: 'closeWithoutSavingButton' });
- await fireEvent.click(submitButton);
-
- await waitFor(() => {
- expect(
- screen.queryByRole('heading', { name: /saveFailedHeader/i }),
- ).not.toBeInTheDocument();
- });
- });
- });
-
- /* Upload in progress dialog submit action */
- describe('Upload in progress dialog submit action', () => {
- it('should close dialog when "Exit" is clicked', async () => {
- render(EditModal, {
- localVue,
- store,
- router: mockRouter,
- stubs,
- propsData: {
- detailNodeIds: 'test-node-id',
- tab: 'details',
- },
- data() {
- return {
- loading: false,
- loadError: false,
- promptUploading: true,
- };
- },
- });
-
- await waitFor(() => {
- expect(
- screen.getByRole('heading', { name: /uploadInProgressHeader/i }),
- ).toBeInTheDocument();
- });
-
- const exitButton = screen.getByRole('button', { name: 'cancelUploadsButton' });
- await fireEvent.click(exitButton);
-
- await waitFor(() => {
- expect(
- screen.queryByRole('heading', { name: /uploadInProgressHeader/i }),
- ).not.toBeInTheDocument();
- });
- });
- });
-});