Skip to content
Snippets Groups Projects
Select Git revision
  • 84accb1803aba24a3a75aebf28550dc95745532b
  • 3.9 default
  • develop
  • 6.0
  • 5.0
  • 4.0
  • scrutinizer-patch-4
  • scrutinizer-patch-3
  • scrutinizer-patch-2
  • scrutinizer-patch-1
  • 3.7
  • 3.8
  • 3.6
  • 3.9_backported
  • 3.8_backported
  • 3.7_backported
  • 3.5
  • 3.6_backported
  • 3.5_backported
  • 3.4
  • 3.3_backported
  • 6.0.4
  • 6.0.3
  • 5.0.7
  • 6.0.2
  • 6.0.1
  • 5.0.6
  • 6.0.0
  • 5.0.5
  • 6.0.0-rc
  • 5.0.4
  • 6.0.0-beta
  • 5.0.3
  • 4.0.6
  • 5.0.2
  • 5.0.1
  • 4.0.5
  • 5.0.0
  • 4.0.4
  • 5.0.0-rc2
  • 5.0.0-rc1
41 results

project.lib.php

Blame
  • numberInputField.test.js 1.74 KiB
    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,
    } 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);
      });
    });
    
    describe('the NumberInputField component', () => {
      test('numberInputField displays apropriate content', () => {
        jest.mock('../unit-selector/unitSelectorSlice.js', () => ({
          selectCurrentInputUnit: jest.fn().mockName('selectCurrentInputUnit'),
        }));
    
        selectCurrentInputUnit.mockReturnValue('cm');
    
        const { container } = render(<NumberInputField/>);
        expect(screen.getByLabelText('inputField')).toHaveAttribute(
          'placeholder', expect.stringContaining('Enter # of "cm"'),
        );
        expect(container).toMatchSnapshot();
      });
    });