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

AGM Location Change Third PR #555

Merged
merged 7 commits into from
Oct 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 src/views/AgmLocationChg.vue
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@
sm="8"
>
<p>
Enter the AGM location not in B.C. Include the city, province or state equivalent, and country.
E.g. "Red Deer, Alberta, Canada"
Enter the AGM location not in B.C. Include the city, province or state equivalent,
and country. E.g. "Red Deer, Alberta, Canada"
</p>
<AgmLocation
v-model="agmLocation"
Expand Down
99 changes: 99 additions & 0 deletions tests/unit/AgmLocation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import Vue from 'vue'
import Vuetify from 'vuetify'
import { mount } from '@vue/test-utils'
import AgmLocation from '@/components/AgmLocationChange/AgmLocation.vue'

Vue.use(Vuetify)
const vuetify = new Vuetify({})

// Prevent the warning "[Vuetify] Unable to locate target [data-app]"
document.body.setAttribute('data-app', 'true')

describe('AgmLocation', () => {
/** Array of validations rules for AGM location to be passed as a prop. */
const rules = [] as Array<(val) => boolean | string>
rules.push(val => !!val || 'AGM location is required.')
rules.push(val => (val.length <= 100) || 'Must be 100 characters or less.')

it('initializes correctly', () => {
const wrapper = mount(AgmLocation,
{
vuetify,
propsData: {
rules: rules
}
})
const vm: any = wrapper.vm

expect(vm.agmLocation).toBe('')
expect(wrapper.emitted('update:agmLocation')).toBeUndefined()
expect(wrapper.emitted('valid').pop()[0]).toBe(false)
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
wrapper.destroy()
})

it('emit correct validation when initial location value is passed', async () => {
const wrapper = mount(AgmLocation,
{
vuetify,
propsData: {
rules: rules,
locationValue: 'Toronto, Ontario, Canada'
}
})

expect(wrapper.emitted('valid').pop()[0]).toBe(true)
wrapper.destroy()
})

it('emit correct events when a valid agm location is the input', async () => {
const wrapper = mount(AgmLocation,
{
vuetify,
propsData: {
rules: rules
}
})

const input = wrapper.find('#agm-location')
await input.setValue('Toronto, Ontario, Canada')

expect(wrapper.emitted('update:agmLocation').pop()[0]).toBe('Toronto, Ontario, Canada')
expect(wrapper.emitted('valid').pop()[0]).toBe(true)
wrapper.destroy()
})

it('emit correct events when an invalid agm location (empty string) is the input', async () => {
const wrapper = mount(AgmLocation,
{
vuetify,
propsData: {
rules: rules
}
})

const input = wrapper.find('#agm-location')
await input.setValue('')

expect(wrapper.emitted('update:agmLocation').pop()[0]).toBe('')
expect(wrapper.emitted('valid').pop()[0]).toBe(false)
wrapper.destroy()
})

it('emit correct events when an invalid agm location (over 100 chars) is the input', async () => {
const wrapper = mount(AgmLocation,
{
vuetify,
propsData: {
rules: rules
}
})

const input = wrapper.find('#agm-location')
const a101 = 'a'.repeat(101)
await input.setValue(a101)
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved

expect(wrapper.emitted('update:agmLocation').pop()[0]).toBe(a101)
expect(wrapper.emitted('valid').pop()[0]).toBe(false)
wrapper.destroy()
})
})
11 changes: 2 additions & 9 deletions tests/unit/AgmLocationChg.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,8 @@ describe('AGM Location Chg view', () => {
filing: {
agmLocationChange: {
year: '2023',
newAgmLocation: {
streetAddress: 'Peter Griffin delivery street address',
streetAddressAdditional: null,
addressCity: 'deliv address city',
addressCountry: 'deliv country',
postalCode: 'H0H0H0',
addressRegion: 'MB',
deliveryInstructions: 'Test notes'
}
agmLocation: 'Toronto, Ontario, Canada',
reason: 'Test Reason'
},
business: {
foundingDate: '2007-04-08T00:00:00+00:00',
Expand Down
132 changes: 132 additions & 0 deletions tests/unit/AgmYear.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import Vue from 'vue'
import Vuetify from 'vuetify'
import { mount } from '@vue/test-utils'
import AgmYear from '@/components/AgmLocationChange/AgmYear.vue'
import { sleep } from '@/utils/sleep'

Vue.use(Vuetify)
const vuetify = new Vuetify({})

// Prevent the warning "[Vuetify] Unable to locate target [data-app]"
document.body.setAttribute('data-app', 'true')

describe('AgmYear', () => {
/** Array of validations rules for AGM Year with min and max AGM year. */
const today = new Date()
const minAgmYear = today.getFullYear() - 2
const maxAgmYear = today.getFullYear() + 1
const rules = [] as Array<(val) => boolean | string>
rules.push(val => !!val || 'AGM year is required.')
rules.push(val => (val && +val <= maxAgmYear) || 'Must be on or before ' + maxAgmYear)
rules.push(val => (val && +val >= minAgmYear) || 'Must be on or after ' + minAgmYear)

it('initializes correctly', () => {
const wrapper = mount(AgmYear,
{
vuetify,
propsData: {
rules: rules
}
})
const vm: any = wrapper.vm

expect(vm.agmYear).toBe('')
expect(wrapper.emitted('input')).toBeUndefined()
expect(wrapper.emitted('valid').pop()[0]).toBe(false)
wrapper.destroy()
})

it('emit correct validation when valid agm year is passed', async () => {
const wrapper = mount(AgmYear,
{
vuetify,
propsData: {
rules: rules,
value: today.getFullYear()
}
})

expect(wrapper.emitted('valid').pop()[0]).toBe(true)
wrapper.destroy()
})

it('emit correct events when a valid agm year is the input', async () => {
const wrapper = mount(AgmYear,
{
vuetify,
propsData: {
rules: rules
}
})

const vm: any = wrapper.vm
vm.onValueChanged(today.getFullYear())
const input = wrapper.find('#year-txt')
await input.setValue(today.getFullYear())
await sleep(300) // need to wait for debounce

expect(wrapper.emitted('input').pop()[0]).toBe(today.getFullYear().toString())
expect(wrapper.emitted('valid').pop()[0]).toBe(true)
wrapper.destroy()
})

it('emit correct events when an invalid agm year (empty string) is the input', async () => {
const wrapper = mount(AgmYear,
{
vuetify,
propsData: {
rules: rules
}
})

const vm: any = wrapper.vm
vm.onValueChanged('')
const input = wrapper.find('#year-txt')
await input.setValue('')
await sleep(300) // need to wait for debounce

expect(wrapper.emitted('input').pop()[0]).toBe('')
expect(wrapper.emitted('valid').pop()[0]).toBe(false)
wrapper.destroy()
})

it('emit correct events when an invalid agm year (less than min) is the input', async () => {
const wrapper = mount(AgmYear,
{
vuetify,
propsData: {
rules: rules
}
})

const vm: any = wrapper.vm
vm.onValueChanged(today.getFullYear() - 3)
const input = wrapper.find('#year-txt')
await input.setValue(today.getFullYear() - 3)
await sleep(300) // need to wait for debounce

expect(wrapper.emitted('input').pop()[0]).toBe((today.getFullYear() - 3).toString())
expect(wrapper.emitted('valid').pop()[0]).toBe(false)
wrapper.destroy()
})

it('emit correct events when an invalid agm year (more than max) is the input', async () => {
const wrapper = mount(AgmYear,
{
vuetify,
propsData: {
rules: rules
}
})

const vm: any = wrapper.vm
vm.onValueChanged(today.getFullYear() + 2)
const input = wrapper.find('#year-txt')
await input.setValue(today.getFullYear() + 2)
await sleep(300) // need to wait for debounce

expect(wrapper.emitted('input').pop()[0]).toBe((today.getFullYear() + 2).toString())
expect(wrapper.emitted('valid').pop()[0]).toBe(false)
wrapper.destroy()
})
})
11 changes: 5 additions & 6 deletions tests/unit/EntityMenu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,15 @@ describe('Entity Menu - Consent to Continuation click tests', () => {
})
})

describe.skip('Entity Menu - Request AGM Extension click tests', () => {
describe('Entity Menu - Request AGM Extension click tests', () => {
let vm: any

beforeAll(() => {
// override feature flag
vi.spyOn(utils, 'GetFeatureFlag').mockImplementation(
(flag) => (flag === 'enable-agm-extension'))
vi.spyOn(utils, 'GetFeatureFlag').mockImplementation(flag => {
if (flag === 'enable-agm-extension') return true
if (flag === 'supported-agm-location-chg-entities') return 'BEN'
})
})

afterAll(() => {
Expand All @@ -500,9 +502,6 @@ describe.skip('Entity Menu - Request AGM Extension click tests', () => {
propsData: { businessId: 'BC1234567' }
})

vm = wrapper.vm
vi.spyOn(vm, 'enableAgmExtension', 'get').mockReturnValue(true)

await wrapper.find('.menu-btn').trigger('click')

expect(wrapper.find('#agm-ext-list-item').exists()).toBe(true)
Expand Down
Loading