Skip to content

Commit

Permalink
17765 complete resolution fix (#565)
Browse files Browse the repository at this point in the history
* Fixed complete resolution unit test

* updated package version

* Removed isVitestRunning flag + fixed AccountContactMissingDialog test + moved to jsdom

* Fixed linting + fixed app unit test
  • Loading branch information
JazzarKarim authored Sep 19, 2023
1 parent 8a46cdf commit 52f0287
Show file tree
Hide file tree
Showing 8 changed files with 539 additions and 28 deletions.
531 changes: 525 additions & 6 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "business-create-ui",
"version": "5.4.3",
"version": "5.4.4",
"private": true,
"appName": "Create UI",
"sbcName": "SBC Common Components",
Expand Down Expand Up @@ -84,8 +84,8 @@
"eslint-plugin-vue": "^8.7.1",
"eslint-plugin-vuetify": "^1.1.0",
"flush-promises": "^1.0.2",
"happy-dom": "^10.5.2",
"intersection-observer": "^0.12.2",
"jsdom": "^22.1.0",
"sass": "~1.32.13",
"sinon": "^14.0.2",
"typescript": "^4.5.5",
Expand Down
1 change: 0 additions & 1 deletion src/components/Dissolution/CompleteResolution.vue
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ export default class CompleteResolution extends Mixins(CommonMixin, DateMixin) {
// Note: the image file path did not resolve correctly when using the require function directly. In order
// to get the image path resolving correctly, needed to get the image context first and use that to build
// the final image file path
if (this.isVitestRunning) return ''
const imagePath = this.getCreateResolutionResource.sampleFormSection.previewImagePath
return new URL(`/src/assets/images/${imagePath}`, import.meta.url).href
}
Expand Down
7 changes: 3 additions & 4 deletions src/components/common/Actions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ export default class Actions extends Mixins(CommonMixin, DateMixin, FilingTempla
) {
this.setEffectiveDateTimeValid(false)
// don't call window.scrollTo during Vitest tests because happy-dom doesn't implement it
if (!this.isVitestRunning) window.scrollTo({ top: 1250, behavior: 'smooth' })
window.scrollTo({ top: 1250, behavior: 'smooth' })
this.setIsFilingPaying(false)
return
}
Expand Down Expand Up @@ -286,8 +285,8 @@ export default class Actions extends Mixins(CommonMixin, DateMixin, FilingTempla
this.setIsFilingPaying(false)
}
} else {
// don't call window.scrollTo during Vitest tests because happy-dom doesn't implement it
if (!this.isVitestRunning) window.scrollTo({ top: 0, behavior: 'smooth' })
// don't call window.scrollTo during Vitest tests because jsdom doesn't implement it
window.scrollTo({ top: 0, behavior: 'smooth' })
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/mixins/add-edit-org-person-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,7 @@ export default class AddEditOrgPersonMixin extends Vue {

/** Copy of function in Common mixin (since this mixin cannot extend another mixin). */
private async scrollToTop (element: any): Promise<void> {
const isVitestRunning = (import.meta.env.VITEST !== undefined)
// don't call window.scrollTo during Vitest tests because happy-dom doesn't implement it
if (element && !isVitestRunning) await element.scrollIntoView({ behavior: 'smooth' })
if (element) await element.scrollIntoView({ behavior: 'smooth' })
}

/** Helper to set the current director data. */
Expand Down
3 changes: 1 addition & 2 deletions src/mixins/common-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export default class CommonMixin extends Vue {
* @param element the element to scroll to the top of
*/
async scrollToTop (element: any): Promise<void> {
// don't call window.scrollTo during Vitest tests because happy-dom doesn't implement it
if (element && !this.isVitestRunning) {
if (element) {
await element.scrollIntoView({ behavior: 'smooth' })
}
}
Expand Down
13 changes: 5 additions & 8 deletions tests/unit/AccountContactMissingDialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,16 @@ describe('AccountContactMissingDialog.vue', () => {
propsData: { dialog: true }
})

// Override window.location.href
let redirectedUrl = ''
// eslint-disable-next-line accessor-pairs
Object.defineProperty(window.location, 'href', {
set (url: string) {
redirectedUrl = url
}
// Override window.location
Object.defineProperty(window, 'location', {
value: new URL('https://dev.account.bcregistry.gov.bc.ca'),
configurable: true
})

// Calling the method directly
wrapper.vm.redirectToUserProfile()

// Checking the logic inside the method
expect(redirectedUrl).toBe('https://dev.account.bcregistry.gov.bc.ca/userprofile')
expect(window.location.href).toBe('https://dev.account.bcregistry.gov.bc.ca/userprofile')
})
})
4 changes: 2 additions & 2 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export default defineConfig(() => {
port: 8080
},
test: {
// simulate DOM with happy-dom
environment: 'happy-dom',
// simulate DOM with jsdom
environment: 'jsdom',
// enable jest-like global test APIs
globals: true,
setupFiles: ['./tests/setup.ts'],
Expand Down

0 comments on commit 52f0287

Please sign in to comment.