diff --git a/unit-conversion/src/features/number-input-field/numberInputField.test.js b/unit-conversion/src/features/number-input-field/numberInputField.test.js index 0fb2b776e9fa23d5aea5b760fddbe95dfa942e1e..34e339bc4b02ccaf5d155ab42a30d5229c117e28 100644 --- a/unit-conversion/src/features/number-input-field/numberInputField.test.js +++ b/unit-conversion/src/features/number-input-field/numberInputField.test.js @@ -1,9 +1,11 @@ // import { render, screen } from '@testing-library/react'; import '../../testing/mockRedux.js'; // import { NumberInputField, internals } from './numberInputField.js'; +import numberInputFieldSlice from '../number-input-field/numberInputFieldSlice.js'; import { selectNumberOfUnits, + setNumberOfUnits, } from './numberInputFieldSlice.js'; /* import { @@ -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', () => ({ selectNumberOfUnits: jest.fn().mockName('selectNumberOfUnits'), })); diff --git a/unit-conversion/src/features/unit-selector/unitSelector.test.js b/unit-conversion/src/features/unit-selector/unitSelector.test.js index ce7a513f368530f7f7e9301e76bf7f6cc1f2327a..bf800686cebd16430649bffc318299848c89da06 100644 --- a/unit-conversion/src/features/unit-selector/unitSelector.test.js +++ b/unit-conversion/src/features/unit-selector/unitSelector.test.js @@ -8,9 +8,11 @@ import { } from '../number-input-field/numberInputFieldSlice.js'; */ -import { +import unitSelectorSlice, { selectCurrentInputUnit, selectCurrentOutputUnit, + setCurrentInputUnit, + setCurrentOutputUnit, } from './unitSelectorSlice.js'; describe('the UnitSelector slice', () => { @@ -46,3 +48,27 @@ describe('the UnitSelector slice', () => { 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'); + }); +});