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

Added selector tests for all slice selectors.

parent 815fe9aa
No related branches found
No related tags found
No related merge requests found
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`the app runs 1`] = `
<div>
<div>
<h1>
Unit Selector
</h1>
<select
name="units"
>
<option
value="km"
>
km
</option>
<option
value="m"
>
m
</option>
<option
value="ft"
>
ft
</option>
<option
value="in"
>
in
</option>
</select>
</div>
<div>
<h1>
NumberInputField
</h1>
<input
placeholder="Enter # of {unitSelectorUnit}"
required=""
type="text"
/>
</div>
<h1>
Ouput Section
</h1>
<div>
<h1>
Unit Selector
</h1>
<select
name="units"
>
<option
value="km"
>
km
</option>
<option
value="m"
>
m
</option>
<option
value="ft"
>
ft
</option>
<option
value="in"
>
in
</option>
</select>
</div>
<div>
<h1>
Number Output Text
</h1>
</div>
</div>
`;
import { Route } from 'react-router-dom';
// import { Route } from 'react-router-dom';
import { EndingNumberOutput } from './features/ending-number-output/endingNumberOutput.js';
import { NumberInputField } from './features/number-input-field/numberInputField.js';
import { UnitSelector } from './features/unit-selector/unitSelector.js';
import { Card } from './features/card/card.js';
/* What is this used for????
<Route exact path={'/'}>
</Route>
*/
export function App() {
return (
<>
<Route exact path={'/'}>
</Route>
<Card title="Input Unit Selector">
<UnitSelector type="Input"/>
</Card>
......
import { render } from '@testing-library/react';
import './testing/mockRedux.js';
import { MemoryRouter as Router } from 'react-router-dom';
import { App } from './app.js';
describe('the app', () => {
test('runs', () => {
const { container } = render(
<Router initialEntries={['/']}>
<App />
</Router>,
);
expect(container).toMatchSnapshot();
});
});
......@@ -18,3 +18,7 @@ export function NumberInputField() {
</div>
);
}
export const internals = {
NumberInputField,
};
// import { render, screen } from '@testing-library/react';
import '../../testing/mockRedux.js';
// import { NumberInputField, internals } from './numberInputField.js';
import {
selectNumberOfUnits,
} 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);
});
});
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 { UnitSelector } from './unitSelector.js';
/*
import {
selectNumberOfUnits,
} from '../number-input-field/numberInputFieldSlice.js';
*/
import {
selectCurrentInputUnit,
selectCurrentOutputUnit,
} 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');
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment