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 34e339bc4b02ccaf5d155ab42a30d5229c117e28..0a7ea78e81d1e23dacb9a00882e5bf8ea5c34a30 100644 --- a/unit-conversion/src/features/number-input-field/numberInputField.test.js +++ b/unit-conversion/src/features/number-input-field/numberInputField.test.js @@ -1,68 +1,65 @@ -// 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 { - selectCurrentInputUnit, - selectCurrentOutputUnit, -} from '../unit-selector/unitSelectorSlice.js'; -*/ - -describe('the NumberInputField slice', () => { - test('selects input value according to the store', () => { - const state = { - unitSelector: { - currentInputUnit: 'm', - currentOutputUnit: 'cm', - }, - numberInputField: { - numberToConvert: 10, - }, - }; - - const selectedInputUnit = selectNumberOfUnits(state); - expect(selectedInputUnit).toEqual(10); - }); -}); - -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'), -})); - -jest.mock('../unit-selector/unitSelectorSlice.js', () => ({ - selectCurrentInputUnit: jest.fn().mockName('selectCurrentInputUnit'), - selectCurrentOutputUnit: jest.fn().mockName('selectCurrentOutputUnit'), -})); - -/* -describe('the NumberInputField component', () => { - test('numberInputField displays apropriate content', () => { - selectNumberOfUnits.mockReturnValue(10); - selectCurrentInputUnit.mockReturnValue('cm'); - selectCurrentOutputUnit.mockReturnValue('cm'); - - render(<NumberInputField/>); - expect(screen.getByLabelText('inputField')).toHaveAttribute( - 'placeholder', expect.stringContaining('Enter # of "cm"'), - ); - }); -}); -*/ +import { render, screen } from '@testing-library/react'; +import '../../testing/mockRedux.js'; +import { NumberInputField } from './numberInputField.js'; +import numberInputFieldSlice from '../number-input-field/numberInputFieldSlice.js'; + +import { + selectNumberOfUnits, + setNumberOfUnits, +} from './numberInputFieldSlice.js'; + +import { + selectCurrentInputUnit, + selectCurrentOutputUnit, +} from '../unit-selector/unitSelectorSlice.js'; + +describe('the NumberInputField slice', () => { + test('selects input value according to the store', () => { + const state = { + unitSelector: { + currentInputUnit: 'm', + currentOutputUnit: 'cm', + }, + numberInputField: { + numberToConvert: 10, + }, + }; + + const selectedInputUnit = selectNumberOfUnits(state); + expect(selectedInputUnit).toEqual(10); + }); +}); + +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'), +})); + +jest.mock('../unit-selector/unitSelectorSlice.js', () => ({ + selectCurrentInputUnit: jest.fn().mockName('selectCurrentInputUnit'), + selectCurrentOutputUnit: jest.fn().mockName('selectCurrentOutputUnit'), +})); + +describe('the NumberInputField component', () => { + test('numberInputField displays apropriate content', () => { + selectNumberOfUnits.mockReturnValue(10); + selectCurrentInputUnit.mockReturnValue('cm'); + selectCurrentOutputUnit.mockReturnValue('cm'); + + render(<NumberInputField/>); + expect(screen.getByLabelText('inputField')).toHaveAttribute( + 'placeholder', expect.stringContaining('Enter # of "cm"'), + ); + }); +}); diff --git a/unit-conversion/src/features/unit-selector/unitSelector.test.js b/unit-conversion/src/features/unit-selector/unitSelector.test.js index bf800686cebd16430649bffc318299848c89da06..a1cb13a899c6a8f543f6f237f66b17fda0274d11 100644 --- a/unit-conversion/src/features/unit-selector/unitSelector.test.js +++ b/unit-conversion/src/features/unit-selector/unitSelector.test.js @@ -1,74 +1,72 @@ -// import { render, screen } from '@testing-library/react'; -import '../../testing/mockRedux.js'; -// import { UnitSelector } from './unitSelector.js'; - -/* -import { - selectNumberOfUnits, -} from '../number-input-field/numberInputFieldSlice.js'; -*/ - -import unitSelectorSlice, { - selectCurrentInputUnit, - selectCurrentOutputUnit, - setCurrentInputUnit, - setCurrentOutputUnit, -} from './unitSelectorSlice.js'; - -describe('the UnitSelector slice', () => { - test('selects inputUnit value according to the store', () => { - const state = { - unitSelector: { - currentInputUnit: 'm', - currentOutputUnit: 'cm', - }, - numberInputField: { - numberToConvert: 10, - }, - }; - - const selectedInputUnit = selectCurrentInputUnit(state); - expect(selectedInputUnit).toEqual('m'); - }); -}); - -describe('the UnitSelector slice', () => { - test('selects outputUnit value according to the store', () => { - const state = { - unitSelector: { - currentInputUnit: 'm', - currentOutputUnit: 'cm', - }, - numberInputField: { - numberToConvert: 10, - }, - }; - - const selectedOutputUnit = selectCurrentOutputUnit(state); - 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'); - }); -}); +import { render, screen } from '@testing-library/react'; +import '../../testing/mockRedux.js'; +import { UnitSelector } from './unitSelector.js'; + +import { + selectNumberOfUnits, +} from '../number-input-field/numberInputFieldSlice.js'; + +import unitSelectorSlice, { + selectCurrentInputUnit, + selectCurrentOutputUnit, + setCurrentInputUnit, + setCurrentOutputUnit, +} from './unitSelectorSlice.js'; + +describe('the UnitSelector slice', () => { + test('selects inputUnit value according to the store', () => { + const state = { + unitSelector: { + currentInputUnit: 'm', + currentOutputUnit: 'cm', + }, + numberInputField: { + numberToConvert: 10, + }, + }; + + const selectedInputUnit = selectCurrentInputUnit(state); + expect(selectedInputUnit).toEqual('m'); + }); +}); + +describe('the UnitSelector slice', () => { + test('selects outputUnit value according to the store', () => { + const state = { + unitSelector: { + currentInputUnit: 'm', + currentOutputUnit: 'cm', + }, + numberInputField: { + numberToConvert: 10, + }, + }; + + const selectedOutputUnit = selectCurrentOutputUnit(state); + 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'); + }); +});