Skip to content

Commit

Permalink
Resolve issue with form incorrectly setting read-only state
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle1morel committed Dec 31, 2024
1 parent 18df550 commit 0d599d7
Show file tree
Hide file tree
Showing 3 changed files with 46 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 @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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 };
Expand Down Expand Up @@ -376,7 +365,6 @@ async function onSubmit(data: any) {
}
} catch (e: any) {
toast.error('Failed to save intake', e);
} finally {
editable.value = true;
}
}
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -532,8 +523,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,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';

Check warning on line 15 in frontend/tests/unit/components/shasIntake/SubmissionIntakeForm.spec.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (Frontend) (18.x)

'Submission' is defined but never used

Check warning on line 15 in frontend/tests/unit/components/shasIntake/SubmissionIntakeForm.spec.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (Frontend) (20.x)

'Submission' is defined but never used

Check warning on line 15 in frontend/tests/unit/components/shasIntake/SubmissionIntakeForm.spec.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (Frontend) (22.x)

'Submission' is defined but never used

Check warning on line 15 in frontend/tests/unit/components/shasIntake/SubmissionIntakeForm.spec.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (Frontend) (18.x)

'Submission' is defined but never used

Check warning on line 15 in frontend/tests/unit/components/shasIntake/SubmissionIntakeForm.spec.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (Frontend) (20.x)

'Submission' is defined but never used

Check warning on line 15 in frontend/tests/unit/components/shasIntake/SubmissionIntakeForm.spec.ts

View workflow job for this annotation

GitHub Actions / Unit Tests (Frontend) (22.x)

'Submission' is defined but never used
import { nextTick } from 'vue';

vi.mock('vue-i18n', () => ({
useI18n: () => ({
Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit 0d599d7

Please sign in to comment.