Skip to content

Commit

Permalink
19179 Added Amalgamating Businesses unit tests (#626)
Browse files Browse the repository at this point in the history
* - app version = 5.6.40
- added element ids
- updated LEAR business duplicate check
- added foreign business duplicate check
- misc cleanup
- added test suite (WIP)

* wip

---------

Co-authored-by: Severin Beauvais <severin.beauvais@gov.bc.ca>
  • Loading branch information
severinbeauvais and Severin Beauvais authored Jan 17, 2024
1 parent 8a544b0 commit 95276ad
Show file tree
Hide file tree
Showing 13 changed files with 379 additions and 42 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.39",
"version": "5.6.40",
"private": true,
"appName": "Create UI",
"sbcName": "SBC Common Components",
Expand Down
74 changes: 45 additions & 29 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 @@ -110,6 +112,7 @@
offset="3"
>
<v-text-field
id="foreign-business-legal-name"
v-model="legalName"
filled
label="Business' full legal name in home jurisdiction"
Expand All @@ -122,6 +125,7 @@
offset="3"
>
<v-text-field
id="foreign-business-corp-number"
v-model="corpNumber"
filled
label="Corporate number in home jurisdiction"
Expand All @@ -133,6 +137,7 @@
class="ms-auto"
>
<v-btn
id="save-foreign-business-button"
large
color="primary"
class="mr-3"
Expand All @@ -141,6 +146,7 @@
<span>Add</span>
</v-btn>
<v-btn
id="cancel-foreign-business-button"
large
outlined
color="primary"
Expand Down Expand Up @@ -213,9 +219,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,22 +237,21 @@ 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
isAddingAmalgamatingForeignBusiness = false
/** TextField rules for "Add an Amalgamating Foreign Business" Panel. */
get foreignBusinessLegalNameRules (): Array<(v) => boolean | string> {
get foreignBusinessLegalNameRules (): Array<(v: string) => boolean | string> {
return [
v => !!v || 'Full legal name is required',
v => (!v || v.length >= 3) || 'Must be at least 3 characters',
v => (!v || v.length <= 150) || 'Cannot exceed 150 characters'
]
}
get foreignBusinessCorpNumberRules (): Array<(v) => boolean | string> {
get foreignBusinessCorpNumberRules (): Array<(v: string) => boolean | string> {
return [
v => (!this.isMrasJurisdiction || (!!v && /^[0-9a-zA-Z-]+$/.test(v))) ||
'Corporate number is required',
Expand All @@ -260,10 +263,10 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
/** Called when Jurisdiction menu item is changed. */
onJurisdictionChange (jurisdiction: any): void {
this.jurisdiction = jurisdiction
this.isCan = (jurisdiction.group === 0)
this.jurisdictionErrorMessage = this.jurisdiction ? '' : 'Home jurisdiction is required'
this.isCan = (jurisdiction?.group === 0)
this.jurisdictionErrorMessage = jurisdiction ? '' : 'Home jurisdiction is required'
this.isMrasJurisdiction = MrasJurisdictions.includes(
this.jurisdiction.text.toLowerCase()
this.jurisdiction?.text.toLowerCase()
)
// Update validation on jurisdiction change
Expand All @@ -276,7 +279,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 +305,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 +360,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 +377,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,20 +415,31 @@ 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)
// Close the "Add an Amalgamating Foreign Business" Panel.
// Close the "Add an Amalgamating Foreign Business" panel.
this.isAddingAmalgamatingForeignBusiness = false
}
/**
* 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 +451,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 All @@ -456,7 +472,7 @@ export default class AmalgamatingBusinesses extends Mixins(AmalgamationMixin, Co
!this.isAddingAmalgamatingForeignBusiness
)
// Reset "Add an Amalgamating Foreign Business" Panel on change
// Reset "Add an Amalgamating Foreign Business" panel on change
this.isForeignBusinessValid = null
this.jurisdiction = null
this.legalName = null
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
Loading

0 comments on commit 95276ad

Please sign in to comment.