Skip to content
Snippets Groups Projects
Commit 34f16bc7 authored by jherman5's avatar jherman5
Browse files

Finished the unit tests for the selectors. Checkpoint 6.

parent 5489efdd
No related branches found
No related tags found
No related merge requests found
...@@ -189,3 +189,25 @@ ...@@ -189,3 +189,25 @@
[0902/132649.421:ERROR:crash_report_database_win.cc(469)] failed to stat report [0902/132649.421:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/132649.421:ERROR:crash_report_database_win.cc(469)] failed to stat report [0902/132649.421:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/132649.422:ERROR:crash_report_database_win.cc(469)] failed to stat report [0902/132649.422:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.529:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.537:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.537:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.537:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.537:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.538:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.539:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.539:ERROR:crash_report_database_win.cc(469)] failed to stat report
[0902/193529.539:ERROR:crash_report_database_win.cc(469)] failed to stat report
...@@ -12,47 +12,52 @@ ...@@ -12,47 +12,52 @@
background-color: #f44336; background-color: #f44336;
border: none; border: none;
width: 50%; width: 50%;
height: 20em; height: 15em;
} }
.redlit{ .redlit{
background-color: #f44336; background-color: #f44336;
border: #ffffff; border: #ffffff;
width: 50%; width: 50%;
height: 20em; height: 15em;
} }
.bluebutton{ .bluebutton{
background-color: #008CBA; background-color: #008CBA;
border: none; border: none;
width: 50%; width: 50%;
height: 20em; height: 15em;
} }
.bluelit{ .bluelit{
background-color: #008CBA; background-color: #008CBA;
border: #ffffff; border: #ffffff;
width: 50%; width: 50%;
height: 20em; height: 15em;
} }
.yellowbutton{ .yellowbutton{
background-color: #ffff00; background-color: #ffff00;
border: none; border: none;
width: 50%; width: 50%;
height: 20em; height: 15em;
} }
.yellowlit{ .yellowlit{
background-color: #ffff00; background-color: #ffff00;
border: #ffffff; border: #ffffff;
width: 50%; width: 50%;
height: 20em; height: 15em;
} }
.greenbutton{ .greenbutton{
background-color: #4CAF50; background-color: #4CAF50;
border: none; border: none;
width: 50%; width: 50%;
height: 20em; height: 15em;
} }
.greenlit{ .greenlit{
background-color: #4CAF50; background-color: #4CAF50;
border: #ffffff; border: #ffffff;
width: 50%; width: 50%;
height: 20em; height: 15em;
}
.start{
background-color: #0fc0fc;
width: 100%;
font-size:3em;
} }
\ No newline at end of file
...@@ -17,20 +17,20 @@ export function Pattern() { ...@@ -17,20 +17,20 @@ export function Pattern() {
const score = useSelector(selectScore); const score = useSelector(selectScore);
const patternList = useSelector(selectPatternList); const patternList = useSelector(selectPatternList);
const redclasses = classNames({ const redclasses = classNames({
['redbutton']: borderState === 0, ['redbutton']: !borderState,
['redlit']: borderState === 1, ['redlit']: borderState,
}); });
const blueclasses = classNames({ const blueclasses = classNames({
['bluebutton']: borderState === 0, ['bluebutton']: !borderState,
['bluelit']: borderState ===1, ['bluelit']: borderState,
}); });
const yellowclasses = classNames({ const yellowclasses = classNames({
['yellowbutton']: borderState === 0, ['yellowbutton']: !borderState,
['yellowlit']: borderState ===1, ['yellowlit']: borderState,
}); });
const greenclasses = classNames({ const greenclasses = classNames({
['greenbutton']: borderState === 0, ['greenbutton']: !borderState,
['greenlit']: borderState ===1, ['greenlit']: borderState,
}); });
return ( return (
<main> <main>
...@@ -38,10 +38,10 @@ export function Pattern() { ...@@ -38,10 +38,10 @@ export function Pattern() {
<blockquote class = 'title'> <blockquote class = 'title'>
Simon Says Simon Says
</blockquote> </blockquote>
<blockquote class = 'score'> <blockquote title = 'score' class = 'score'>
Score: {score} Score: {score}
</blockquote> </blockquote>
<button class = {redclasses}> <button title = 'red' class = {redclasses}>
</button> </button>
<button class = {blueclasses}> <button class = {blueclasses}>
</button> </button>
...@@ -49,6 +49,9 @@ export function Pattern() { ...@@ -49,6 +49,9 @@ export function Pattern() {
</button> </button>
<button class = {greenclasses}> <button class = {greenclasses}>
</button> </button>
<button class = 'start'>
Start
</button>
</div> </div>
</main> </main>
); );
......
/* eslint-disable no-magic-numbers */
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import '../../testing/mockRedux.js';
import { Pattern } from './patternGeneration.js';
import {
selectBorderState,
selectPatternList,
selectScore,
} from './patternSlice.js'
jest.mock('./patternSlice.js', () =>({
selectBorderState: jest.fn().mockName('selectBorderState'),
selectPatternList: jest.fn().mockName('selectPatternList'),
selectScore: jest.fn().mockName('selectScore'),
}));
describe('red button', () => {
test('has a white border if borderState is true', () => {
selectBorderState.mockReturnValue(true);
render(<Pattern button={'Foo'}/>);
expect(screen.getByTitle('red')).toHaveClass('redlit');
});
});
describe('the score counter', () => {
test('displays the correct score', () => {
selectScore.mockReturnValue(100);
render(<Pattern></Pattern>);
expect(screen.getByTitle('score')).toHaveTextContent('Score: 100');
});
});
describe('the pattern list', () => {
test('works', () => {
const list = selectPatternList.mockReturnValue([0, 1, 3]);
render(<Pattern></Pattern>);
expect( list === [0,1,3]);
});
});
\ No newline at end of file
...@@ -3,7 +3,7 @@ import { createSlice } from '@reduxjs/toolkit'; ...@@ -3,7 +3,7 @@ import { createSlice } from '@reduxjs/toolkit';
const patternSlice = createSlice({ const patternSlice = createSlice({
name: 'pattern', name: 'pattern',
initialState: { initialState: {
border: 0, borderState: false,
patternList: [], patternList: [],
score: 0, score: 0,
}, },
...@@ -16,7 +16,7 @@ export const { ...@@ -16,7 +16,7 @@ export const {
} = patternSlice.actions; } = patternSlice.actions;
export function selectBorderState(state) { export function selectBorderState(state) {
return state.pattern.border; return state.pattern.borderState;
} }
export function selectPatternList(state) { export function selectPatternList(state) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment