Skip to content
Snippets Groups Projects
Commit 369cb48a authored by Gabriel Clark's avatar Gabriel Clark
Browse files

Added unit tests for all project reducers.

parent 1f56c796
No related branches found
No related tags found
No related merge requests found
// import { render, screen } from '@testing-library/react'; // import { render, screen } from '@testing-library/react';
import '../../testing/mockRedux.js'; import '../../testing/mockRedux.js';
// import { NumberInputField, internals } from './numberInputField.js'; // import { NumberInputField, internals } from './numberInputField.js';
import numberInputFieldSlice from '../number-input-field/numberInputFieldSlice.js';
import { import {
selectNumberOfUnits, selectNumberOfUnits,
setNumberOfUnits,
} from './numberInputFieldSlice.js'; } from './numberInputFieldSlice.js';
/* /*
import { import {
...@@ -29,6 +31,18 @@ describe('the NumberInputField slice', () => { ...@@ -29,6 +31,18 @@ describe('the NumberInputField slice', () => {
}); });
}); });
describe('the NumberInputField slice', () => {
test('setNumberOfUnits correctly adjusts state value', () => {
// This is what the local state looks like to the "setNumberOfUnits" reducer.
const state = numberInputFieldSlice.reducer({
numberToConvert: 10,
}, setNumberOfUnits(100));
const numberOfUnits = 100;
expect(state.numberToConvert).toEqual(numberOfUnits);
});
});
jest.mock('./numberInputField.js', () => ({ jest.mock('./numberInputField.js', () => ({
selectNumberOfUnits: jest.fn().mockName('selectNumberOfUnits'), selectNumberOfUnits: jest.fn().mockName('selectNumberOfUnits'),
})); }));
......
...@@ -8,9 +8,11 @@ import { ...@@ -8,9 +8,11 @@ import {
} from '../number-input-field/numberInputFieldSlice.js'; } from '../number-input-field/numberInputFieldSlice.js';
*/ */
import { import unitSelectorSlice, {
selectCurrentInputUnit, selectCurrentInputUnit,
selectCurrentOutputUnit, selectCurrentOutputUnit,
setCurrentInputUnit,
setCurrentOutputUnit,
} from './unitSelectorSlice.js'; } from './unitSelectorSlice.js';
describe('the UnitSelector slice', () => { describe('the UnitSelector slice', () => {
...@@ -46,3 +48,27 @@ describe('the UnitSelector slice', () => { ...@@ -46,3 +48,27 @@ describe('the UnitSelector slice', () => {
expect(selectedOutputUnit).toEqual('cm'); expect(selectedOutputUnit).toEqual('cm');
}); });
}); });
describe('the UnitSelector slice', () => {
test('setcurrentInputUnit correctly adjusts state value', () => {
// This is what the local state looks like to the "setCurrentInputUnit" reducer.
const state = unitSelectorSlice.reducer({
currentInputUnit: 'm',
currentOutputUnit: 'cm',
}, setCurrentInputUnit('km'));
expect(state.currentInputUnit).toEqual('km');
});
});
describe('the UnitSelector slice', () => {
test('setcurrentOutputUnit correctly adjusts state value', () => {
// This is what the local state looks like to the "setCurrentOutputUnit" reducer.
const state = unitSelectorSlice.reducer({
currentInputUnit: 'm',
currentOutputUnit: 'cm',
}, setCurrentOutputUnit('km'));
expect(state.currentOutputUnit).toEqual('km');
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment