-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from amichard/unit-tests
Unit tests
- Loading branch information
Showing
8 changed files
with
7,145 additions
and
4,012 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"presets": ["airbnb"] | ||
"presets": ["airbnb", "env", "react"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
"extends": ["airbnb-standard"], | ||
"plugins": ["jest"], | ||
"rules": { | ||
"jsx-a11y/anchor-is-valid": [ "error", { | ||
"components": [ "Link" ], | ||
"specialLink": [ "to" ] | ||
}], | ||
"no-underscore-dangle": ["error", { | ||
"allowAfterThis": true | ||
}], | ||
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jdx"] }], | ||
"react/no-unused-prop-types": [0], | ||
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}] | ||
}, | ||
"env": { | ||
"jest/globals": true | ||
} | ||
}; |
32 changes: 32 additions & 0 deletions
32
frontend/__tests__/actions/CreditTransfersActions/getCreditTransferType.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { getCreditTransferType } from '../../../src/actions/creditTransfersActions'; | ||
import { CREDIT_TRANSFER_TYPES } from '../../../src/constants/values'; | ||
|
||
test('getCreditTransferType should return a display value for Validation', () => { | ||
const data = getCreditTransferType(CREDIT_TRANSFER_TYPES.validation.id); | ||
|
||
expect('Validation').toEqual(data); | ||
}); | ||
|
||
test('getCreditTransferType should return a display value for Reduction', () => { | ||
const data = getCreditTransferType(CREDIT_TRANSFER_TYPES.retirement.id); | ||
|
||
expect('Reduction').toEqual(data); | ||
}); | ||
|
||
test('getCreditTransferType should return a display value for Part 3 Award', () => { | ||
const data = getCreditTransferType(CREDIT_TRANSFER_TYPES.part3Award.id); | ||
|
||
expect('Part 3 Award').toEqual(data); | ||
}); | ||
|
||
test('getCreditTransferType should return a display value for Sell', () => { | ||
const data = getCreditTransferType(CREDIT_TRANSFER_TYPES.sell.id); | ||
|
||
expect('Credit Transfer').toEqual(data); | ||
}); | ||
|
||
test('getCreditTransferType should return a display value for Buy', () => { | ||
const data = getCreditTransferType(CREDIT_TRANSFER_TYPES.buy.id); | ||
|
||
expect('Credit Transfer').toEqual(data); | ||
}); |
110 changes: 110 additions & 0 deletions
110
frontend/__tests__/actions/CreditTransfersActions/prepareCreditTransfer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { prepareCreditTransfer } from '../../../src/actions/creditTransfersActions'; | ||
import { CREDIT_TRANSFER_STATUS, CREDIT_TRANSFER_TYPES, DEFAULT_ORGANIZATION } from '../../../src/constants/values'; | ||
|
||
test('prepareCreditTransfer should return the right data for Credit Transfers (Sell)', () => { | ||
const data = prepareCreditTransfer({ | ||
creditsFrom: { | ||
id: 2 | ||
}, | ||
creditsTo: { | ||
id: 5 | ||
}, | ||
note: '', | ||
numberOfCredits: 100, | ||
tradeEffectiveDate: '2018-01-01', | ||
transferType: CREDIT_TRANSFER_TYPES.sell.id, | ||
zeroDollarReason: '' | ||
}); | ||
|
||
expect({ | ||
initiator: 2, | ||
note: '', | ||
numberOfCredits: 100, | ||
respondent: 5, | ||
status: CREDIT_TRANSFER_STATUS.approved.id, | ||
tradeEffectiveDate: '2018-01-01', | ||
type: CREDIT_TRANSFER_TYPES.sell.id, | ||
zeroReason: '' | ||
}).toEqual(data); | ||
}); | ||
|
||
test('prepareCreditTransfer should return the right data for Part 3 Award', () => { | ||
const data = prepareCreditTransfer({ | ||
creditsFrom: { | ||
id: 0 | ||
}, | ||
creditsTo: { | ||
id: 5 | ||
}, | ||
note: '', | ||
numberOfCredits: 100, | ||
tradeEffectiveDate: '2018-01-01', | ||
transferType: CREDIT_TRANSFER_TYPES.part3Award.id, | ||
zeroDollarReason: '' | ||
}); | ||
|
||
expect({ | ||
initiator: DEFAULT_ORGANIZATION.id, | ||
note: '', | ||
numberOfCredits: 100, | ||
respondent: 5, | ||
status: CREDIT_TRANSFER_STATUS.approved.id, | ||
tradeEffectiveDate: '2018-01-01', | ||
type: CREDIT_TRANSFER_TYPES.part3Award.id, | ||
zeroReason: '' | ||
}).toEqual(data); | ||
}); | ||
|
||
test('prepareCreditTransfer should return the right data for Validation', () => { | ||
const data = prepareCreditTransfer({ | ||
creditsFrom: { | ||
id: 0 | ||
}, | ||
creditsTo: { | ||
id: 5 | ||
}, | ||
note: '', | ||
numberOfCredits: 100, | ||
tradeEffectiveDate: '2018-01-01', | ||
transferType: CREDIT_TRANSFER_TYPES.validation.id, | ||
zeroDollarReason: '' | ||
}); | ||
|
||
expect({ | ||
initiator: DEFAULT_ORGANIZATION.id, | ||
note: '', | ||
numberOfCredits: 100, | ||
respondent: 5, | ||
status: CREDIT_TRANSFER_STATUS.approved.id, | ||
tradeEffectiveDate: '2018-01-01', | ||
type: CREDIT_TRANSFER_TYPES.validation.id, | ||
zeroReason: '' | ||
}).toEqual(data); | ||
}); | ||
|
||
test('prepareCreditTransfer should return the right data for Reduction', () => { | ||
const data = prepareCreditTransfer({ | ||
creditsFrom: { | ||
id: 5 | ||
}, | ||
creditsTo: { | ||
id: 0 | ||
}, | ||
note: '', | ||
numberOfCredits: 100, | ||
tradeEffectiveDate: '2018-01-01', | ||
transferType: CREDIT_TRANSFER_TYPES.retirement.id, | ||
zeroDollarReason: '' | ||
}); | ||
|
||
expect({ | ||
initiator: 5, | ||
note: '', | ||
numberOfCredits: 100, | ||
respondent: DEFAULT_ORGANIZATION.id, | ||
status: CREDIT_TRANSFER_STATUS.approved.id, | ||
tradeEffectiveDate: '2018-01-01', | ||
type: CREDIT_TRANSFER_TYPES.retirement.id, | ||
zeroReason: '' | ||
}).toEqual(data); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
|
||
import ErrorAlert from '../../../src/app/components/ErrorAlert'; | ||
|
||
test('ErrorAlert should display the title and message as expected', () => { | ||
const component = renderer.create(<ErrorAlert title="Title" message="Message" />); | ||
|
||
const tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); |
12 changes: 12 additions & 0 deletions
12
frontend/__tests__/app/components/__snapshots__/ErrorAlert.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ErrorAlert should display the title and message as expected 1`] = ` | ||
<div> | ||
<h1> | ||
Title | ||
</h1> | ||
<p> | ||
Message | ||
</p> | ||
</div> | ||
`; |
Oops, something went wrong.