Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('AnsweredQuestions component', () => {
);
}

it('should render', () => {
test('should render', () => {
const {container} = render(getUi([new AnsweredQuestion(new Question(2, 3), 6)]));
expect(container.querySelector('.answersContainer')).toBeInTheDocument();
expect(container.querySelector('.answersTable')).toBeInTheDocument();
Expand Down
29 changes: 17 additions & 12 deletions src/components/multiplicationGame/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,23 @@ export default function MultiplicationGame() {
const question = questions[currentQuestionIndex!];
return (
<div className={'multiplicationTable'}>
<form onSubmit={handleSumitAnswer}>
<label className={'question'}>{question.factorOne} * {question.factorTwo} = </label>
<input
type='number'
autoComplete={'off'}
id={'answer'}
onChange={handleChange}
value={answer}
autoFocus={true}
required={true}
/>
</form>
<div className={'gameProgress'}>
Pozostało pytań: {questions.length}
</div>
<div className={'questionForm'}>
<form onSubmit={handleSumitAnswer}>
<label className={'question'}>{question.factorOne} * {question.factorTwo} = </label>
<input
type='number'
autoComplete={'off'}
id={'answer'}
onChange={handleChange}
value={answer}
autoFocus={true}
required={true}
/>
</form>
</div>
</div>
);
} else if (context.gameState && context.gameState === GameState.Finished) {
Expand Down
9 changes: 8 additions & 1 deletion src/components/multiplicationGame/multiplicationGame.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
justify-content: center;
align-items: center;
margin-top: 1em;
gap: 2em;
gap: 1em;
flex-flow: column;

.gameProgress {
display: block;
font-size: 2em;
font-weight: bold;
}

.question {
font-size: 2em;
Expand Down
15 changes: 15 additions & 0 deletions src/components/multiplicationGame/multiplicationGame.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,19 @@ describe('MultiplicationGame component', () => {

expect(container.querySelector('input')).not.toBeInTheDocument();
});

test('shows progress', () => {
const container = renderGame(GameState.InProgress, [new Question(2, 3), new Question(3, 3)]);

let progress = container.querySelector('.gameProgress');
expect(progress).toBeInTheDocument();
expect(progress?.textContent).toBe('Pozostało pytań: 2');

const input: HTMLInputElement | null = container.querySelector('input');
fireEvent.change(input!, {target: {value: '6'}});
fireEvent.submit(input!);

progress = container.querySelector('.gameProgress');
expect(progress?.textContent).toBe('Pozostało pytań: 1');
});
});
4 changes: 2 additions & 2 deletions src/providers/answeredQuestion.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {AnsweredQuestion, Question} from './MultiplicationTableStateProvider';

describe('AnsweredQUestion', () => {
it('is correct', () => {
test('is correct', () => {
let answer = new AnsweredQuestion(new Question(2, 3), 6);

expect(answer.isCorrect).toBeTruthy();
});

it('is falsy', () => {
test('is falsy', () => {
let answer = new AnsweredQuestion(new Question(2, 3), 7);

expect(answer.isCorrect).toBeFalsy();
Expand Down
Loading