Skip to content

Commit

Permalink
Merge pull request #7 from nedjwab/testing
Browse files Browse the repository at this point in the history
Testing React with Jest
  • Loading branch information
nedjwab committed Jun 16, 2022
2 parents 961ee27 + 2e6298c commit f49d59a
Show file tree
Hide file tree
Showing 14 changed files with 355 additions and 7 deletions.
7 changes: 7 additions & 0 deletions MIT.md
@@ -0,0 +1,7 @@
## Copyright 2021, Nedjwa Bouraiou

Permission is hereby granted, free of charge, to any person obtaining a copy of this webpage/website and associated documentation files, to deal in the webpage/website without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the webpage/website, and to permit persons to whom the webpage/website is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the webpage/website.

THE webpage/website IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE webpage/website OR THE USE OR OTHER DEALINGS IN THE webpage/website.
7 changes: 6 additions & 1 deletion README.md
Expand Up @@ -5,7 +5,9 @@ Math magicians is a website for all fans of mathematics. It is a Single Page App


## Live Demo
[Here](https://62a8ee1d33108f0ef4e1cf6d--loquacious-custard-2f3cce.netlify.app/) you can find a live demo of Math Magicians .
[Here the Netlify's link ](https://62a8ee1d33108f0ef4e1cf6d--loquacious-custard-2f3cce.netlify.app/) to the live demo of Math Magicians .

[Here the Heroku's link ](https://nedjwa-math-magicians.herokuapp.com/) to the live demo of Math Magicians .
## Built With 🔨

- HTML
Expand Down Expand Up @@ -67,5 +69,8 @@ Contributions, issues, and feature requests are welcome!

Give a ⭐️ if you like this project!

## 📝 License

This project is [MIT](./MIT.md) licensed.


85 changes: 79 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -11,6 +11,7 @@
"react-dom": "^18.1.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"react-test-renderer": "^18.2.0",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions src/tests/__snapshots__/footer.test.js.snap
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
<footer>
Made By @nedjwa_Bouraiou
</footer>
`;
25 changes: 25 additions & 0 deletions src/tests/__snapshots__/home.test.js.snap
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
<div
className="home-container"
>
<img
alt="gif"
className="brain-img"
src="https://upload.wikimedia.org/wikipedia/commons/e/e2/Math_-_Idil_Keysan_-_Wikimedia_Giphy_stickers_2019.gif"
/>
<div
className="body"
>
<h2>
Welcome to our page!
</h2>
<div
className="contenu"
>
While it may seem like math problems like the above have no real use in life, this couldn’t be farther from the truth! Math is incredibly important in our lives and, without realizing it, we use mathematical concepts, as well as the skills we learn from doing math problems, every day. The laws of mathematics govern everything around us, and without a good understanding of them, one can encounter significant problems in life.
</div>
</div>
</div>
`;
36 changes: 36 additions & 0 deletions src/tests/__snapshots__/navBar.test.js.snap
@@ -0,0 +1,36 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
<header>
<h1
id="logo"
>
Math Magicians
</h1>
<nav
className="nav-items"
>
<a
className="nav-item"
href="/"
onClick={[Function]}
>
Home
</a>
<a
className="nav-item"
href="/calculator"
onClick={[Function]}
>
Calculator
</a>
<a
className="nav-item"
href="/quote"
onClick={[Function]}
>
Quotes
</a>
</nav>
</header>
`;
33 changes: 33 additions & 0 deletions src/tests/__snapshots__/quote.test.js.snap
@@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
<div
className="quotes"
>
<ul>
<li>
Without mathematics, there’s nothing you can do. Everything around you is mathematics. Everything around you is numbers.
<span>
— Shakuntala Devi, Indian writer and mental calculator
</span>
</li>
<br />
<li>
Mathematics as an expression of the human mind reflects the active will, the contemplative reason, and the desire for aesthetic perfection. Its basic elements are logic and intuition, analysis and construction, generality and individuality.
<span>
— Richard Courant, German-American mathematician
</span>
</li>
<br />
<li>
What is mathematics? It is only a systematic effort of solving puzzles posed by nature.
<span>
— Shakuntala Devi
</span>
</li>
</ul>
</div>
`;
67 changes: 67 additions & 0 deletions src/tests/calculator.test.js
@@ -0,0 +1,67 @@
import calculate from '../logic/calculate';

describe('Test for calculate function', () => {
test('Test AC button', () => {
const obj = {
next: null,
total: 5,
operation: '+',
};

const result = calculate(obj, 'AC');

expect(result).toStrictEqual({
total: null,
next: null,
operation: null,
});
});

test('Test = button', () => {
const obj = {
next: 3,
total: 5,
operation: '+',
};

const result = calculate(obj, '=');

expect(result).toStrictEqual({
total: '8',
next: null,
operation: null,
});
});

test('Test . button', () => {
const obj = {
next: '3.',
total: null,
operation: '+',
};

const result = calculate(obj, '.');

expect(result).toStrictEqual({
total: null,
next: '3.',
operation: '+',
});
});

test('Test +/- button', () => {
const obj = {
next: '4',
total: null,
operation: '+',
};

const result = calculate(obj, '+/-');

expect(result).toStrictEqual({
total: null,
next: '-4',
operation: '+',
});
});
});
10 changes: 10 additions & 0 deletions src/tests/footer.test.js
@@ -0,0 +1,10 @@
import React from 'react';
import renderer from 'react-test-renderer';
import Footer from '../components/footer';

it('renders correctly', () => {
const footer = renderer
.create(<Footer />)
.toJSON();
expect(footer).toMatchSnapshot();
});
10 changes: 10 additions & 0 deletions src/tests/home.test.js
@@ -0,0 +1,10 @@
import React from 'react';
import renderer from 'react-test-renderer';
import Home from '../components/home';

it('renders correctly', () => {
const home = renderer
.create(<Home />)
.toJSON();
expect(home).toMatchSnapshot();
});
11 changes: 11 additions & 0 deletions src/tests/navBar.test.js
@@ -0,0 +1,11 @@
import React from 'react';
import renderer from 'react-test-renderer';
import { BrowserRouter as Router } from 'react-router-dom';
import Navbar from '../components/navBar';

it('renders correctly', () => {
const navbar = renderer
.create(<Router><Navbar /></Router>)
.toJSON();
expect(navbar).toMatchSnapshot();
});

0 comments on commit f49d59a

Please sign in to comment.