forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters