diff --git a/app/src/services/submission.ts b/app/src/services/submission.ts index 34fbe3f5..a7350a9e 100644 --- a/app/src/services/submission.ts +++ b/app/src/services/submission.ts @@ -246,6 +246,9 @@ const service = { } }, user: true + }, + orderBy: { + created_at: 'desc' } }); diff --git a/frontend/src/components/housing/submission/SubmissionIntakeForm.vue b/frontend/src/components/housing/submission/SubmissionIntakeForm.vue index 970d584a..eabe0c8a 100644 --- a/frontend/src/components/housing/submission/SubmissionIntakeForm.vue +++ b/frontend/src/components/housing/submission/SubmissionIntakeForm.vue @@ -49,14 +49,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 { omit } from '@/utils/utils'; @@ -298,8 +291,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; @@ -315,8 +306,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 }; @@ -376,7 +365,6 @@ async function onSubmit(data: any) { } } catch (e: any) { toast.error('Failed to save intake', e); - } finally { editable.value = true; } } @@ -466,6 +454,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 = { @@ -532,8 +523,6 @@ onBeforeMount(async () => { await nextTick(); - editable.value = response.intakeStatus !== IntakeStatus.SUBMITTED; - // Move map pin onLatLongInputClick(); } catch (e) { diff --git a/frontend/tests/unit/components/shasIntake/SubmissionIntakeForm.spec.ts b/frontend/tests/unit/components/shasIntake/SubmissionIntakeForm.spec.ts index 04177c0e..49039d67 100644 --- a/frontend/tests/unit/components/shasIntake/SubmissionIntakeForm.spec.ts +++ b/frontend/tests/unit/components/shasIntake/SubmissionIntakeForm.spec.ts @@ -3,15 +3,17 @@ 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 { flushPromises, mount, RouterLinkStub } 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'; import type { AxiosResponse } from 'axios'; +import type { Submission } from '@/types'; +import { nextTick } from 'vue'; vi.mock('vue-i18n', () => ({ useI18n: () => ({ @@ -135,6 +137,41 @@ describe('SubmissionIntakeForm', () => { expect(wrapper).toBeTruthy(); }); + it('sets editable to true in draft mode', async () => { + const getDraftSpy = vi.spyOn(submissionService, 'getDraft'); + + getDraftSpy.mockResolvedValue({ activityId: '123' } as any); + + const wrapper = mount(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 = mount(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());