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.
Bug Fix: Error When Choosing Not to Unpublish a Form (bcgov#1331)
* removed routing * disable toggle if navigating from form designer and click cancel * rewrite cancel logic * added some test cases * updated tests * fixed unpublish issue * fixed unpublish issue --------- Co-authored-by: jasonchung1871 <[email protected]>
- Loading branch information
1 parent
a8839f3
commit 54de902
Showing
2 changed files
with
113 additions
and
17 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
99 changes: 99 additions & 0 deletions
99
app/frontend/tests/unit/components/forms/manage/ManageVersions.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,99 @@ | ||
import ManageVersions from '~/components/forms/manage/ManageVersions.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"; | ||
|
||
describe("ManageVersions.vue", () => { | ||
const pinia = createTestingPinia(); | ||
const router = createRouter({ | ||
history: createWebHistory(), | ||
routes: getRouter().getRoutes(), | ||
}); | ||
|
||
setActivePinia(pinia); | ||
const formStore = useFormStore(pinia); | ||
|
||
beforeEach(() => { | ||
formStore.$reset(); | ||
}); | ||
|
||
it("publishes a draft when the status is toggled and continue is clicked", () => { | ||
// spy on updatePublish method | ||
const publishSpy = vi.spyOn(ManageVersions.methods, "updatePublish"); | ||
// mock a draft | ||
formStore.drafts = [ | ||
{ | ||
id: '123-456', | ||
version: '1', | ||
published: false, | ||
}, | ||
]; | ||
const wrapper = mount(ManageVersions, { | ||
global: { | ||
plugins: [router, pinia], | ||
mocks: { | ||
$filters: { | ||
formatDateLong: vi.fn().mockReturnValue("formatted date") | ||
} | ||
}, | ||
provide: { | ||
formDesigner: false, | ||
draftId: '123-456', | ||
formId: '123-456', | ||
}, | ||
}, | ||
}); | ||
// Call the togglePublish method (simulates user clicking the status toggle) | ||
wrapper.vm.togglePublish(true, '123-456', '1', true); | ||
// Find the BaseDialog with v-model="showPublishDialog" | ||
const baseDialog = wrapper.findAllComponents({ name: 'BaseDialog' }) | ||
.find(w => w.props('type') === 'CONTINUE'); | ||
// Emit the continue-dialog event (simulate clicking continue in the dialog) | ||
baseDialog.vm.$emit('continue-dialog'); | ||
|
||
expect(publishSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it("does not publish a draft when the status is toggled and cancel is clicked", () => { | ||
// spy on updatePublish method | ||
const publishSpy = vi.spyOn(ManageVersions.methods, "updatePublish"); | ||
// mock a draft | ||
formStore.drafts = [ | ||
{ | ||
id: '123-456', | ||
version: '1', | ||
published: false, | ||
}, | ||
]; | ||
const wrapper = mount(ManageVersions, { | ||
global: { | ||
plugins: [router, pinia], | ||
mocks: { | ||
$filters: { | ||
formatDateLong: vi.fn().mockReturnValue("formatted date") | ||
} | ||
}, | ||
provide: { | ||
formDesigner: false, | ||
draftId: '123-456', | ||
formId: '123-456', | ||
}, | ||
}, | ||
}); | ||
// Call the togglePublish method (simulates user clicking the status toggle) | ||
wrapper.vm.togglePublish(true, '123-456', '2', true); | ||
// Find the BaseDialog with v-model="showPublishDialog" | ||
const baseDialog = wrapper.findAllComponents({ name: 'BaseDialog' }) | ||
.find(w => w.props('type') === 'CONTINUE'); | ||
// Emit the close-dialog event (simulate clicking cancel in the dialog) | ||
baseDialog.vm.$emit('close-dialog'); | ||
|
||
expect(publishSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
|
||
}); |