Skip to content

Commit

Permalink
Merge pull request #179 from DTS-STN/develop
Browse files Browse the repository at this point in the history
Release 2022-02-17
  • Loading branch information
JeremyKennedy authored Feb 17, 2022
2 parents d400f1e + 7c47aab commit 3a74079
Show file tree
Hide file tree
Showing 88 changed files with 3,369 additions and 1,872 deletions.
29 changes: 25 additions & 4 deletions __tests__/client-state/mst.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { getSnapshot, Instance } from 'mobx-state-tree'
import { Instance } from 'mobx-state-tree'
import * as nextRouter from 'next/router'
import { Form } from '../../client-state/models/Form'
import { FormField } from '../../client-state/models/FormField'
import { RootStore } from '../../client-state/store'
import {
Language,
LegalStatus,
LivingCountry,
MaritalStatus,
Expand All @@ -11,6 +13,20 @@ import { mockPartialGetRequest } from '../pages/api/factory'

describe('test the mobx state tree nodes', () => {
let root: Instance<typeof RootStore>
let useRouter

beforeAll(() => {
useRouter = jest.spyOn(nextRouter, 'useRouter')
useRouter.mockImplementation(() => ({
route: '/',
pathname: '/',
query: '',
asPath: '',
locale: 'en',
locales: ['en', 'fr'],
}))
})

beforeEach(() => {
root = RootStore.create({
form: {},
Expand All @@ -19,6 +35,7 @@ describe('test the mobx state tree nodes', () => {
afs: {},
allowance: {},
summary: {},
lang: Language.EN,
})
})

Expand Down Expand Up @@ -82,6 +99,10 @@ describe('test the mobx state tree nodes', () => {
it('can clear all values from a form', async () => {
const res = await instantiateFormFields()
const form: Instance<typeof Form> = root.form

const sendReq = jest.spyOn(form, 'sendAPIRequest')
sendReq.mockImplementationOnce(async () => res)

form.setupForm(res.body.fieldData)
expect(form.fields).toHaveLength(6)
form.clearForm()
Expand Down Expand Up @@ -128,9 +149,9 @@ describe('test the mobx state tree nodes', () => {
const form: Instance<typeof Form> = root.form
form.setupForm(res.body.fieldData)
fillOutForm(form)
expect(form.validateAgainstEmptyFields()).toBe(false) // no errors exist
expect(form.validateAgainstEmptyFields('en')).toBe(false) // no errors exist
form.fields[0].setValue(null)
expect(form.validateAgainstEmptyFields()).toBe(true)
expect(form.validateAgainstEmptyFields('en')).toBe(true)
})

it('can report on the forms progress', async () => {
Expand All @@ -151,7 +172,7 @@ describe('test the mobx state tree nodes', () => {
const form: Instance<typeof Form> = root.form
form.setupForm(res.body.fieldData)
let qs = form.buildQueryStringWithFormData()
expect(qs).toBe('livingCountry=CAN') // Canada is selected by default
expect(qs).toBe('_language=EN&livingCountry=CAN') // Canada is selected by default, and locale is EN
fillOutForm(form)
qs = form.buildQueryStringWithFormData()
expect(qs).toContain('income=20000')
Expand Down
44 changes: 27 additions & 17 deletions __tests__/components/CurrencyField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
* @jest-environment jsdom
*/
import '@testing-library/jest-dom'
import { render, screen } from '@testing-library/react'
import * as nextRouter from 'next/router'
import React from 'react'
import { cleanup, render, screen } from '@testing-library/react'
import { LanguageProvider, StoreProvider } from '../../components/Contexts'
import { StoreProvider } from '../../components/Contexts'
import { CurrencyField } from '../../components/Forms/CurrencyField'

describe('CurrencyField component', () => {
let useRouter

beforeAll(() => {
useRouter = jest.spyOn(nextRouter, 'useRouter')
useRouter.mockImplementation(() => ({
route: '/',
pathname: '/',
query: '',
asPath: '',
locale: 'en',
locales: ['en', 'fr'],
}))
})
it('should render an input component that is required component', () => {
const props = {
name: 'income',
Expand All @@ -17,13 +31,11 @@ describe('CurrencyField component', () => {

const ui = (
<StoreProvider>
<LanguageProvider>
<CurrencyField
name={props.name}
label={props.label}
required={props.required}
/>
</LanguageProvider>
<CurrencyField
name={props.name}
label={props.label}
required={props.required}
/>
</StoreProvider>
)

Expand All @@ -50,14 +62,12 @@ describe('CurrencyField component', () => {

const ui = (
<StoreProvider>
<LanguageProvider>
<CurrencyField
name={props.name}
label={props.label}
error={props.error}
required={props.required}
/>
</LanguageProvider>
<CurrencyField
name={props.name}
label={props.label}
error={props.error}
required={props.required}
/>
</StoreProvider>
)

Expand Down
44 changes: 27 additions & 17 deletions __tests__/components/NumberField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
* @jest-environment jsdom
*/
import '@testing-library/jest-dom'
import { render, screen } from '@testing-library/react'
import * as nextRouter from 'next/router'
import React from 'react'
import { cleanup, render, screen } from '@testing-library/react'
import { LanguageProvider, StoreProvider } from '../../components/Contexts'
import { StoreProvider } from '../../components/Contexts'
import { NumberField } from '../../components/Forms/NumberField'

describe('NumberField component', () => {
let useRouter

beforeAll(() => {
useRouter = jest.spyOn(nextRouter, 'useRouter')
useRouter.mockImplementation(() => ({
route: '/',
pathname: '/',
query: '',
asPath: '',
locale: 'en',
locales: ['en', 'fr'],
}))
})
it('should render an input component that is required component', () => {
const props = {
name: 'age',
Expand All @@ -17,13 +31,11 @@ describe('NumberField component', () => {

const ui = (
<StoreProvider>
<LanguageProvider>
<NumberField
name={props.name}
label={props.label}
required={props.required}
/>
</LanguageProvider>
<NumberField
name={props.name}
label={props.label}
required={props.required}
/>
</StoreProvider>
)

Expand All @@ -50,14 +62,12 @@ describe('NumberField component', () => {

const ui = (
<StoreProvider>
<LanguageProvider>
<NumberField
name={props.name}
label={props.label}
error={props.error}
required={props.required}
/>
</LanguageProvider>
<NumberField
name={props.name}
label={props.label}
error={props.error}
required={props.required}
/>
</StoreProvider>
)

Expand Down
94 changes: 53 additions & 41 deletions __tests__/components/ProgressBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,31 @@
* @jest-environment jsdom
*/
import '@testing-library/jest-dom'
import { render, screen } from '@testing-library/react'
import { Instance } from 'mobx-state-tree'
import * as nextRouter from 'next/router'
import React from 'react'
import { cleanup, render, screen } from '@testing-library/react'
import { LanguageProvider, StoreProvider } from '../../components/Contexts'
import ProgressBar from '../../components/ProgressBar'
import { RootStore } from '../../client-state/store'
import { Instance } from 'mobx-state-tree'
import { FieldCategory } from '../../utils/api/definitions/enums'
import { StoreProvider } from '../../components/Contexts'
import ProgressBar from '../../components/ProgressBar'
import { FieldCategory, Language } from '../../utils/api/definitions/enums'

describe('ProgressBar component', () => {
let root: Instance<typeof RootStore>
let useRouter

beforeAll(() => {
useRouter = jest.spyOn(nextRouter, 'useRouter')
useRouter.mockImplementation(() => ({
route: '/',
pathname: '/',
query: '',
asPath: '',
locale: 'en',
locales: ['en', 'fr'],
}))
})

beforeEach(() => {
root = RootStore.create({
form: {
Expand Down Expand Up @@ -71,31 +86,30 @@ describe('ProgressBar component', () => {
afs: {},
allowance: {},
summary: {},
lang: Language.EN,
})
})
it('renders progress for an incomplete form', () => {
root.form.fields[0].setValue('10000') // set income to complete

const ui = (
<StoreProvider>
<LanguageProvider>
<ProgressBar
sections={[
{
title: 'Income Details',
complete: root.form.progress.income,
},
{
title: 'Personal Information',
complete: root.form.progress.personal,
},
{
title: 'Legal Status',
complete: root.form.progress.legal,
},
]}
/>
</LanguageProvider>
<ProgressBar
sections={[
{
title: 'Income Details',
complete: root.form.progress.income,
},
{
title: 'Personal Information',
complete: root.form.progress.personal,
},
{
title: 'Legal Status',
complete: root.form.progress.legal,
},
]}
/>
</StoreProvider>
)
render(ui)
Expand All @@ -113,24 +127,22 @@ describe('ProgressBar component', () => {

const ui = (
<StoreProvider>
<LanguageProvider>
<ProgressBar
sections={[
{
title: 'Income Details',
complete: root.form.progress.income,
},
{
title: 'Personal Information',
complete: root.form.progress.personal,
},
{
title: 'Legal Status',
complete: root.form.progress.legal,
},
]}
/>
</LanguageProvider>
<ProgressBar
sections={[
{
title: 'Income Details',
complete: root.form.progress.income,
},
{
title: 'Personal Information',
complete: root.form.progress.personal,
},
{
title: 'Legal Status',
complete: root.form.progress.legal,
},
]}
/>
</StoreProvider>
)
render(ui)
Expand Down
Loading

1 comment on commit 3a74079

@vercel
Copy link

@vercel vercel bot commented on 3a74079 Feb 17, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.