import {createStore, initLocalVue, mountComposition} from '~/tests/unit/Helpers' import { form } from '~/tests/unit/fixture/state/profile' import {useForm} from "~/composables/form/useForm"; import { AnyStore } from '~/types/interfaces' import {FORM_STATUS, SUBMIT_TYPE} from "~/types/enums"; import {Route} from "vue-router"; let store: AnyStore let useFormMount:any beforeAll(() => { store = createStore() store.registerModule('form', form) initLocalVue({store: store}) const component = mountComposition(() => { useFormMount = useForm(store) }); }) describe('markFormAsDirty()', () => { it('should commit the form state dirty to true', async () => { useFormMount.markAsDirty() expect(store.state.form.dirty).toBeTruthy() }) }) describe('markAsNotDirty()', () => { it('should commit the form state dirty to false', async () => { useFormMount.markAsNotDirty() expect(store.state.form.dirty).toBeFalsy() }) }) describe('nextStepFactory()', () => { const route: Route = { path: 'ma_route', hash: 'hash', query: {}, params: {}, fullPath: 'ma_route', matched: [] } it('should push the new route when the action is save and back', async () => { const router: any = [] useFormMount.nextStepFactory(route, {}, router)[SUBMIT_TYPE.SAVE_AND_BACK]() expect(router).toHaveLength(1) }) it('should dont push the new route when the action is save and the form is EDIT', async () => { store.commit('form/setFormStatus', FORM_STATUS.EDIT) const router: any = [] useFormMount.nextStepFactory(route, {}, router)[SUBMIT_TYPE.SAVE]() expect(router).toHaveLength(0) }) it('should push the new route when the action is save and the form is CREATE', async () => { store.commit('form/setFormStatus', FORM_STATUS.CREATE) const router: any = [] useFormMount.nextStepFactory(route, {}, router)[SUBMIT_TYPE.SAVE]() expect(router).toHaveLength(1) }) })