From 416e2e783c5585e3602a48638361b780c3d70272 Mon Sep 17 00:00:00 2001 From: Dima K Date: Mon, 20 Nov 2023 15:14:19 -0800 Subject: [PATCH 1/5] Update MHRSearch unit test --- ppr-ui/tests/unit/MHRSearch.spec.ts | 38 ++++++----------------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/ppr-ui/tests/unit/MHRSearch.spec.ts b/ppr-ui/tests/unit/MHRSearch.spec.ts index fe29a2809..76da91e65 100644 --- a/ppr-ui/tests/unit/MHRSearch.spec.ts +++ b/ppr-ui/tests/unit/MHRSearch.spec.ts @@ -1,24 +1,15 @@ // Libraries -import Vue from 'vue' -import Vuetify from 'vuetify' -import VueRouter from 'vue-router' -import { createPinia, setActivePinia } from 'pinia' import { useStore } from '../../src/store/store' -import { shallowMount, createLocalVue } from '@vue/test-utils' // Components import { SearchedResultMhr } from '@/components/tables' import { MHRSearch } from '@/views' // Other -import mockRouter from './MockRouter' import { mockedMHRSearchResponse } from './test-data' -import { UIMHRSearchTypes } from '@/enums' +import { RouteNames, UIMHRSearchTypes } from '@/enums' +import { createComponent } from './utils' -Vue.use(Vuetify) - -const vuetify = new Vuetify({}) -setActivePinia(createPinia()) const store = useStore() // Prevent the warning "[Vuetify] Unable to locate target [data-app]" @@ -34,25 +25,8 @@ describe('Search component', () => { let wrapper: any const { assign } = window.location - beforeEach(async () => { - // mock the window.location.assign function - delete window.location - window.location = { assign: jest.fn() } as any - - // create a Local Vue and install router on it - const localVue = createLocalVue() - localVue.use(VueRouter) - const router = mockRouter.mock() - await router.push({ name: 'mhr-search' }) - wrapper = shallowMount((MHRSearch as any), { localVue, store, router, vuetify }) - }) - - afterEach(() => { - window.location.assign = assign - wrapper.destroy() - }) - - it('renders Search View with base components', () => { + it('renders Search View with base components', async () => { + wrapper = await createComponent(MHRSearch, { appReady: true }, RouteNames.MHRSEARCH) expect(wrapper.findComponent(MHRSearch).exists()).toBe(true) // doesn't render unless there are results expect(wrapper.find(searchMeta).exists()).toBe(false) @@ -61,16 +35,20 @@ describe('Search component', () => { expect(wrapper.find(folioHeader).exists()).toBe(false) expect(wrapper.findComponent(SearchedResultMhr).exists()).toBe(false) }) + it('renders the Results component and displays search data elements with filled result set.', async () => { await store.setManufacturedHomeSearchResults(mockedMHRSearchResponse[UIMHRSearchTypes.MHRMHR_NUMBER]) + wrapper = await createComponent(MHRSearch, { appReady: true }, RouteNames.MHRSEARCH) expect(wrapper.find(noResultsInfo).exists()).toBe(false) expect(wrapper.findComponent(SearchedResultMhr).exists()).toBe(true) }) + it('renders the Results component and displays search data elements with empty result set.', async () => { const response = mockedMHRSearchResponse[UIMHRSearchTypes.MHRMHR_NUMBER] response.totalResultsSize = 0 response.results = [] await store.setManufacturedHomeSearchResults(response) + wrapper = await createComponent(MHRSearch, { appReady: true }, RouteNames.MHRSEARCH) expect(wrapper.find(noResultsInfo).exists()).toBe(true) expect(wrapper.findComponent(SearchedResultMhr).exists()).toBe(true) }) From f4614f122f1a845399f5ed9b79f83d48f175bf33 Mon Sep 17 00:00:00 2001 From: Dima K Date: Tue, 21 Nov 2023 18:17:03 -0800 Subject: [PATCH 2/5] Update MHR related unit tests --- ppr-ui/tests/unit/HomeSections.spec.ts | 44 ++++------------------- ppr-ui/tests/unit/MHRSearch.spec.ts | 16 ++++----- ppr-ui/tests/unit/MhrCivicAddress.spec.ts | 33 +++-------------- 3 files changed, 18 insertions(+), 75 deletions(-) diff --git a/ppr-ui/tests/unit/HomeSections.spec.ts b/ppr-ui/tests/unit/HomeSections.spec.ts index a7e2a4beb..29e756f6f 100644 --- a/ppr-ui/tests/unit/HomeSections.spec.ts +++ b/ppr-ui/tests/unit/HomeSections.spec.ts @@ -1,56 +1,25 @@ // Libraries -import Vue, { nextTick } from 'vue' -import Vuetify from 'vuetify' -import { createPinia, setActivePinia } from 'pinia' import { useStore } from '../../src/store/store' -import { mount, createLocalVue, Wrapper } from '@vue/test-utils' - // Components -import { HomeSections } from '@/components/mhrRegistration' -import AddEditHomeSections from '@/components/mhrRegistration/YourHome/AddEditHomeSections.vue' -import HomeSectionsTable from '@/components/tables/mhr/HomeSectionsTable.vue' +import { AddEditHomeSections, HomeSections } from '@/components/mhrRegistration' import { mockedHomeSections } from './test-data/mock-home-sections' +import { createComponent } from './utils' +import { HomeSectionsTable } from '@/components/tables/mhr' -Vue.use(Vuetify) - -const vuetify = new Vuetify({}) -setActivePinia(createPinia()) const store = useStore() const addEditHomeSectionBtn = '.add-home-section-btn' const sectionCounter = '#section-count' const errorText = '.error-text' -/** - * Creates and mounts a component, so that it can be tested. - * - * @returns a Wrapper object with the given parameters. - */ -function createComponent (): Wrapper { - const localVue = createLocalVue() - - localVue.use(Vuetify) - document.body.setAttribute('data-app', 'true') - return mount((HomeSections as any), { - localVue, - propsData: {}, - store, - vuetify - }) -} - describe('Home Sections', () => { - let wrapper: Wrapper + let wrapper beforeEach(async () => { // Set home sections default await store.setMhrHomeDescription({ key: 'sections', value: [] }) - - wrapper = createComponent() - }) - afterEach(() => { - wrapper.destroy() + wrapper = await createComponent(HomeSections) }) it('renders base component with sub components', async () => { @@ -81,8 +50,7 @@ describe('Home Sections', () => { // Verify hidden by default expect(wrapper.findComponent(AddEditHomeSections).exists()).toBe(false) await wrapper.find(addEditHomeSectionBtn).trigger('click') - - expect(wrapper.find(addEditHomeSectionBtn).attributes('disabled')).toBe('disabled') + expect(wrapper.find(addEditHomeSectionBtn).getCurrentComponent().props.disabled).toBe(true) }) it('counts the added Home Sections', async () => { diff --git a/ppr-ui/tests/unit/MHRSearch.spec.ts b/ppr-ui/tests/unit/MHRSearch.spec.ts index 76da91e65..95b491602 100644 --- a/ppr-ui/tests/unit/MHRSearch.spec.ts +++ b/ppr-ui/tests/unit/MHRSearch.spec.ts @@ -9,6 +9,7 @@ import { MHRSearch } from '@/views' import { mockedMHRSearchResponse } from './test-data' import { RouteNames, UIMHRSearchTypes } from '@/enums' import { createComponent } from './utils' +import { nextTick } from 'vue' const store = useStore() @@ -23,10 +24,12 @@ const folioHeader = '#results-folio-header' describe('Search component', () => { let wrapper: any - const { assign } = window.location - it('renders Search View with base components', async () => { + beforeEach(async () => { wrapper = await createComponent(MHRSearch, { appReady: true }, RouteNames.MHRSEARCH) + }) + + it('renders Search View with base components', async () => { expect(wrapper.findComponent(MHRSearch).exists()).toBe(true) // doesn't render unless there are results expect(wrapper.find(searchMeta).exists()).toBe(false) @@ -38,17 +41,14 @@ describe('Search component', () => { it('renders the Results component and displays search data elements with filled result set.', async () => { await store.setManufacturedHomeSearchResults(mockedMHRSearchResponse[UIMHRSearchTypes.MHRMHR_NUMBER]) - wrapper = await createComponent(MHRSearch, { appReady: true }, RouteNames.MHRSEARCH) + await nextTick() expect(wrapper.find(noResultsInfo).exists()).toBe(false) expect(wrapper.findComponent(SearchedResultMhr).exists()).toBe(true) }) it('renders the Results component and displays search data elements with empty result set.', async () => { - const response = mockedMHRSearchResponse[UIMHRSearchTypes.MHRMHR_NUMBER] - response.totalResultsSize = 0 - response.results = [] - await store.setManufacturedHomeSearchResults(response) - wrapper = await createComponent(MHRSearch, { appReady: true }, RouteNames.MHRSEARCH) + await store.setManufacturedHomeSearchResults({ ...mockedMHRSearchResponse[UIMHRSearchTypes.MHRMHR_NUMBER], totalResultsSize: 0, results: [] }) + await nextTick() expect(wrapper.find(noResultsInfo).exists()).toBe(true) expect(wrapper.findComponent(SearchedResultMhr).exists()).toBe(true) }) diff --git a/ppr-ui/tests/unit/MhrCivicAddress.spec.ts b/ppr-ui/tests/unit/MhrCivicAddress.spec.ts index 0e09f2350..08b6f6641 100644 --- a/ppr-ui/tests/unit/MhrCivicAddress.spec.ts +++ b/ppr-ui/tests/unit/MhrCivicAddress.spec.ts @@ -1,41 +1,16 @@ -import Vue, { nextTick } from 'vue' -import Vuetify from 'vuetify' -import { createPinia, setActivePinia } from 'pinia' -import { useStore } from '../../src/store/store' +import { nextTick } from 'vue' -import { mount, createLocalVue, Wrapper } from '@vue/test-utils' import { HomeCivicAddress } from '@/components/mhrRegistration/HomeLocation' - -Vue.use(Vuetify) -setActivePinia(createPinia()) -const store = useStore() -const vuetify = new Vuetify({}) - -/** - * Creates and mounts a component, so that it can be tested. - * @returns a Wrapper object with the given parameters. - */ -function createComponent (): Wrapper { - const localVue = createLocalVue() - - return mount((HomeCivicAddress as any), { - localVue, - store, - vuetify - }) -} +import { createComponent } from './utils' // Error message class selector const ERROR_MSG = '.error--text .v-messages__message' describe('mhr home civic address', () => { - let wrapper: Wrapper + let wrapper beforeEach(async () => { - wrapper = createComponent() - }) - afterEach(() => { - wrapper.destroy() + wrapper = await createComponent(HomeCivicAddress ) }) it('renders the component', async () => { From 7a7bf6bff0e05a6ce6e569ff8f42183fd391e362 Mon Sep 17 00:00:00 2001 From: Dima K Date: Fri, 24 Nov 2023 09:02:44 -0800 Subject: [PATCH 3/5] Update MHR unit tests --- ppr-ui/package-lock.json | 4 +- ppr-ui/package.json | 4 +- ppr-ui/src/components/common/Attention.vue | 1 + ppr-ui/src/components/common/ButtonFooter.vue | 1 + .../YourHome/HomeCertification.vue | 8 +-- ppr-ui/tests/setup.ts | 3 +- ppr-ui/tests/unit/HomeCertification.spec.ts | 68 ++++++++----------- ppr-ui/tests/unit/HomeLandOwnership.spec.ts | 40 ++--------- ppr-ui/tests/unit/MhrCivicAddress.spec.ts | 5 +- ppr-ui/tests/unit/OtherInformation.spec.ts | 35 ++-------- ppr-ui/tests/unit/SimpleHelpToggle.spec.ts | 36 ++-------- ppr-ui/tests/unit/SortingIcon.spec.ts | 19 ++---- ppr-ui/tests/unit/plugins/data-test-id.ts | 22 ++++++ ppr-ui/tests/unit/plugins/index.ts | 1 + 14 files changed, 86 insertions(+), 161 deletions(-) create mode 100644 ppr-ui/tests/unit/plugins/data-test-id.ts create mode 100644 ppr-ui/tests/unit/plugins/index.ts diff --git a/ppr-ui/package-lock.json b/ppr-ui/package-lock.json index e5a6186fa..2756b2c0a 100644 --- a/ppr-ui/package-lock.json +++ b/ppr-ui/package-lock.json @@ -1,12 +1,12 @@ { "name": "ppr-ui", - "version": "3.0.3", + "version": "3.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ppr-ui", - "version": "3.0.3", + "version": "3.0.4", "dependencies": { "@lemoncode/fonk": "^1.5.1", "@lemoncode/fonk-range-number-validator": "^1.1.0", diff --git a/ppr-ui/package.json b/ppr-ui/package.json index 01e922e40..e092bb504 100644 --- a/ppr-ui/package.json +++ b/ppr-ui/package.json @@ -1,13 +1,13 @@ { "name": "ppr-ui", - "version": "3.0.3", + "version": "3.0.4", "private": true, "appName": "Assets UI", "sbcName": "SBC Common Components", "scripts": { "dev": "vite", "build": "vite build", - "serve": "vite preview", + "serve": "vite dev", "lint": "eslint . --ext .js,.ts,.vue", "test:unit": "vitest run", "test:coverage": "vitest run --coverage" diff --git a/ppr-ui/src/components/common/Attention.vue b/ppr-ui/src/components/common/Attention.vue index 219cece0d..ff181db3a 100644 --- a/ppr-ui/src/components/common/Attention.vue +++ b/ppr-ui/src/components/common/Attention.vue @@ -65,6 +65,7 @@ export default defineComponent({ }, sectionNumber: { type: Number, + default: null, required: false }, validate: { diff --git a/ppr-ui/src/components/common/ButtonFooter.vue b/ppr-ui/src/components/common/ButtonFooter.vue index eebe54f69..886e311dd 100644 --- a/ppr-ui/src/components/common/ButtonFooter.vue +++ b/ppr-ui/src/components/common/ButtonFooter.vue @@ -208,6 +208,7 @@ export default defineComponent({ return props.navConfig[i] } } + return null }) }) const cancel = () => { diff --git a/ppr-ui/src/components/mhrRegistration/YourHome/HomeCertification.vue b/ppr-ui/src/components/mhrRegistration/YourHome/HomeCertification.vue index c9a26d4ea..6d68e8c1e 100644 --- a/ppr-ui/src/components/mhrRegistration/YourHome/HomeCertification.vue +++ b/ppr-ui/src/components/mhrRegistration/YourHome/HomeCertification.vue @@ -22,13 +22,13 @@ >