Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: GEO-1239 - edit expired announcement now has default 'save as' status of 'DRAFT' #861

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});
});
Loading