Skip to content

Commit

Permalink
removed some test files into a new branch, added one more progress test
Browse files Browse the repository at this point in the history
  • Loading branch information
Khalid committed Jan 24, 2022
1 parent 261fa97 commit 7662a6f
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 40 deletions.
12 changes: 0 additions & 12 deletions __tests__/components/ComponentFactory.test.tsx

This file was deleted.

82 changes: 78 additions & 4 deletions __tests__/components/ProgressBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,56 @@ 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'

describe('ProgressBar component', () => {
it('renders progress correctly based on questions answered', () => {
const root = RootStore.create({
let root: Instance<typeof RootStore>
beforeEach(() => {
root = RootStore.create({
form: {
fields: [
{
key: 'income',
type: 'currency',
label:
'What is your current annual net income in Canadian Dollars?',
category: { key: 'incomeDetails', text: 'Income Details' },
category: {
key: FieldCategory.INCOME_DETAILS,
text: 'Income Details',
},
order: 1,
placeholder: '$20,000',
default: undefined,
value: null,
options: [],
error: undefined,
},
{
key: 'fakefield',
type: 'currency',
label:
'What is your current annual net income in Canadian Dollars?',
category: {
key: FieldCategory.PERSONAL_INFORMATION,
text: 'Personal Information',
},
order: 1,
placeholder: '$20,000',
default: undefined,
value: null,
options: [],
error: undefined,
},
{
key: 'fakefieldtwo',
type: 'currency',
label:
'What is your current annual net income in Canadian Dollars?',
category: {
key: FieldCategory.LEGAL_STATUS,
text: 'Legal Status',
},
order: 1,
placeholder: '$20,000',
default: undefined,
Expand All @@ -34,7 +72,8 @@ describe('ProgressBar component', () => {
allowance: {},
summary: {},
})

})
it('renders progress for an incomplete form', () => {
root.form.fields[0].setValue('10000') // set income to complete

const ui = (
Expand Down Expand Up @@ -66,4 +105,39 @@ describe('ProgressBar component', () => {
expect(progress[1].classList).toContain('incomplete-progress-section')
expect(progress[2].classList).toContain('incomplete-progress-section')
})

it('renders progress for a complete form', () => {
root.form.fields[0].setValue('10000')
root.form.fields[1].setValue('10000')
root.form.fields[2].setValue('10000')

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>
</StoreProvider>
)
render(ui)

const progress = screen.getAllByTestId('progress')
expect(progress[0].classList).toContain('complete-progress-section')
expect(progress[1].classList).toContain('complete-progress-section')
expect(progress[2].classList).toContain('complete-progress-section')
})
})
10 changes: 0 additions & 10 deletions __tests__/components/ResultsTable.test.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions __tests__/components/Select.test.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions __tests__/hooks/index.test.tsx

This file was deleted.

1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ module.exports = {
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
],
setupFilesAfterEnv: ['<rootDir>/jestSetup.js'],
}
5 changes: 5 additions & 0 deletions jestSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import '@testing-library/jest-dom'
//@ts-ignore
import replaceAllInserter from 'string.prototype.replaceall'

replaceAllInserter.shim()
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"node-mocks-http": "^1.11.0",
"postcss": "^8.4.5",
"prettier": "^2.3.2",
"string.prototype.replaceall": "^1.0.6",
"tailwindcss": "^2.2.9",
"typescript": "^4.5.4"
},
Expand Down
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3521,6 +3521,7 @@ __metadata:
react-dom: 17.0.2
react-number-format: ^4.9.1
react-select: ^5.2.1
string.prototype.replaceall: ^1.0.6
swagger-ui-react: ^4.1.2
tailwindcss: ^2.2.9
ts-node: ^10.4.0
Expand Down Expand Up @@ -8586,6 +8587,20 @@ __metadata:
languageName: node
linkType: hard

"string.prototype.replaceall@npm:^1.0.6":
version: 1.0.6
resolution: "string.prototype.replaceall@npm:1.0.6"
dependencies:
call-bind: ^1.0.2
define-properties: ^1.1.3
es-abstract: ^1.19.1
get-intrinsic: ^1.1.1
has-symbols: ^1.0.2
is-regex: ^1.1.4
checksum: 5020755c7bc8931fc7fb8c73b2f5b3600bbc6ce0fc1df7fef834798f6623e49b57afc2b997e83a69d50686b94b2d47304571435a6adbe59ca53c02a9ceec3422
languageName: node
linkType: hard

"string.prototype.trimend@npm:^1.0.4":
version: 1.0.4
resolution: "string.prototype.trimend@npm:1.0.4"
Expand Down

0 comments on commit 7662a6f

Please sign in to comment.