Skip to content

Commit

Permalink
Merge pull request #232 from bcgov/bug/intake-readonly
Browse files Browse the repository at this point in the history
Resolve issue with form incorrectly setting read-only state
  • Loading branch information
wilwong89 authored Jan 3, 2025
2 parents 85a68a0 + be8a4a3 commit 4ba83d3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
3 changes: 3 additions & 0 deletions app/src/services/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ const service = {
}
},
user: true
},
orderBy: {
created_at: 'desc'
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,7 @@ import {
PROJECT_RELATIONSHIP_LIST
} from '@/utils/constants/housing';
import { BasicResponse, RouteName } from '@/utils/enums/application';
import {
IntakeFormCategory,
IntakeStatus,
PermitNeeded,
PermitStatus,
ProjectLocation,
SubmissionType
} from '@/utils/enums/housing';
import { IntakeFormCategory, PermitNeeded, PermitStatus, ProjectLocation, SubmissionType } from '@/utils/enums/housing';
import { confirmationTemplateSubmission } from '@/utils/templates';
import { getHTMLElement, omit } from '@/utils/utils';
Expand Down Expand Up @@ -300,8 +293,6 @@ function onPermitsHasAppliedChange(e: BasicResponse, fieldsLength: number, push:
}
async function onSaveDraft(data: GenericObject, isAutoSave: boolean = false, showToast: boolean = true) {
editable.value = false;
autoSaveRef.value?.stopAutoSave();
let response;
Expand All @@ -317,8 +308,6 @@ async function onSaveDraft(data: GenericObject, isAutoSave: boolean = false, sho
if (showToast) toast.success(isAutoSave ? 'Draft autosaved' : 'Draft saved');
} catch (e: any) {
toast.error('Failed to save draft', e);
} finally {
editable.value = true;
}
return { activityId: response?.data.activityId, draftId: response?.data.draftId };
Expand Down Expand Up @@ -378,7 +367,6 @@ async function onSubmit(data: any) {
}
} catch (e: any) {
toast.error('Failed to save intake', e);
} finally {
editable.value = true;
}
}
Expand Down Expand Up @@ -468,6 +456,9 @@ onBeforeMount(async () => {
permits = (await permitService.listPermits({ activityId: activityId })).data;
documents = (await documentService.listDocuments(activityId)).data;
submissionStore.setDocuments(documents);
// Set form to read-only on non draft form reopening
editable.value = false;
}
initialFormValues.value = {
Expand Down Expand Up @@ -534,8 +525,6 @@ onBeforeMount(async () => {
await nextTick();
editable.value = response.intakeStatus !== IntakeStatus.SUBMITTED;
// Move map pin
onLatLongInputClick();
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import PrimeVue from 'primevue/config';
import ConfirmationService from 'primevue/confirmationservice';
import ToastService from 'primevue/toastservice';
import Tooltip from 'primevue/tooltip';
import { mount, RouterLinkStub } from '@vue/test-utils';
import { nextTick } from 'vue';
import { flushPromises, mount, RouterLinkStub, shallowMount } from '@vue/test-utils';

import SubmissionIntakeForm from '@/components/housing/submission/SubmissionIntakeForm.vue';
import { submissionIntakeSchema } from '@/components/housing/submission/SubmissionIntakeSchema';
import { permitService } from '@/services';
import { documentService, permitService, submissionService } from '@/services';
import { NUM_RESIDENTIAL_UNITS_LIST } from '@/utils/constants/housing';
import { BasicResponse, StorageKey } from '@/utils/enums/application';

Expand Down Expand Up @@ -135,6 +136,43 @@ describe('SubmissionIntakeForm', () => {
expect(wrapper).toBeTruthy();
});

describe('onBeforeMount', () => {
it('keeps editable true in draft mode', async () => {
const getDraftSpy = vi.spyOn(submissionService, 'getDraft');

getDraftSpy.mockResolvedValue({ activityId: '123' } as any);

const wrapper = shallowMount(SubmissionIntakeForm, { ...wrapperSettings(), props: { draftId: '123' } });

await nextTick();
await flushPromises();

const editable = (wrapper.vm as any)?.editable;
expect(editable).toBeTruthy();
});

it('sets editable to false when activity and submission ID given', async () => {
const getSubmissionSpy = vi.spyOn(submissionService, 'getSubmission');
const listPermitsSpy = vi.spyOn(permitService, 'listPermits');
const listDocumentsSpy = vi.spyOn(documentService, 'listDocuments');

getSubmissionSpy.mockResolvedValue({ activityId: '123', submissionId: '456' } as any);
listPermitsSpy.mockResolvedValue({ permitId: '123' } as any);
listDocumentsSpy.mockResolvedValue({ documentId: '123' } as any);

const wrapper = shallowMount(SubmissionIntakeForm, {
...wrapperSettings(),
props: { activityId: '123', submissionId: '456' }
});

await nextTick();
await flushPromises();

const editable = (wrapper.vm as any)?.editable;
expect(editable).toBeFalsy();
});
});

it('checks submit btn disabled conditions', async () => {
const wrapper = mount(SubmissionIntakeForm, wrapperSettings());

Expand Down

0 comments on commit 4ba83d3

Please sign in to comment.