Skip to content

Commit

Permalink
spinner test
Browse files Browse the repository at this point in the history
  • Loading branch information
uo288574 committed Apr 28, 2024
1 parent 4b3ab9e commit be4601c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
51 changes: 51 additions & 0 deletions webapp/src/components/spinner/Spinner.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import Spinner from './Spinner';
import { ContextFun } from '../Context';
import { BrowserRouter as Router } from 'react-router-dom';

const mockAxios = new MockAdapter(axios);

describe("Test for spinner component", () => {

beforeEach(() => {
mockAxios.reset();
});

test("renders Spinner",async () => {
render(
<ContextFun>
<Router>
<Spinner/>
</Router>
</ContextFun>
);

let divChilds = document.getElementsByClassName('input-number')[0].childNodes;
expect(divChilds.length).toBe(3);
});

test('should increment and decrement value', async () => {
render(
<ContextFun>
<Router>
<Spinner/>
</Router>
</ContextFun>
);

let spanElem = document.getElementsByClassName('input-number')[0].childNodes[1];
let btDec = document.getElementsByClassName('input-number')[0].childNodes[0];
let btInc = document.getElementsByClassName('input-number')[0].childNodes[2];
expect(spanElem.textContent).toBe("0");
fireEvent.click(btDec);
expect(spanElem.textContent).toBe("-1");
fireEvent.click(btInc);
fireEvent.click(btInc);
expect(spanElem.textContent).toBe("1");
});

});

4 changes: 2 additions & 2 deletions webapp/src/help/Help.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, fireEvent, screen, waitFor, act } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import Help from './Help';
Expand All @@ -14,7 +14,7 @@ describe("Help for game", () => {
mockAxios.reset();
});

test("renders GameConfig",async () => {
test("renders Help",async () => {
render(
<ContextFun>
<Router>
Expand Down

0 comments on commit be4601c

Please sign in to comment.