diff --git a/ppr-ui/package-lock.json b/ppr-ui/package-lock.json index 1355d8cd9..dc517b482 100644 --- a/ppr-ui/package-lock.json +++ b/ppr-ui/package-lock.json @@ -1,12 +1,12 @@ { "name": "ppr-ui", - "version": "2.0.10", + "version": "2.0.11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ppr-ui", - "version": "2.0.10", + "version": "2.0.11", "dependencies": { "@bcrs-shared-components/corp-type-module": "^1.0.7", "@bcrs-shared-components/enums": "^1.0.19", diff --git a/ppr-ui/package.json b/ppr-ui/package.json index 2a03d7040..34ad0869e 100644 --- a/ppr-ui/package.json +++ b/ppr-ui/package.json @@ -1,6 +1,6 @@ { "name": "ppr-ui", - "version": "2.0.10", + "version": "2.0.11", "private": true, "appName": "Assets UI", "sbcName": "SBC Common Components", diff --git a/ppr-ui/src/components/common/RegistrationsWrapper.vue b/ppr-ui/src/components/common/RegistrationsWrapper.vue index 46202699f..dbcc7a354 100644 --- a/ppr-ui/src/components/common/RegistrationsWrapper.vue +++ b/ppr-ui/src/components/common/RegistrationsWrapper.vue @@ -260,13 +260,14 @@ export default defineComponent({ } = useStore() const { // Getters - getRegTableBaseRegs, getRegTableDraftsBaseReg, isMhrRegistration, getRegTableTotalRowCount, getStateModel, - getRegTableDraftsChildReg, hasMorePages, getRegTableNewItem, getRegTableSortOptions, getRegTableSortPage, - getUserSettings, getMhRegTableBaseRegs + getRegTableBaseRegs, getRegTableDraftsBaseReg, isMhrRegistration, isMhrManufacturerRegistration, + getRegTableTotalRowCount, getStateModel, getRegTableDraftsChildReg, hasMorePages, getRegTableNewItem, + getRegTableSortOptions, getRegTableSortPage, getUserSettings, getMhRegTableBaseRegs } = storeToRefs(useStore()) const { initNewMhr, + initNewManufacturerMhr, fetchMhRegistrations } = useNewMhrRegistration() @@ -389,6 +390,10 @@ export default defineComponent({ setRegistrationType(selectedRegistration) setRegTableCollapsed(null) + if (!isMhDraft && isMhrManufacturerRegistration.value) { + await initNewManufacturerMhr() + } + const route = isMhrRegistration.value ? RouteNames.YOUR_HOME : RouteNames.LENGTH_TRUST await router.replace({ name: route }) } diff --git a/ppr-ui/src/components/common/SimpleHelpToggle.vue b/ppr-ui/src/components/common/SimpleHelpToggle.vue index a12dce884..78861b41d 100644 --- a/ppr-ui/src/components/common/SimpleHelpToggle.vue +++ b/ppr-ui/src/components/common/SimpleHelpToggle.vue @@ -6,11 +6,12 @@ class="help-btn px-0" :ripple="false" @click="isHelpContentOpen = !isHelpContentOpen" + data-test-id="help-toggle-btn" > mdi-help-circle-outline - {{ isHelpContentOpen ? 'Hide ' + title : title }} + {{ title }}
@@ -34,19 +35,22 @@ + + diff --git a/ppr-ui/src/components/mhrRegistration/YourHome/ManufacturedYearSelect.vue b/ppr-ui/src/components/mhrRegistration/YourHome/ManufacturedYearSelect.vue new file mode 100644 index 000000000..a9b902657 --- /dev/null +++ b/ppr-ui/src/components/mhrRegistration/YourHome/ManufacturedYearSelect.vue @@ -0,0 +1,119 @@ + + + + + diff --git a/ppr-ui/src/components/mhrRegistration/YourHome/ManufacturerMakeModel.vue b/ppr-ui/src/components/mhrRegistration/YourHome/ManufacturerMakeModel.vue index 4177a4dde..c5761f9e2 100644 --- a/ppr-ui/src/components/mhrRegistration/YourHome/ManufacturerMakeModel.vue +++ b/ppr-ui/src/components/mhrRegistration/YourHome/ManufacturerMakeModel.vue @@ -18,6 +18,8 @@ ref="nameRef" v-model="manufacturerName" filled + :disabled="isMhrManufacturerRegistration" + :class="{ 'unselectable' : isMhrManufacturerRegistration }" :rules="manufacturerNameRules" label="Business Legal Name" data-test-id="manufacturer-name" @@ -25,58 +27,8 @@ - - - - - - - - - - - - When the exact year of manufacture is unknown, enter an estimated - year and indicate that the year is approximate. - - - + + @@ -140,8 +92,11 @@ import { useStore } from '@/store/store' import { useInputRules, useMhrValidations } from '@/composables/' import { storeToRefs } from 'pinia' import { FormIF } from '@/interfaces' +import ManufacturedYearInput from './ManufacturedYearInput.vue' +import ManufacturedYearSelect from './ManufacturedYearSelect.vue' export default defineComponent({ + components: { ManufacturedYearInput, ManufacturedYearSelect }, props: { validate: { type: Boolean, @@ -153,7 +108,6 @@ export default defineComponent({ const makeModelComboForm = ref(null) as FormIF const nameRef = ref(null) - const yearRef = ref(null) const makeRef = ref(null) const modelRef = ref(null) const { setMhrHomeDescription, setMhrHomeBaseInformation } = useStore() @@ -161,19 +115,15 @@ export default defineComponent({ // Getters getMhrRegistrationValidationModel, getMhrRegistrationManufacturerName, - getMhrRegistrationYearOfManufacture, - getMhrRegistrationIsYearApproximate, getMhrRegistrationHomeMake, + isMhrManufacturerRegistration, getMhrRegistrationHomeModel } = storeToRefs(useStore()) const { customRules, required, - minLength, maxLength, - startsWith, - greaterThan, - isNumber + greaterThan } = useInputRules() const { @@ -183,17 +133,6 @@ export default defineComponent({ setValidation } = useMhrValidations(toRefs(getMhrRegistrationValidationModel.value)) - const manufactureYearRules = computed((): Array => - customRules( - required('Enter a year of manufacture'), - isNumber(), - minLength(4, true), - maxLength(4, true), - startsWith(['19', '20'], 'Year must begin with 19 or 20'), - greaterThan(new Date().getFullYear() + 1, 'Year cannot be more than 1 year in the future') - ) - ) - const combinedMakeModelLengthRule = (localState): Array => { return [ () => (0 || localState.model?.length) + (0 || localState.make?.length) <= 65 || @@ -225,8 +164,6 @@ export default defineComponent({ const localState = reactive({ makeModelValid: false, manufacturerName: getMhrRegistrationManufacturerName.value, - yearOfManufacture: getMhrRegistrationYearOfManufacture.value?.toString(), - circa: getMhrRegistrationIsYearApproximate.value, make: getMhrRegistrationHomeMake.value, model: getMhrRegistrationHomeModel.value }) @@ -235,16 +172,6 @@ export default defineComponent({ setMhrHomeDescription({ key: 'manufacturer', value: val }) }) - watch(() => localState.yearOfManufacture, (val: string) => { - if (parseInt(val)) { - setMhrHomeBaseInformation({ key: 'year', value: parseInt(val) }) - } - }) - - watch(() => localState.circa, (val: boolean) => { - setMhrHomeBaseInformation({ key: 'circa', value: val }) - }) - watch(() => localState.make, (val: string) => { setMhrHomeBaseInformation({ key: 'make', value: val }) }) @@ -264,16 +191,15 @@ export default defineComponent({ return { hasError, nameRef, - yearRef, makeRef, modelRef, makeModelComboForm, - manufactureYearRules, makeRules, modelRules, manufacturerNameRules, maxLength, greaterThan, + isMhrManufacturerRegistration, ...toRefs(localState) } } @@ -281,7 +207,7 @@ export default defineComponent({ diff --git a/ppr-ui/src/components/mhrRegistration/YourHome/index.ts b/ppr-ui/src/components/mhrRegistration/YourHome/index.ts index 01769724b..fe4948198 100644 --- a/ppr-ui/src/components/mhrRegistration/YourHome/index.ts +++ b/ppr-ui/src/components/mhrRegistration/YourHome/index.ts @@ -4,3 +4,5 @@ export { default as HomeSections } from './HomeSections.vue' export { default as ManufacturerMakeModel } from './ManufacturerMakeModel.vue' export { default as RebuiltStatus } from './RebuiltStatus.vue' export { default as OtherInformation } from './OtherInformation.vue' +export { default as ManufacturedYearInput } from './ManufacturedYearInput.vue' +export { default as ManufacturedYearSelect } from './ManufacturedYearSelect.vue' diff --git a/ppr-ui/src/composables/mhrRegistration/useNewMhrRegistration.ts b/ppr-ui/src/composables/mhrRegistration/useNewMhrRegistration.ts index 9a609cb1a..5a4edff9b 100644 --- a/ppr-ui/src/composables/mhrRegistration/useNewMhrRegistration.ts +++ b/ppr-ui/src/composables/mhrRegistration/useNewMhrRegistration.ts @@ -12,8 +12,8 @@ import { MhrDraftIF } from '@/interfaces' import { StaffPaymentIF } from '@bcrs-shared-components/interfaces' -import { APIMhrTypes, HomeTenancyTypes, HomeLocationTypes, MhApiStatusTypes } from '@/enums' -import { createMhrDraft, getMhrDrafts, mhrRegistrationHistory, updateMhrDraft } from '@/utils' +import { APIMhrTypes, HomeTenancyTypes, HomeLocationTypes, MhApiStatusTypes, HomeCertificationOptions } from '@/enums' +import { createMhrDraft, getMhrDrafts, getMhrManufacturerInfo, mhrRegistrationHistory, updateMhrDraft } from '@/utils' import { orderBy } from 'lodash' import { useHomeOwners } from '@/composables' @@ -132,6 +132,14 @@ export const useNewMhrRegistration = () => { } } + const initNewManufacturerMhr = async (): Promise => { + const data = await getMhrManufacturerInfo() + setMhrHomeDescription({ key: 'manufacturer', value: data.description.manufacturer }) + setMhrHomeDescription({ key: 'certificationOption', value: HomeCertificationOptions.CSA }) + setMhrRegistrationSubmittingParty(data.submittingParty) + setMhrRegistrationHomeOwnerGroups(data.ownerGroups) + } + /** * Parse a draft MHR into State. * @param draft The draft filing to parse. @@ -392,6 +400,7 @@ export const useNewMhrRegistration = () => { return { initNewMhr, + initNewManufacturerMhr, initDraftMhr, mhrDraftHandler, resetLocationInfoFields, diff --git a/ppr-ui/src/interfaces/mhr-registration-interfaces/MhrManufacturerInfoIF.ts b/ppr-ui/src/interfaces/mhr-registration-interfaces/MhrManufacturerInfoIF.ts new file mode 100644 index 000000000..acb189064 --- /dev/null +++ b/ppr-ui/src/interfaces/mhr-registration-interfaces/MhrManufacturerInfoIF.ts @@ -0,0 +1,10 @@ +import { MhrRegistrationHomeLocationIF, MhrRegistrationHomeOwnerGroupIF, SubmittingPartyIF } from '@/interfaces' + +export interface MhrManufacturerInfoIF { + description: { + manufacturer: string + } + location: MhrRegistrationHomeLocationIF, + ownerGroups: MhrRegistrationHomeOwnerGroupIF[], + submittingParty: SubmittingPartyIF +} diff --git a/ppr-ui/src/interfaces/mhr-registration-interfaces/index.ts b/ppr-ui/src/interfaces/mhr-registration-interfaces/index.ts index 9df6908d3..526533e98 100644 --- a/ppr-ui/src/interfaces/mhr-registration-interfaces/index.ts +++ b/ppr-ui/src/interfaces/mhr-registration-interfaces/index.ts @@ -13,3 +13,4 @@ export * from './MhrTransferTypeIF' export * from './AttnRefConfigIF' export * from './AdditionalNameConfigIF' export * from './OwnerRoleConfigIF' +export * from './MhrManufacturerInfoIF' diff --git a/ppr-ui/src/resources/mhr-registration/index.ts b/ppr-ui/src/resources/mhr-registration/index.ts new file mode 100644 index 000000000..ef2ec08ea --- /dev/null +++ b/ppr-ui/src/resources/mhr-registration/index.ts @@ -0,0 +1 @@ +export * from './your-home-text' diff --git a/ppr-ui/src/resources/mhr-registration/your-home-text.ts b/ppr-ui/src/resources/mhr-registration/your-home-text.ts new file mode 100644 index 000000000..14aba13b9 --- /dev/null +++ b/ppr-ui/src/resources/mhr-registration/your-home-text.ts @@ -0,0 +1,11 @@ +export const ManufacturerMakeModelPrompt = { + staff: 'Enter the Year of Manufacture (not the model year), Make, and Model of the home.', + manufacturer: 'Enter the Year of Manufacture (not the model year), Make, and Model of the home. ' + + 'Your Manufacturer’s Name is based on your manufacturer information and cannot be changed here. ' + + 'If you wish to update this information please contact BC Registries.' +} + +export const HomeCertificationPrompt = { + staff: "Enter either the Canadian Standards Association (CSA) number OR the Engineer's inspection information.", + manufacturer: 'Enter the Canadian Standards Association (CSA) number.' +} diff --git a/ppr-ui/src/utils/mhr-api-helper.ts b/ppr-ui/src/utils/mhr-api-helper.ts index bcfdcc18c..1b5c9479b 100644 --- a/ppr-ui/src/utils/mhr-api-helper.ts +++ b/ppr-ui/src/utils/mhr-api-helper.ts @@ -11,7 +11,8 @@ import { ErrorIF, MhrDraftApiIF, RegistrationSortIF, - MhrDraftIF + MhrDraftIF, + MhrManufacturerInfoIF } from '@/interfaces' import { APIMhrTypes, ErrorCategories, ErrorCodes } from '@/enums' import { useSearch } from '@/composables/useSearch' @@ -674,3 +675,16 @@ function addSortParams (url: string, sortOptions: RegistrationSortIF): string { } return url } + +// Get the manufacturer information for a manufacturer MHR +export async function getMhrManufacturerInfo (): Promise { + return axios + .get('manufacturers', getDefaultConfig()) + .then(response => { + const data: MhrManufacturerInfoIF = response?.data + if (!data) { + throw new Error('Invalid API response') + } + return data + }) +} diff --git a/ppr-ui/src/views/newMhrRegistration/HomeOwners.vue b/ppr-ui/src/views/newMhrRegistration/HomeOwners.vue index 30c73ffd1..d59c4a8d3 100644 --- a/ppr-ui/src/views/newMhrRegistration/HomeOwners.vue +++ b/ppr-ui/src/views/newMhrRegistration/HomeOwners.vue @@ -21,7 +21,11 @@ owners.

- +

Help with Owners

Sole Owner

diff --git a/ppr-ui/src/views/newMhrRegistration/YourHome.vue b/ppr-ui/src/views/newMhrRegistration/YourHome.vue index 317624180..58d09af36 100644 --- a/ppr-ui/src/views/newMhrRegistration/YourHome.vue +++ b/ppr-ui/src/views/newMhrRegistration/YourHome.vue @@ -2,11 +2,30 @@

Manufacturer, Make, and Model

-

- Enter the Year of Manufacture (not the model year), Make, and Model of - the home. +

+ {{ manufacturerMakeModelPrompt }}

+ +

+ Contact BC Registries +

+
+ +
+

Hours of Operation:

+

Monday to Friday, 8:30 am - 4:30 pm Pacific time

+
+
+
+

Home Certification

-

- Enter either the Canadian Standards Association (CSA) number OR the Engineer's inspection information. -

+

{{ homeCertificationPrompt }}

-
+

Rebuilt Status

If the home was rebuilt, include the description of the changes to the home (normally accompanied by a statutory @@ -49,7 +66,7 @@ />

-
+

Other Information

Include any other relevant information about the home. @@ -74,8 +91,11 @@ import { RebuiltStatus, OtherInformation } from '@/components/mhrRegistration/YourHome' +import { SimpleHelpToggle } from '@/components/common' +import { DialogContent } from '@/components/dialogs/common' import { useMhrValidations } from '@/composables/mhrRegistration/useMhrValidations' import { storeToRefs } from 'pinia' +import { ManufacturerMakeModelPrompt, HomeCertificationPrompt } from '@/resources/mhr-registration' export default defineComponent({ name: 'YourHome', @@ -84,12 +104,16 @@ export default defineComponent({ HomeSections, ManufacturerMakeModel, RebuiltStatus, - OtherInformation + OtherInformation, + SimpleHelpToggle, + DialogContent }, props: {}, setup () { const { - getMhrRegistrationValidationModel + getMhrRegistrationValidationModel, + isMhrManufacturerRegistration, + isRoleManufacturer } = storeToRefs(useStore()) const { @@ -114,6 +138,19 @@ export default defineComponent({ }), validateOther: computed(() => { return getSectionValidation(MhrSectVal.YOUR_HOME_VALID, MhrCompVal.OTHER_VALID) + }), + showHelp: computed(() => isMhrManufacturerRegistration.value), + showRebuiltStatus: computed(() => !isMhrManufacturerRegistration.value), + showOtherInformation: computed(() => !isMhrManufacturerRegistration.value), + manufacturerMakeModelPrompt: computed(() : string => { + return isRoleManufacturer.value + ? ManufacturerMakeModelPrompt.manufacturer + : ManufacturerMakeModelPrompt.staff + }), + homeCertificationPrompt: computed(() : string => { + return isRoleManufacturer.value + ? HomeCertificationPrompt.manufacturer + : HomeCertificationPrompt.staff }) }) diff --git a/ppr-ui/tests/unit/HomeCertification.spec.ts b/ppr-ui/tests/unit/HomeCertification.spec.ts index 68eb2853c..71a137ff0 100644 --- a/ppr-ui/tests/unit/HomeCertification.spec.ts +++ b/ppr-ui/tests/unit/HomeCertification.spec.ts @@ -9,6 +9,9 @@ import { mount, createLocalVue, Wrapper } from '@vue/test-utils' import { HomeCertification } from '@/components/mhrRegistration' import { SharedDatePicker } from '@/components/common' import flushPromises from 'flush-promises' +import { MhrRegistrationType } from '@/resources' +import { mockedManufacturerAuthRoles } from './test-data' +import { HomeCertificationOptions } from '@/enums' Vue.use(Vuetify) @@ -34,7 +37,7 @@ function createComponent (): Wrapper { }) } -describe('Home Certification', () => { +describe('Home Certification - staff', () => { let wrapper: Wrapper beforeEach(async () => { @@ -140,3 +143,40 @@ describe('Home Certification', () => { expect(wrapper.findComponent(SharedDatePicker).exists()).toBe(true) }) }) + +describe('Home Certification - manufacturer', () => { + let wrapper: Wrapper + + beforeAll(async () => { + await store.setAuthRoles(mockedManufacturerAuthRoles) + await store.setRegistrationType(MhrRegistrationType) + // When a manufacturer registration is inited it sets the certificatonOption to CSA + await store.setMhrHomeDescription({ key: 'certificationOption', value: HomeCertificationOptions.CSA }) + }) + + beforeEach(async () => { + wrapper = createComponent() + await nextTick() + await flushPromises() + }) + afterEach(() => { + wrapper.destroy() + }) + + afterAll(async () => { + await store.setAuthRoles(null) + await store.setRegistrationType(null) + }) + + it('renders base component with correct sub components', async () => { + expect(wrapper.findComponent(HomeCertification).exists()).toBe(true) + expect(wrapper.findComponent(SharedDatePicker).exists()).toBe(false) + + /// Verify Radio group does not exist + expect(wrapper.find('#certification-option-btns').exists()).toBe(false) + + // Verify only csa-form is shown + expect(wrapper.find('#csa-form').isVisible()).toBe(true) + expect(wrapper.find('#engineer-form').exists()).toBe(false) + }) +}) diff --git a/ppr-ui/tests/unit/ManufacturerMakeModel.spec.ts b/ppr-ui/tests/unit/ManufacturerMakeModel.spec.ts index 053ed3fb6..c12c96b92 100644 --- a/ppr-ui/tests/unit/ManufacturerMakeModel.spec.ts +++ b/ppr-ui/tests/unit/ManufacturerMakeModel.spec.ts @@ -5,7 +5,9 @@ import { useStore } from '../../src/store/store' import { mount, createLocalVue, Wrapper } from '@vue/test-utils' import { getTestId } from './utils' -import { ManufacturerMakeModel } from '@/components/mhrRegistration' +import { ManufacturerMakeModel, ManufacturedYearInput, ManufacturedYearSelect } from '@/components/mhrRegistration' +import { MhrRegistrationType } from '@/resources' +import { mockedManufacturerAuthRoles } from './test-data' Vue.use(Vuetify) const vuetify = new Vuetify({}) @@ -31,7 +33,7 @@ function createComponent (): Wrapper { // Error message class selector const ERROR_MSG = '.error--text .v-messages__message' -describe('ManufacturerMakeModel component', () => { +describe('ManufacturerMakeModel component - staff', () => { let wrapper: Wrapper beforeEach(async () => { @@ -43,6 +45,8 @@ describe('ManufacturerMakeModel component', () => { it('renders the component', async () => { expect(wrapper.findComponent(ManufacturerMakeModel).exists()).toBe(true) + expect(wrapper.findComponent(ManufacturedYearInput).exists()).toBe(true) + expect(wrapper.findComponent(ManufacturedYearSelect).exists()).toBe(false) wrapper.find(getTestId('manufacturer-name')).exists() wrapper.find(getTestId('manufacture-year')).exists() @@ -52,6 +56,10 @@ describe('ManufacturerMakeModel component', () => { wrapper.find(getTestId('manufacturer-model')).exists() }) + it('verifes Name of Manufactuer field is not disabled', async () => { + expect(wrapper.find(getTestId('manufacturer-name')).attributes('disabled')).toBe(undefined) + }) + it('show error messages for Name of Manufacturer field', async () => { wrapper.find(getTestId('manufacturer-name')).setValue('x') await nextTick() @@ -130,3 +138,58 @@ describe('ManufacturerMakeModel component', () => { expect(wrapper.findAll(ERROR_MSG).at(1).text()).toContain('cannot exceed 65') }) }) + +describe('ManufacturerMakeModel component - manufacturer', () => { + let wrapper: Wrapper + + beforeAll(async () => { + await store.setAuthRoles(mockedManufacturerAuthRoles) + await store.setRegistrationType(MhrRegistrationType) + }) + + beforeEach(async () => { + wrapper = createComponent() + }) + afterEach(() => { + wrapper.destroy() + }) + + afterAll(async () => { + await store.setAuthRoles(null) + await store.setRegistrationType(null) + }) + + it('renders the component', async () => { + expect(wrapper.findComponent(ManufacturerMakeModel).exists()).toBe(true) + expect(wrapper.findComponent(ManufacturedYearInput).exists()).toBe(false) + expect(wrapper.findComponent(ManufacturedYearSelect).exists()).toBe(true) + + wrapper.find(getTestId('manufacturer-name')).exists() + expect(wrapper.find(getTestId('manufacture-year')).exists()).toBe(false) + expect(wrapper.find(getTestId('manufacture-year-select')).exists()).toBe(true) + expect(wrapper.find(getTestId('circa-year-checkbox')).exists()).toBe(false) + expect(wrapper.find(getTestId('circa-year-tooltip')).exists()).toBe(false) + wrapper.find(getTestId('manufacturer-make')).exists() + wrapper.find(getTestId('manufacturer-model')).exists() + }) + + it('verifes Name of Manufacturer field is disabled', async () => { + expect(wrapper.find(getTestId('manufacturer-name')).attributes('disabled')).toBe('disabled') + }) + + it('show error messages for Manufacturer Make Model inputs', async () => { + wrapper.find(getTestId('manufacturer-make')).setValue('x'.repeat(70)) + wrapper.find(getTestId('manufacturer-model')).setValue('x'.repeat(70)) + await nextTick() + const messages = wrapper.findAll(ERROR_MSG) + expect(messages.length).toBe(2) + }) + + it('checks year of manufacturer select works as expected', async () => { + const yearSelect = wrapper.findComponent(ManufacturedYearSelect) + const select = yearSelect.find('.v-select') + const items = select.props('items') + const currentYear = new Date().getFullYear() + expect(items).toStrictEqual([currentYear + 1, currentYear, currentYear - 1]) + }) +}) diff --git a/ppr-ui/tests/unit/SimpleHelpToggle.spec.ts b/ppr-ui/tests/unit/SimpleHelpToggle.spec.ts new file mode 100644 index 000000000..14d7d0d18 --- /dev/null +++ b/ppr-ui/tests/unit/SimpleHelpToggle.spec.ts @@ -0,0 +1,55 @@ +// Libraries +import Vue from 'vue' +import Vuetify from 'vuetify' +import { createLocalVue, mount, Wrapper } from '@vue/test-utils' + +// Components +import { SimpleHelpToggle } from '@/components/common' + +// Utilities +import { getTestId } from './utils' + +Vue.use(Vuetify) +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 (propsData: any): Wrapper { + const localVue = createLocalVue() + localVue.use(Vuetify) + + return mount((SimpleHelpToggle as any), { + localVue, + propsData, + vuetify + }) +} + +describe('SimpleHelpToggle', () => { + it('renders the component properly', () => { + const wrapper: Wrapper = createComponent({ toggleButtonTitle: 'test' }) + expect(wrapper.findComponent(SimpleHelpToggle).exists()).toBe(true) + const toggleButton = wrapper.find(getTestId('help-toggle-btn')) + expect(toggleButton.text()).toBe('test') + expect(toggleButton.text().includes('Hide')).toBe(false) + }) + + it('has the proper hide text - default hide text', async () => { + const wrapper: Wrapper = createComponent({ toggleButtonTitle: 'test' }) + const toggleButton = wrapper.find(getTestId('help-toggle-btn')) + await toggleButton.trigger('click') + expect(toggleButton.text()).not.toBe('test') + expect(toggleButton.text()).toBe('Hide Help') + }) + + it('has the proper hide text - none default hide text', async () => { + const wrapper: Wrapper = createComponent({ toggleButtonTitle: 'test', defaultHideText: false }) + const toggleButton = wrapper.find(getTestId('help-toggle-btn')) + await toggleButton.trigger('click') + expect(toggleButton.text()).not.toBe('test') + expect(toggleButton.text()).toBe('Hide test') + }) +}) diff --git a/ppr-ui/tests/unit/YourHome.spec.ts b/ppr-ui/tests/unit/YourHome.spec.ts index 307d730d5..4ed9a90cf 100644 --- a/ppr-ui/tests/unit/YourHome.spec.ts +++ b/ppr-ui/tests/unit/YourHome.spec.ts @@ -19,6 +19,10 @@ import { MhrRegistrationType } from '@/resources' import { defaultFlagSet } from '@/utils' import mockRouter from './MockRouter' import { RouteNames } from '@/enums' +import { getTestId } from './utils' +import { mockedManufacturerAuthRoles } from './test-data' +import { HomeCertificationPrompt, ManufacturerMakeModelPrompt } from '@/resources/mhr-registration' +import { SimpleHelpToggle } from '@/components/common' Vue.use(Vuetify) @@ -52,7 +56,7 @@ function createComponent (): Wrapper { }) } -describe('Your Home', () => { +describe('Your Home - Staff', () => { let wrapper: Wrapper beforeEach(async () => { @@ -73,10 +77,13 @@ describe('Your Home', () => { it('renders and displays the correct headers and sub components', async () => { expect(wrapper.find('#mhr-make-model h2').text()).toBe('Manufacturer, Make, and Model') + expect(wrapper.find(getTestId('make-model-prompt')).text()).toBe(ManufacturerMakeModelPrompt.staff) expect(wrapper.findComponent(ManufacturerMakeModel).exists()).toBe(true) + expect(wrapper.findComponent(SimpleHelpToggle).exists()).toBe(false) expect(wrapper.find('#mhr-home-sections h2').text()).toBe('Home Sections') expect(wrapper.findComponent(HomeSections).exists()).toBe(true) expect(wrapper.find('#mhr-home-certification h2').text()).toBe('Home Certification') + expect(wrapper.find(getTestId('home-certification-prompt')).text()).toBe(HomeCertificationPrompt.staff) expect(wrapper.findComponent(HomeCertification).exists()).toBe(true) expect(wrapper.find('#mhr-rebuilt-status h2').text()).toBe('Rebuilt Status') expect(wrapper.findComponent(RebuiltStatus).exists()).toBe(true) @@ -84,3 +91,45 @@ describe('Your Home', () => { expect(wrapper.findComponent(OtherInformation).exists()).toBe(true) }) }) + +describe('Your Home - Manufacturer', () => { + let wrapper: Wrapper + + beforeAll(async () => { + defaultFlagSet['mhr-registration-enabled'] = true + await store.setAuthRoles(mockedManufacturerAuthRoles) + await store.setRegistrationType(MhrRegistrationType) + }) + + beforeEach(async () => { + wrapper = createComponent() + }) + + afterEach(() => { + wrapper.destroy() + }) + + afterAll(async () => { + defaultFlagSet['mhr-registration-enabled'] = false + await store.setAuthRoles(null) + await store.setRegistrationType(null) + }) + + it('renders and displays Your Home View', async () => { + expect(wrapper.findComponent(YourHome).exists()).toBe(true) + }) + + it('renders and displays the correct headers and sub components', async () => { + expect(wrapper.find('#mhr-make-model h2').text()).toBe('Manufacturer, Make, and Model') + expect(wrapper.find(getTestId('make-model-prompt')).text()).toBe(ManufacturerMakeModelPrompt.manufacturer) + expect(wrapper.findComponent(ManufacturerMakeModel).exists()).toBe(true) + expect(wrapper.findComponent(SimpleHelpToggle).exists()).toBe(true) + expect(wrapper.find('#mhr-home-sections h2').text()).toBe('Home Sections') + expect(wrapper.findComponent(HomeSections).exists()).toBe(true) + expect(wrapper.find('#mhr-home-certification h2').text()).toBe('Home Certification') + expect(wrapper.find(getTestId('home-certification-prompt')).text()).toBe(HomeCertificationPrompt.manufacturer) + expect(wrapper.findComponent(HomeCertification).exists()).toBe(true) + expect(wrapper.findComponent(RebuiltStatus).exists()).toBe(false) + expect(wrapper.findComponent(OtherInformation).exists()).toBe(false) + }) +})