Skip to content

Commit

Permalink
fix: GEO-1239 - edit expired announcement now has default 'save as' s…
Browse files Browse the repository at this point in the history
…tatus of 'DRAFT' (#861)
  • Loading branch information
banders authored Nov 29, 2024
1 parent ae2589b commit ef0ccd9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
11 changes: 10 additions & 1 deletion admin-frontend/src/components/announcements/AnnouncementForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<VTextField | null>(null);
const linkUrlRef = ref<VTextField | null>(null);
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -22,7 +26,7 @@ vi.mock('../../../services/apiService', () => ({
},
}));

describe('AnnouncementItem - Vue Test Utils tests', () => {
describe('AnnouncementForm - Vue Test Utils tests', () => {
let wrapper;
let pinia;

Expand All @@ -36,6 +40,7 @@ describe('AnnouncementItem - Vue Test Utils tests', () => {
initialState: {},
});
wrapper = mount(AnnouncementForm, {
...options,
global: {
plugins: [vuetify, pinia],
},
Expand All @@ -45,10 +50,6 @@ describe('AnnouncementItem - Vue Test Utils tests', () => {
await flushPromises();
};

beforeEach(async () => {
await initWrapper();
});

afterEach(() => {
if (wrapper) {
vi.clearAllMocks();
Expand All @@ -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';
Expand All @@ -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);
});
});
});
});

0 comments on commit ef0ccd9

Please sign in to comment.