Skip to content

Commit

Permalink
- app version = 5.6.40
Browse files Browse the repository at this point in the history
- added element ids
- updated LEAR business duplicate check
- added foreign business duplicate check
- misc cleanup
- added test suite (WIP)
  • Loading branch information
Severin Beauvais committed Jan 17, 2024
1 parent 87fc3f9 commit 9b3623f
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 34 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "business-create-ui",
"version": "5.6.38",
"version": "5.6.40",
"private": true,
"appName": "Create UI",
"sbcName": "SBC Common Components",
Expand Down
57 changes: 36 additions & 21 deletions src/components/Amalgamation/AmalgamatingBusinesses.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div id="amalgamating-businesses">
<v-btn
id="btn-add-amalgamating-business"
id="add-amalgamating-business-button"
outlined
color="primary"
class="btn-outlined-primary"
Expand All @@ -14,7 +14,7 @@

<v-btn
v-if="isRoleStaff"
id="btn-add-amalgamating-foreign-business"
id="add-foreign-business-button"
outlined
color="primary"
class="ml-2 btn-outlined-primary"
Expand All @@ -29,6 +29,7 @@
<v-expand-transition>
<v-card
v-if="isAddingAmalgamatingBusiness"
id="add-amalgamating-business-panel"
flat
class="section-container mt-4 pr-0"
>
Expand Down Expand Up @@ -80,6 +81,7 @@
<v-expand-transition>
<v-card
v-if="isAddingAmalgamatingForeignBusiness"
id="add-foreign-business-panel"
flat
class="section-container mt-4"
>
Expand Down Expand Up @@ -133,6 +135,7 @@
class="ms-auto"
>
<v-btn
id="save-foreign-business-button"
large
color="primary"
class="mr-3"
Expand All @@ -141,6 +144,7 @@
<span>Add</span>
</v-btn>
<v-btn
id="cancel-foreign-business-button"
large
outlined
color="primary"
Expand Down Expand Up @@ -213,9 +217,7 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
readonly BusinessLookupServices = BusinessLookupServices
readonly EmptyBusinessLookup = EmptyBusinessLookup
@Getter(useStore) getAmalgamatingBusinessesValid!: boolean
@Getter(useStore) getShowErrors!: boolean
// @Getter(useStore) isAmalgamationFilingHorizontal!: boolean
@Action(useStore) pushAmalgamatingBusiness!: (x: AmalgamatingBusinessIF) => void
@Action(useStore) setAmalgamatingBusinessesValid!: (x: boolean) => void
Expand All @@ -233,7 +235,7 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
isMrasJurisdiction = false
jurisdictionErrorMessage = ''
// Null for no validation, false for invalid, true for valid
isForeignBusinessValid = null
isForeignBusinessValid = null as boolean
// Button properties
isAddingAmalgamatingBusiness = false
Expand Down Expand Up @@ -276,7 +278,7 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
// Show spinner since the network calls below can take a few seconds.
this.$root.$emit('showSpinner', true)
// Special case to handle Extra-pro A companies
// Special case to handle Extra Pro A companies
if ((businessLookup.legalType as any) === CorpTypeCd.EXTRA_PRO_A) {
const region = CanJurisdictions.find(jurisdiction => jurisdiction.value === JurisdictionLocation.BC)
const tingBusiness = {
Expand All @@ -302,8 +304,10 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
}
this.pushAmalgamatingBusiness(tingBusiness)
// Close the "Add an Amalgamating Business" panel.
this.isAddingAmalgamatingBusiness = false
// Hide spinner.
this.$root.$emit('showSpinner', false)
Expand Down Expand Up @@ -355,17 +359,6 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
return
}
// Check for duplicate.
if (this.checkForDuplicateInTable(business)) {
this.snackbarText = 'Business is already in table.'
this.snackbar = true
// Hide spinner.
this.$root.$emit('showSpinner', false)
return
}
// Create amalgamating business object.
const tingBusiness: AmalgamatingBusinessIF = {
type: AmlTypes.LEAR,
Expand All @@ -383,6 +376,17 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
isHistorical: (business.businessInfo.state === EntityStates.HISTORICAL)
}
// Check for duplicate.
if (this.checkForDuplicateInTable(tingBusiness)) {
this.snackbarText = 'Business is already in table.'
this.snackbar = true
// Hide spinner.
this.$root.$emit('showSpinner', false)
return
}
// Add the new business to the amalgamating businesses list.
this.pushAmalgamatingBusiness(tingBusiness)
Expand Down Expand Up @@ -410,6 +414,17 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
corpNumber: this.corpNumber
} as AmalgamatingBusinessIF
// Check for duplicate.
if (this.checkForDuplicateInTable(tingBusiness)) {
this.snackbarText = 'Business is already in table.'
this.snackbar = true
// Hide spinner.
this.$root.$emit('showSpinner', false)
return
}
// Set the amalgamated businesses array in the store.
this.pushAmalgamatingBusiness(tingBusiness)
Expand All @@ -421,9 +436,9 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
* Check if business is already in table.
* @param business The business being added.
*/
checkForDuplicateInTable (business: any): boolean {
const checkDuplication = this.getAmalgamatingBusinesses.find((b: any) =>
(b.type === AmlTypes.LEAR && b.identifier === business.businessInfo?.identifier) ||
private checkForDuplicateInTable (business: any): boolean {
const checkDuplication = this.getAmalgamatingBusinesses.find((b: AmalgamatingBusinessIF) =>
(b.type === AmlTypes.LEAR && b.identifier === business.identifier) ||
(b.type === AmlTypes.FOREIGN && b.corpNumber === business.corpNumber)
)
Expand All @@ -435,7 +450,7 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
}
/** Validate Add Amalgamating Foreign Business. */
validateAddAmalgamatingForeignBusiness (): void {
private validateAddAmalgamatingForeignBusiness (): void {
this.isForeignBusinessValid = (
!!this.jurisdiction &&
!!this.legalName &&
Expand Down
1 change: 0 additions & 1 deletion tests/unit/Actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module'
import { CourtOrderStepIF, DefineCompanyIF, EffectiveDateTimeIF, IncorporationAgreementIF, NameRequestIF,
OrgPersonIF, PeopleAndRoleIF, ShareStructureIF, TombstoneIF } from '@/interfaces'
import { ShareClassIF } from '@bcrs-shared-components/interfaces'
import { vi } from 'vitest'

const vuetify = new Vuetify({})
setActivePinia(createPinia())
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/AddEditOrgPerson.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import AddEditOrgPerson from '@/components/common/AddEditOrgPerson.vue'
import { EmptyOrgPerson } from '@/interfaces'
import { CorpTypeCd } from '@bcrs-shared-components/corp-type-module'

import { vi } from 'vitest'

// mock the console.warn function to hide "[Vuetify] Unable to locate target XXX"
console.warn = vi.fn()

Expand Down
181 changes: 181 additions & 0 deletions tests/unit/AmalgamatingBusinesses.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import Vue from 'vue'
import Vuetify from 'vuetify'
import { createPinia, setActivePinia } from 'pinia'
import { useStore } from '@/store/store'
import { mount } from '@vue/test-utils'
import flushPromises from 'flush-promises'
import LegalServices from '@/services/legal-services'
import AmalgamatingBusinesses from '@/components/Amalgamation/AmalgamatingBusinesses.vue'
import { AmlRoles, AmlTypes } from '@/enums/amalgamationEnums'

const vuetify = new Vuetify({})
setActivePinia(createPinia())
const store = useStore()

// mock services function
// vi.spyOn((LegalServices as any), 'updateFiling').mockImplementation(() => {})

describe('Amalgamating Businesses - add amalgamating business', () => {
let wrapper: any

beforeEach(() => {
// initial state
store.stateModel.tombstone.keycloakRoles = []
store.stateModel.amalgamation.amalgamatingBusinesses = []

wrapper = mount(AmalgamatingBusinesses, { vuetify })
})

afterEach(() => {
wrapper.destroy()
})

it('conditionally renders the amalgamating business panel', async () => {
})

it('saves an amalgamating business', async () => {
})

it('saves an amalgamating business', async () => {
})

it('doesn\'t add a duplicate amalgamating business', async () => {
})
})

describe('Amalgamating Businesses - add amalgamating foreign business', () => {
let wrapper: any

beforeEach(() => {
// initial state
store.stateModel.tombstone.keycloakRoles = ['staff']
store.stateModel.amalgamation.amalgamatingBusinesses = []

wrapper = mount(AmalgamatingBusinesses, { vuetify })
})

afterEach(() => {
wrapper.destroy()
})

it('conditionally renders the foreign business panel', async () => {
// verify panel not yet rendered
expect(wrapper.find('#add-foreign-business-panel').exists()).toBe(false)

// verify Add buttons are enabled
const addAmalgamatingButton = wrapper.find('#add-amalgamating-business-button')
const addForeignButton = wrapper.find('#add-foreign-business-button')
expect(addAmalgamatingButton.classes()).not.toContain('v-btn--disabled')
expect(addForeignButton.classes()).not.toContain('v-btn--disabled')

// verify Add Foreign button and click it
expect(addForeignButton.text()).toBe('Add an Amalgamating Foreign Business')
await addForeignButton.trigger('click')

// verify Add buttons are now disabled
expect(addAmalgamatingButton.classes()).toContain('v-btn--disabled')
expect(addForeignButton.classes()).toContain('v-btn--disabled')

// verify panel is now rendered
expect(wrapper.find('#add-foreign-business-panel').exists()).toBe(true)

// verify Save button
const saveButton = wrapper.find('#save-foreign-business-button')
expect(saveButton.text()).toBe('Add')

// verify Cancel button and click it
const cancelButton = wrapper.find('#cancel-foreign-business-button')
expect(cancelButton.text()).toBe('Cancel')
await cancelButton.trigger('click')

// verify panel is no longer rendered
expect(wrapper.find('#add-foreign-business-panel').exists()).toBe(false)
})

it('saves a foreign business', async () => {
// open panel
await wrapper.setData({
isAddingAmalgamatingForeignBusiness: true
})

// simulate form data
await wrapper.setData({
isCan: true,
jurisdiction: { text: 'BC', value: 'CA' },
legalName: 'Foreign Business',
corpNumber: 'ABC-123'
})

// simulate Save button action
wrapper.vm.saveAmalgamatingForeignBusiness()

// verify validation
expect(wrapper.vm.isForeignBusinessValid).toBe(true)

// verify data
expect(store.stateModel.amalgamation.amalgamatingBusinesses.length).toBe(1)
const business = store.stateModel.amalgamation.amalgamatingBusinesses[0] as any
expect(business.type).toBe(AmlTypes.FOREIGN)
expect(business.role).toBe(AmlRoles.AMALGAMATING)
expect(business.foreignJurisdiction).toEqual({ country: 'CA', region: 'BC' })
expect(business.legalName).toBe('Foreign Business')
expect(business.corpNumber).toBe('ABC-123')

// verify panel is now closed
expect(wrapper.vm.isAddingAmalgamatingForeignBusiness).toBe(false)
})

it('doesn\'t add a duplicate foreign business', async () => {
// pre-populate a foreign business
store.stateModel.amalgamation.amalgamatingBusinesses = [
{
type: AmlTypes.FOREIGN,
role: AmlRoles.AMALGAMATING,
foreignJurisdiction: { country: 'CA', region: 'BC' },
legalName: 'Foreign Business',
corpNumber: 'ABC-123'
}
]
expect(store.stateModel.amalgamation.amalgamatingBusinesses.length).toBe(1)

// open panel
await wrapper.setData({
isAddingAmalgamatingForeignBusiness: true
})

// simulate form data
await wrapper.setData({
isCan: true,
jurisdiction: { text: 'BC', value: 'CA' },
legalName: 'Foreign Business',
corpNumber: 'ABC-123'
})

// verify snackbar is not displayed
expect(wrapper.vm.snackbar).toBe(false)

// simulate Save button action
wrapper.vm.saveAmalgamatingForeignBusiness()

// verify snackbar is displayed
expect(wrapper.vm.snackbar).toBe(true)

// verify data
expect(store.stateModel.amalgamation.amalgamatingBusinesses.length).toBe(1)

// verify panel is still open
expect(wrapper.vm.isAddingAmalgamatingForeignBusiness).toBe(true)
})
})

describe.skip('Amalgamating Businesses - foreign business form', () => {
let wrapper: any

beforeEach(() => {
wrapper = mount(AmalgamatingBusinesses, { vuetify })
})

afterEach(() => {
wrapper.destroy()
})
})
1 change: 0 additions & 1 deletion tests/unit/App.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import EntityInfo from '@/components/common/EntityInfo.vue'
import Stepper from '@/components/common/Stepper.vue'
import { ConfirmDialog } from '@bcrs-shared-components/confirm-dialog'
import mockRouter from './MockRouter'
import { vi } from 'vitest'

// mock fetch() as it is not defined in Jest
// NB: it should be `global.fetch` but that doesn't work and this does
Expand Down
Loading

0 comments on commit 9b3623f

Please sign in to comment.