Skip to content

Commit

Permalink
Merge pull request #255 from amichard/unit-tests
Browse files Browse the repository at this point in the history
Unit tests
  • Loading branch information
kuanfandevops committed May 1, 2018
2 parents 57fb2bc + c36ae2e commit def1128
Show file tree
Hide file tree
Showing 8 changed files with 7,145 additions and 4,012 deletions.
2 changes: 1 addition & 1 deletion frontend/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["airbnb"]
"presets": ["airbnb", "env", "react"]
}
19 changes: 19 additions & 0 deletions frontend/.eslintrc.js
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
}
};
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);
});
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);
});
11 changes: 11 additions & 0 deletions frontend/__tests__/app/components/ErrorAlert.js
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 frontend/__tests__/app/components/__snapshots__/ErrorAlert.js.snap
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>
`;
Loading

0 comments on commit def1128

Please sign in to comment.