From da6e4be12951555537a5188a1f83bee135246b07 Mon Sep 17 00:00:00 2001 From: davwas Date: Wed, 18 Oct 2023 13:06:11 +0200 Subject: [PATCH] BC-5426 - Add a delete option to the school specific Privacy Policy and Terms of Use (#2853) * add delete action to terms of use and privacy policy modules * add views and actions to remove terms of use and privacy policy * add an option to download policy and terms from new admin page --- .../administration/SchoolPolicy.unit.ts | 47 ++++++-- .../organisms/administration/SchoolPolicy.vue | 112 ++++++++++++++---- .../SchoolPolicyFormDialog.unit.ts | 8 +- .../administration/SchoolPolicyFormDialog.vue | 43 ++----- .../administration/SchoolTerms.unit.ts | 47 ++++++-- .../organisms/administration/SchoolTerms.vue | 110 +++++++++++++---- .../SchoolTermsFormDialog.unit.ts | 8 +- .../administration/SchoolTermsFormDialog.vue | 43 ++----- src/components/organisms/vCustomDialog.vue | 11 +- src/locales/de.json | 13 +- src/locales/en.json | 11 +- src/locales/es.json | 11 +- src/locales/uk.json | 7 ++ src/store/privacy-policy.ts | 18 +++ src/store/privacy-policy.unit.ts | 84 ++++++++++++- src/store/terms-of-use.ts | 18 +++ src/store/terms-of-use.unit.ts | 80 ++++++++++++- 17 files changed, 526 insertions(+), 145 deletions(-) diff --git a/src/components/organisms/administration/SchoolPolicy.unit.ts b/src/components/organisms/administration/SchoolPolicy.unit.ts index 077dbf2309..713a85e9fd 100644 --- a/src/components/organisms/administration/SchoolPolicy.unit.ts +++ b/src/components/organisms/administration/SchoolPolicy.unit.ts @@ -2,6 +2,7 @@ import SchoolPolicy from "./SchoolPolicy.vue"; import AuthModule from "@/store/auth"; import SchoolsModule from "@/store/schools"; import PrivacyPolicyModule from "@/store/privacy-policy"; +import NotifierModule from "@/store/notifier"; import { createModuleMocks } from "@/utils/mock-store-module"; import { shallowMount, Wrapper } from "@vue/test-utils"; import createComponentMocks from "@@/tests/test-utils/componentMocks"; @@ -10,16 +11,20 @@ import { ConsentVersion } from "@/store/types/consent-version"; import { AUTH_MODULE_KEY, I18N_KEY, + NOTIFIER_MODULE_KEY, PRIVACY_POLICY_MODULE_KEY, SCHOOLS_MODULE_KEY, } from "@/utils/inject"; -import Vue from "vue"; import { i18nMock } from "@@/tests/test-utils"; +import { downloadFile } from "@/utils/fileHelper"; + +jest.mock("@/utils/fileHelper"); describe("SchoolPolicy", () => { let authModule: jest.Mocked; let schoolsModule: jest.Mocked; let privacyPolicyModule: jest.Mocked; + let notifierModule: jest.Mocked; const mockPolicy: ConsentVersion = { _id: "123", @@ -68,7 +73,9 @@ describe("SchoolPolicy", () => { ...getters, }); - const wrapper: Wrapper = shallowMount(SchoolPolicy, { + notifierModule = createModuleMocks(NotifierModule); + + const wrapper: Wrapper = shallowMount(SchoolPolicy, { ...createComponentMocks({ i18n: true, }), @@ -77,6 +84,7 @@ describe("SchoolPolicy", () => { [PRIVACY_POLICY_MODULE_KEY.valueOf()]: privacyPolicyModule, [AUTH_MODULE_KEY.valueOf()]: authModule, [SCHOOLS_MODULE_KEY.valueOf()]: schoolsModule, + [NOTIFIER_MODULE_KEY.valueOf()]: notifierModule, }, }); @@ -108,22 +116,20 @@ describe("SchoolPolicy", () => { }); describe("when privacy policy is found", () => { - it("should render download button", () => { + it("should render delete button", () => { const wrapper = setup(); - expect(wrapper.find('[data-testid="download-button"]').exists()).toBe( - true - ); + expect(wrapper.find('[data-testid="delete-button"]').exists()).toBe(true); }); }); describe("when privacy policy is not found", () => { - it("should not render download button", () => { + it("should not render delete button", () => { const wrapper = setup({ getPrivacyPolicy: null, }); - expect(wrapper.find('[data-testid="download-button"]').exists()).toBe( + expect(wrapper.find('[data-testid="delete-button"]').exists()).toBe( false ); }); @@ -161,9 +167,30 @@ describe("SchoolPolicy", () => { it("should change isSchoolPolicyFormDialogOpen to true", () => { const wrapper = setup(); - expect((wrapper.vm as any).isSchoolPolicyFormDialogOpen).toBe(false); + expect(wrapper.vm.isSchoolPolicyFormDialogOpen).toBe(false); wrapper.find('[data-testid="edit-button"]').trigger("click"); - expect((wrapper.vm as any).isSchoolPolicyFormDialogOpen).toBe(true); + expect(wrapper.vm.isSchoolPolicyFormDialogOpen).toBe(true); + }); + }); + + describe("when user clicks delete button", () => { + it("should change isDeletePolicyDialogOpen to true", () => { + const wrapper = setup(); + + expect(wrapper.vm.isDeletePolicyDialogOpen).toBe(false); + wrapper.find('[data-testid="delete-button"]').trigger("click"); + expect(wrapper.vm.isDeletePolicyDialogOpen).toBe(true); + }); + }); + + describe("when user clicks policy item", () => { + it("should call downloadFile method", () => { + const wrapper = setup(); + + const downloadFileMock = jest.mocked(downloadFile).mockReturnValueOnce(); + + wrapper.find('[data-testid="policy-item"]').vm.$emit("click"); + expect(downloadFileMock).toHaveBeenCalledTimes(1); }); }); diff --git a/src/components/organisms/administration/SchoolPolicy.vue b/src/components/organisms/administration/SchoolPolicy.vue index d54e0c35e7..6fc10da73a 100644 --- a/src/components/organisms/administration/SchoolPolicy.vue +++ b/src/components/organisms/administration/SchoolPolicy.vue @@ -21,8 +21,17 @@ class="mb-6" data-testid="progress-bar" /> - - + + $file_pdf_outline @@ -33,9 +42,7 @@ @@ -50,9 +57,8 @@ - $mdiPencilOutline + $mdiTrayArrowUp - $mdiTrayArrowDown + $mdiTrashCanOutline @@ -85,13 +90,34 @@ @close="closeDialog" data-testid="form-dialog" /> + +

+ {{ t("pages.administration.school.index.schoolPolicy.delete.title") }} +

+ +
+ + diff --git a/src/components/organisms/administration/SchoolPolicyFormDialog.unit.ts b/src/components/organisms/administration/SchoolPolicyFormDialog.unit.ts index 84f5241a27..9db32125db 100644 --- a/src/components/organisms/administration/SchoolPolicyFormDialog.unit.ts +++ b/src/components/organisms/administration/SchoolPolicyFormDialog.unit.ts @@ -48,7 +48,7 @@ describe("SchoolPolicyFormDialog", () => { notifierModule = createModuleMocks(NotifierModule); - const wrapper: Wrapper = mount( + const wrapper: Wrapper = mount( SchoolPolicyFormDialog as MountOptions, { ...createComponentMocks({ @@ -72,13 +72,13 @@ describe("SchoolPolicyFormDialog", () => { const wrapper = setup(); expect( - wrapper.find('[data-testid="submit-button"]').attributes().disabled + wrapper.find('[data-testid="dialog-confirm"]').attributes().disabled ).toBeDefined(); }); it("should render warning icon", async () => { const wrapper = setup(); - (wrapper.vm as any).isTouched = true; + wrapper.vm.isTouched = true; await Vue.nextTick(); expect(wrapper.find('[data-testid="warning-icon"]').exists()).toBe(true); }); @@ -88,7 +88,7 @@ describe("SchoolPolicyFormDialog", () => { it("should emit 'close'", () => { const wrapper = setup(); - wrapper.find('[data-testid="cancel-button"]').trigger("click"); + wrapper.find('[data-testid="dialog-cancel"]').trigger("click"); expect(wrapper.emitted()).toHaveProperty("close"); }); }); diff --git a/src/components/organisms/administration/SchoolPolicyFormDialog.vue b/src/components/organisms/administration/SchoolPolicyFormDialog.vue index 71bc4acab1..2299e194b2 100644 --- a/src/components/organisms/administration/SchoolPolicyFormDialog.vue +++ b/src/components/organisms/administration/SchoolPolicyFormDialog.vue @@ -1,12 +1,21 @@