Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17178 - Alteration - Feature flag - Change Business Types #520

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-edit-ui",
"version": "4.5.2",
"version": "4.5.3",
"private": true,
"appName": "Edit UI",
"sbcName": "SBC Common Components",
Expand Down
19 changes: 16 additions & 3 deletions src/components/common/YourCompany/ChangeBusinessType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
<span>Undo</span>
</v-btn>
<v-btn
v-else-if="isBcCompany || isBcUlcCompany || isBenefitCompany"
v-else-if="enableEditButton"
id="btn-correct-business-type"
text
color="primary"
Expand Down Expand Up @@ -247,7 +247,7 @@ import { BcRegContacts } from '@/components/common/'
import { CommonMixin } from '@/mixins/'
import { CorpTypeCd, GetCorpFullDescription } from '@bcrs-shared-components/corp-type-module/'
import { ActionBindingIF, EntitySnapshotIF, EntityTypeOption, ResourceIF } from '@/interfaces/'
import { ResourceUtilities } from '@/utils'
import { GetFeatureFlag, ResourceUtilities } from '@/utils'
import { useStore } from '@/store/store'

@Component({
Expand Down Expand Up @@ -287,10 +287,12 @@ export default class ChangeBusinessType extends Mixins(CommonMixin) {
confirmArticles = false
isEditingType = false
dropdown: boolean = null
supportedEntityTypes: Array<string> = []

/** Called when component is mounted. */
mounted (): void {
this.initializeEntityType()
this.supportedEntityTypes = GetFeatureFlag('supported-alteration-change-business-types')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still fall back to [] in case LD returns null/undefined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahah I had a feeling - ok adding it to the list. We're going to have to make some more changes for the payment codes I believe

Copy link
Collaborator

@severinbeauvais severinbeauvais Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the conditional chaining on line 325 that you don't need if this variable is always an array (not falsy).

My guideline: don't use conditional chaining any more than you have to since it can hide errors (something that you'd want to catch during development or testing).

}

/** Define the entity type locally once the value has been populated in the store. */
Expand Down Expand Up @@ -318,7 +320,18 @@ export default class ChangeBusinessType extends Mixins(CommonMixin) {

/** Entity type options based on the company type */
get entityTypeOptions (): EntityTypeOption[] {
return this.getResource.changeData?.entityTypeOptions || []
const entityTypeOptions = this.getResource.changeData?.entityTypeOptions || []
return entityTypeOptions.filter((option: EntityTypeOption) => {
return this.supportedEntityTypes?.includes(option.value)
})
}

get enableEditButton (): boolean {
// Exclude CCC - Originally: isBcCompany || isBcUlcCompany || isBenefitCompany
if (this.getEntitySnapshot?.businessInfo?.legalType === CorpTypeCd.BC_CCC) {
return false
}
return this.supportedEntityTypes?.includes(this.getEntitySnapshot?.businessInfo?.legalType)
}

get minimumThreeDirectorError (): boolean {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/feature-flag-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ declare const window: any
* Default flag values when LD is not available.
* Uses "business-edit" project (per LD client id in config).
*/
const defaultFlagSet: LDFlagSet = {
export const defaultFlagSet: LDFlagSet = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exported this, so I could use it in the setup

'alteration-ui-enabled': false,
'banner-text': '', // by default, there is no banner text
'change-ui-enabled': false,
'conversion-ui-enabled': false,
'restoration-ui-enabled': false,
'sentry-enable': false, // by default, no sentry logs
'supported-correction-entities': []
'supported-correction-entities': [],
'supported-alteration-change-business-types': []
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/ChangeBusinessType.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Vue from 'vue'
import Vuetify from 'vuetify'
import { mount } from '@vue/test-utils'
import ChangeBusinessType from '@/components/common/YourCompany/ChangeBusinessType.vue'
Expand Down Expand Up @@ -81,14 +82,16 @@ describe('Change Business Type component', () => {
wrapper.destroy()
})

it('should have correct button and no tooltip for BC Alteration filing', () => {
it('should have correct button and no tooltip for BC Alteration filing', async () => {
store.stateModel.tombstone.entityType = CorpTypeCd.BC_COMPANY
store.stateModel.tombstone.filingType = FilingTypes.ALTERATION
store.stateModel.entitySnapshot = { businessInfo: { legalType: 'BC' } } as any
store.resourceModel.changeData = { typeChangeInfo: null } as any

const wrapper = mount(ChangeBusinessType, { vuetify })

await Vue.nextTick()

expect(wrapper.find('.v-tooltip').exists()).toBe(false)
expect(wrapper.find('#btn-correct-business-type').exists()).toBe(true)

Expand Down
13 changes: 12 additions & 1 deletion tests/unit/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* This file is to provide the correct setup for the Vue instance.
/* This file is to provide the correct setup for the Vue instance. Also for system wide mocks.
* It can save people time when writing tests, as they wont need to figure out
* why some of the errors are showing up due to Vue not having the plugins it needs.
* See src/main.ts.
Expand All @@ -10,6 +10,7 @@ import Affix from 'vue-affix'
import Vue2Filters from 'vue2-filters' // needed by SbcFeeSummary
import Vuetify from 'vuetify'
import { TiptapVuetifyPlugin } from 'tiptap-vuetify'
import * as util from '@/utils/'

Vue.use(Vuetify)
Vue.use(Affix)
Expand All @@ -28,3 +29,13 @@ Vue.use(TiptapVuetifyPlugin, {
// optional, default to 'md' (default vuetify icons before v2.0.0)
iconsGroup: 'mdi'
})

// Mock feature flags for unit tests.
jest.spyOn(util, 'GetFeatureFlag').mockImplementation(
(name) => {
if (name === 'supported-alteration-change-business-types') {
Copy link
Collaborator Author

@seeker25 seeker25 Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is too global, let me know, I can call a function instead in the 2-3 sections that need it

I will create another PR and clean it up if needed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too global -- other features may want different feature flags.

Nice code, though :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding it to the list for next PR

return ['BEN', 'BC', 'CC', 'ULC']
} else {
return util.defaultFlagSet[name]
}
})