Skip to content

Commit

Permalink
Simplify test data
Browse files Browse the repository at this point in the history
We don't need to create new data objects for test subsets. We can
use the existing testData object and slice it to the required size.
  • Loading branch information
JuliaCasamitjana committed May 13, 2024
1 parent e5fd16e commit 51ab3ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 76 deletions.
23 changes: 11 additions & 12 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { render, screen } from '@testing-library/react';
import userEvent, { UserEvent } from '@testing-library/user-event';
import { within } from '@testing-library/dom';
import App from './App';
import {
testData as data,
testDataWithOneQuestion,
testDataWithTwoQuestion,
} from './static/data';
import { testData as data } from './static/data';
import { translationsProvider } from './util';

const answerQuestionCorrectly = async (user: UserEvent) => {
Expand Down Expand Up @@ -120,7 +116,8 @@ describe('App component', () => {

it('shows the result page after answering all questions', async () => {
const user = userEvent.setup();
render(<App data={testDataWithOneQuestion}></App>, {
const testDataWith1Question = data.slice(0, 1);
render(<App data={testDataWith1Question}></App>, {
wrapper: translationsProvider,
});

Expand Down Expand Up @@ -242,8 +239,8 @@ describe('App component', () => {
describe('multiple attempts feature', () => {
it('shows a wrongly answered question again up to 3 times', async () => {
const user = userEvent.setup();

render(<App data={testDataWithOneQuestion}></App>, {
const testDataWith1Question = data.slice(0, 1);
render(<App data={testDataWith1Question}></App>, {
wrapper: translationsProvider,
});

Expand All @@ -263,7 +260,8 @@ describe('App component', () => {

it('shows the attempts needed for each question', async () => {
const user = userEvent.setup();
render(<App data={testDataWithTwoQuestion}></App>, {
const testDataWith2Questions = data.slice(0, 2);
render(<App data={testDataWith2Questions}></App>, {
wrapper: translationsProvider,
});

Expand Down Expand Up @@ -311,7 +309,8 @@ describe('App component', () => {

it('displays the quiz progress', async () => {
const user = userEvent.setup();
render(<App data={testDataWithTwoQuestion}></App>, {
const testDataWith2Questions = data.slice(0, 2);
render(<App data={testDataWith2Questions}></App>, {
wrapper: translationsProvider,
});

Expand All @@ -334,8 +333,8 @@ describe('App component', () => {

it('displays the remaining attempts after wrongly answering a question', async () => {
const user = userEvent.setup();

render(<App data={testDataWithOneQuestion}></App>, {
const testDataWith1Question = data.slice(0, 1);
render(<App data={testDataWith1Question}></App>, {
wrapper: translationsProvider,
});

Expand Down
71 changes: 7 additions & 64 deletions src/static/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const testData: Data = [
{
id: 'answer_02',
correct: false,
text: 'Answer 2',
text: 'Incorrect Answer',
},
],
},
Expand All @@ -218,7 +218,7 @@ export const testData: Data = [
{
id: 'answer_04',
correct: false,
text: 'Answer 4',
text: 'Incorrect Answer',
},
],
},
Expand All @@ -235,7 +235,7 @@ export const testData: Data = [
{
id: 'answer_06',
correct: false,
text: 'Answer 6',
text: 'Incorrect Answer',
},
{
id: 'answer_07',
Expand All @@ -245,7 +245,7 @@ export const testData: Data = [
{
id: 'answer_08',
correct: false,
text: 'Answer 8',
text: 'Incorrect Answer',
},
],
},
Expand All @@ -257,77 +257,20 @@ export const testData: Data = [
{
id: 'answer_09',
correct: false,
text: 'Answer 9',
text: 'Incorrect Answer',
},
{
id: 'answer_10',
correct: false,
text: 'Answer 10',
},
{
id: 'answer_11',
correct: false,
text: 'Answer 11',
},
{
id: 'answer_12',
correct: false,
text: 'Answer 12',
},
],
},
] as Data;

export const testDataWithOneQuestion: Data = [
{
id: 'id-01',
type: QuestionTypes.SingleChoice,
text: 'Q1: What is the answer?',
answers: [
{
id: 'answer_01',
correct: true,
text: 'Correct Answer',
},
{
id: 'answer_02',
correct: false,
text: 'Incorrect Answer',
},
],
},
] as Data;

export const testDataWithTwoQuestion: Data = [
{
id: 'id-01',
type: QuestionTypes.SingleChoice,
text: 'Q1: What is the answer?',
answers: [
{
id: 'answer_01',
correct: true,
text: 'Correct Answer',
},
{
id: 'answer_02',
id: 'answer_11',
correct: false,
text: 'Incorrect Answer',
},
],
},
{
id: 'id-02',
type: QuestionTypes.SingleChoice,
text: 'Q2: What is the answer?',
answers: [
{
id: 'answer_03',
correct: true,
text: 'Correct Answer',
},
{
id: 'answer_04',
id: 'answer_12',
correct: false,
text: 'Incorrect Answer',
},
Expand Down

0 comments on commit 51ab3ce

Please sign in to comment.