forked from bcgov/common-hosted-form-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into test/forms-1114-cypress-workflow
- Loading branch information
Showing
2 changed files
with
86 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/frontend/tests/unit/components/forms/manage/ManageForm.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import ManageForm from "~/components/forms/manage/ManageForm.vue"; | ||
import { useFormStore } from "~/store/form"; | ||
import { mount } from "@vue/test-utils"; | ||
import { createTestingPinia } from "@pinia/testing"; | ||
import { setActivePinia } from "pinia"; | ||
import { createRouter, createWebHistory } from "vue-router"; | ||
import { beforeEach, expect, vi } from "vitest"; | ||
import getRouter from "~/router"; | ||
import { FormPermissions } from '~/utils/constants'; | ||
|
||
describe("ManageForm.vue", () => { | ||
|
||
const pinia = createTestingPinia(); | ||
const router = createRouter({ | ||
history: createWebHistory(), | ||
routes: getRouter().getRoutes(), | ||
}); | ||
|
||
setActivePinia(pinia); | ||
const formStore = useFormStore(pinia); | ||
|
||
beforeEach(() => { | ||
formStore.$reset(); | ||
}); | ||
|
||
it("does not call readFormSubscriptionData without permission", () => { | ||
const readFormSpy = vi.spyOn(formStore, "readFormSubscriptionData"); | ||
formStore.permissions = []; | ||
const wrapper = mount(ManageForm, { | ||
global: { | ||
plugins: [router, pinia], | ||
mocks: { | ||
$filters: { | ||
formatDate: vi.fn().mockReturnValue("formatted date") | ||
} | ||
}, | ||
provide: { | ||
formDesigner: false, | ||
draftId: '123-456', | ||
formId: '123-456', | ||
}, | ||
}, | ||
}); | ||
expect(readFormSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("calls readFormSubscriptionData with correct permissions", () => { | ||
const readFormSpy = vi.spyOn(formStore, "readFormSubscriptionData"); | ||
formStore.permissions = [FormPermissions.FORM_UPDATE]; | ||
const wrapper = mount(ManageForm, { | ||
global: { | ||
plugins: [router, pinia], | ||
mocks: { | ||
$filters: { | ||
formatDate: vi.fn().mockReturnValue("formatted date") | ||
} | ||
}, | ||
provide: { | ||
formDesigner: false, | ||
draftId: '123-456', | ||
formId: '123-456', | ||
}, | ||
}, | ||
}); | ||
expect(readFormSpy).toBeCalledTimes(1); | ||
}); | ||
|
||
}); |