diff --git a/admin-frontend/src/components/announcements/AnnouncementForm.vue b/admin-frontend/src/components/announcements/AnnouncementForm.vue index b95bb2801..da500cda4 100644 --- a/admin-frontend/src/components/announcements/AnnouncementForm.vue +++ b/admin-frontend/src/components/announcements/AnnouncementForm.vue @@ -398,6 +398,11 @@ import AnnouncementStatusChip from './AnnouncementStatusChip.vue'; import type { VTextField } from 'vuetify/components'; import RichTextArea from '../RichTextArea.vue'; +const announcementStatusOptions = [ + AnnouncementStatus.Draft, + AnnouncementStatus.Published, +]; + // References to component's exported properties const announcementTitleRef = ref(null); const linkUrlRef = ref(null); @@ -480,7 +485,11 @@ const { handleSubmit, setErrors, errors, meta, values } = useForm({ linkDisplayName: announcement?.linkDisplayName || '', fileDisplayName: announcement?.fileDisplayName || '', attachmentId: announcement?.attachmentId || v4(), - status: announcement?.status || 'DRAFT', + status: + announcement?.status && + announcementStatusOptions.indexOf(announcement.status as any) >= 0 + ? announcement.status + : AnnouncementStatus.Draft, attachment: undefined, }, validationSchema: { diff --git a/admin-frontend/src/components/announcements/__tests__/AnnouncementForm.spec.ts b/admin-frontend/src/components/announcements/__tests__/AnnouncementForm.spec.ts index 730999b60..51343066e 100644 --- a/admin-frontend/src/components/announcements/__tests__/AnnouncementForm.spec.ts +++ b/admin-frontend/src/components/announcements/__tests__/AnnouncementForm.spec.ts @@ -1,9 +1,13 @@ import { createTestingPinia } from '@pinia/testing'; import { flushPromises, mount } from '@vue/test-utils'; -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { afterEach, describe, expect, it, vi } from 'vitest'; import { createVuetify } from 'vuetify'; import * as components from 'vuetify/components'; import * as directives from 'vuetify/directives'; +import { + AnnouncementFormMode, + AnnouncementStatus, +} from '../../../types/announcements'; import AnnouncementForm from '../AnnouncementForm.vue'; global.ResizeObserver = require('resize-observer-polyfill'); @@ -22,7 +26,7 @@ vi.mock('../../../services/apiService', () => ({ }, })); -describe('AnnouncementItem - Vue Test Utils tests', () => { +describe('AnnouncementForm - Vue Test Utils tests', () => { let wrapper; let pinia; @@ -36,6 +40,7 @@ describe('AnnouncementItem - Vue Test Utils tests', () => { initialState: {}, }); wrapper = mount(AnnouncementForm, { + ...options, global: { plugins: [vuetify, pinia], }, @@ -45,10 +50,6 @@ describe('AnnouncementItem - Vue Test Utils tests', () => { await flushPromises(); }; - beforeEach(async () => { - await initWrapper(); - }); - afterEach(() => { if (wrapper) { vi.clearAllMocks(); @@ -59,6 +60,7 @@ describe('AnnouncementItem - Vue Test Utils tests', () => { describe('buildAnnouncementToPreview', () => { describe('when link and attachment details are provided', () => { it('builds an announcement with resources', async () => { + await initWrapper(); wrapper.vm.announcementTitle = 'title'; wrapper.vm.announcementDescription = 'desc'; wrapper.vm.linkDisplayName = 'link name'; @@ -82,10 +84,34 @@ describe('AnnouncementItem - Vue Test Utils tests', () => { describe('Link Url', () => { it('should display the length and max length even if it is too long', async () => { + await initWrapper(); const longUrl = 'http://' + 'x'.repeat(255); const test = wrapper.findComponent({ ref: 'linkUrlRef' }); await test.setValue(longUrl); expect(test.html()).toContain('>262/255<'); }); }); + + describe('Edit an expired announcement', () => { + describe('When the announcement is expired', async () => { + it('Should set the default "Save As" status to "DRAFT"', async () => { + await initWrapper({ + props: { + announcement: { + title: 'My announcement', + description: 'Description here', + active_on: '2024-11-25T19:46:56.000Z', + expires_on: '2024-11-25T19:46:57.000Z', + status: AnnouncementStatus.Expired as string, + announcement_id: 'dfs543sdf4r56', + no_expiry: true, + }, + title: 'Title', + mode: AnnouncementFormMode.EDIT, + }, + }); + expect(wrapper.vm.status).toBe(AnnouncementStatus.Draft); + }); + }); + }); });