diff --git a/README.md b/README.md index 07e25b7..98e9b31 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ ## Live Demo -[Live Demo Link](https://lily-coder.github.io/math-magicians/) +[Github Live Demo](https://lily-coder.github.io/math-magicians/) +[Heroku Live Demo](https://math-mag.herokuapp.com/home) +[Netlify Live Demo](https://focused-kirch-4d3870.netlify.app/) ## Getting Started diff --git a/package-lock.json b/package-lock.json index 54cd337..9f9d0bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2165,6 +2165,7 @@ "version": "7.31.2", "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-7.31.2.tgz", "integrity": "sha512-3UqjCpey6HiTZT92vODYLPxTBWlM8ZOOjr3LX5F37/VRipW2M1kX6I/Cm4VXzteZqfGfagg8yXywpcOgQBlNsQ==", + "dev": true, "requires": { "@babel/code-frame": "^7.10.4", "@babel/runtime": "^7.12.5", @@ -2180,6 +2181,7 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", + "dev": true, "requires": { "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-reports": "^3.0.0", @@ -2192,6 +2194,7 @@ "version": "15.0.14", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.14.tgz", "integrity": "sha512-yEJzHoxf6SyQGhBhIYGXQDSCkJjB6HohDShto7m8vaKg9Yp0Yn8+71J9eakh2bnPg6BfsH9PRMhiRTZnd4eXGQ==", + "dev": true, "requires": { "@types/yargs-parser": "*" } @@ -2200,6 +2203,7 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, "requires": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -2209,6 +2213,7 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", "integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", + "dev": true, "requires": { "@jest/types": "^26.6.2", "ansi-regex": "^5.0.0", @@ -2238,6 +2243,7 @@ "version": "11.2.7", "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-11.2.7.tgz", "integrity": "sha512-tzRNp7pzd5QmbtXNG/mhdcl7Awfu/Iz1RaVHY75zTdOkmHCuzMhRL83gWHSgOAcjS3CCbyfwUHMZgRJb4kAfpA==", + "dev": true, "requires": { "@babel/runtime": "^7.12.5", "@testing-library/dom": "^7.28.1" @@ -2259,7 +2265,8 @@ "@types/aria-query": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-4.2.2.tgz", - "integrity": "sha512-HnYpAE1Y6kRyKM/XkEuiRQhTHvkzMBurTHnpFLYLBGPIylZNPs9jJcuOOYWxPLJCSEtmZT0Y8rHDokKN7rRTig==" + "integrity": "sha512-HnYpAE1Y6kRyKM/XkEuiRQhTHvkzMBurTHnpFLYLBGPIylZNPs9jJcuOOYWxPLJCSEtmZT0Y8rHDokKN7rRTig==", + "dev": true }, "@types/babel__core": { "version": "7.1.16", @@ -3645,6 +3652,15 @@ "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "optional": true }, + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "optional": true, + "requires": { + "file-uri-to-path": "1.0.0" + } + }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -6523,6 +6539,12 @@ } } }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "optional": true + }, "filename-reserved-regex": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz", @@ -10079,7 +10101,8 @@ "lz-string": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz", - "integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY=" + "integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY=", + "dev": true }, "magic-string": { "version": "0.25.7", @@ -10440,6 +10463,12 @@ "resolved": "https://registry.npmjs.org/multicast-dns-service-types/-/multicast-dns-service-types-1.1.0.tgz", "integrity": "sha1-iZ8R2WhuXgXLkbNdXw5jt3PPyQE=" }, + "nan": { + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz", + "integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==", + "optional": true + }, "nanoid": { "version": "3.1.25", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.25.tgz", @@ -12899,6 +12928,26 @@ "workbox-webpack-plugin": "5.1.4" } }, + "react-shallow-renderer": { + "version": "16.14.1", + "resolved": "https://registry.npmjs.org/react-shallow-renderer/-/react-shallow-renderer-16.14.1.tgz", + "integrity": "sha512-rkIMcQi01/+kxiTE9D3fdS959U1g7gs+/rborw++42m1O9FAQiNI/UNRZExVUoAOprn4umcXf+pFRou8i4zuBg==", + "requires": { + "object-assign": "^4.1.1", + "react-is": "^16.12.0 || ^17.0.0" + } + }, + "react-test-renderer": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-17.0.2.tgz", + "integrity": "sha512-yaQ9cB89c17PUb0x6UfWRs7kQCorVdHlutU1boVPEsB8IDZH6n9tHxMacc3y0JoXOJUsZb/t/Mb8FUWMKaM7iQ==", + "requires": { + "object-assign": "^4.1.1", + "react-is": "^17.0.2", + "react-shallow-renderer": "^16.13.1", + "scheduler": "^0.20.2" + } + }, "read-pkg": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-3.0.0.tgz", @@ -15502,7 +15551,11 @@ "version": "1.2.13", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz", "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==", - "optional": true + "optional": true, + "requires": { + "bindings": "^1.5.0", + "nan": "^2.12.1" + } }, "glob-parent": { "version": "3.1.0", @@ -16100,7 +16153,11 @@ "version": "1.2.13", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz", "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==", - "optional": true + "optional": true, + "requires": { + "bindings": "^1.5.0", + "nan": "^2.12.1" + } }, "glob-parent": { "version": "3.1.0", diff --git a/package.json b/package.json index 9e8a873..17cf2cb 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,9 @@ "name": "math-magicians", "version": "0.1.0", "private": true, - "homepage": "https://lily-coder.github.io/math-magicians", + "homepage": ".", "dependencies": { "@testing-library/jest-dom": "^5.14.1", - "@testing-library/react": "^11.2.7", "@testing-library/user-event": "^12.8.3", "big.js": "^6.1.1", "gh-pages": "^3.2.3", @@ -15,6 +14,7 @@ "react-icons": "^4.2.0", "react-router-dom": "^5.3.0", "react-scripts": "4.0.3", + "react-test-renderer": "^17.0.2", "web-vitals": "^1.1.2" }, "scripts": { @@ -44,6 +44,7 @@ ] }, "devDependencies": { + "@testing-library/react": "^11.2.7", "eslint": "^7.32.0", "eslint-config-airbnb-base": "^14.2.1", "eslint-plugin-import": "^2.24.1" diff --git a/src/App.test.js b/src/App.test.js deleted file mode 100644 index 4dfa815..0000000 --- a/src/App.test.js +++ /dev/null @@ -1,9 +0,0 @@ -/* eslint no-unused-vars: 0 no-undef: 0 */ -import { render, screen } from '@testing-library/react'; -import App from './App.js'; - -test('renders learn react link', () => { - render(); - const linkElement = screen.getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); -}); diff --git a/src/__test__/Answer.test.js b/src/__test__/Answer.test.js new file mode 100644 index 0000000..374a645 --- /dev/null +++ b/src/__test__/Answer.test.js @@ -0,0 +1,11 @@ +/* eslint no-unused-vars: 0 no-undef: 0 */ +import renderer from 'react-test-renderer'; +import '@testing-library/jest-dom/extend-expect.js'; +import Answer from '../components/Answer.js'; + +describe('Answer', () => { + test('Correctly renders Answer component', () => { + const answerTree = renderer.create().toJSON(); + expect(answerTree).toMatchSnapshot(); + }); +}); \ No newline at end of file diff --git a/src/__test__/Calculator.test.js b/src/__test__/Calculator.test.js new file mode 100644 index 0000000..d5e8407 --- /dev/null +++ b/src/__test__/Calculator.test.js @@ -0,0 +1,13 @@ +/* eslint no-unused-vars: 0 no-undef: 0 */ +import renderer from 'react-test-renderer'; +import '@testing-library/jest-dom/extend-expect.js'; +import Calculator from '../components/Calculator.js'; + +describe('Calculator Component', () => { + const handleClick = () => { ''; }; + + it('renders correctly', () => { + const calculatorTree = renderer.create().toJSON(); + expect(calculatorTree).toMatchSnapshot(); + }); +}); \ No newline at end of file diff --git a/src/__test__/Equal.test.js b/src/__test__/Equal.test.js new file mode 100644 index 0000000..1da8aef --- /dev/null +++ b/src/__test__/Equal.test.js @@ -0,0 +1,13 @@ +/* eslint no-unused-vars: 0 no-undef: 0 */ +import renderer from 'react-test-renderer'; +import '@testing-library/jest-dom/extend-expect.js'; +import Equal from '../components/Equals.js'; + +describe('Equal Component', () => { + const handleClick = () => { ''; }; + + it('renders correctly', () => { + const equalTree = renderer.create().toJSON(); + expect(equalTree).toMatchSnapshot(); + }); +}); \ No newline at end of file diff --git a/src/__test__/Navbar.test.js b/src/__test__/Navbar.test.js new file mode 100644 index 0000000..9644e8c --- /dev/null +++ b/src/__test__/Navbar.test.js @@ -0,0 +1,16 @@ +/* eslint-disable no-unused-vars */ +import renderer from 'react-test-renderer'; +import { BrowserRouter as Router } from 'react-router-dom'; +import '@testing-library/jest-dom/extend-expect.js'; +import Navbar from '../components/Navbar.js'; + +it('renders Navbar Component correctly', () => { + const tree = renderer + .create( + + + , + ) + .toJSON(); + expect(tree).toMatchSnapshot(); +}); diff --git a/src/__test__/Numbers.test.js b/src/__test__/Numbers.test.js new file mode 100644 index 0000000..3dedd90 --- /dev/null +++ b/src/__test__/Numbers.test.js @@ -0,0 +1,9 @@ +/* eslint-disable no-unused-vars */ +import renderer from 'react-test-renderer'; +import Numbers from '../components/Numbers.js'; +import '@testing-library/jest-dom/extend-expect.js'; + +it('renders Numbers Component correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); diff --git a/src/__test__/__snapshots__/Answer.test.js.snap b/src/__test__/__snapshots__/Answer.test.js.snap new file mode 100644 index 0000000..d0a5d7e --- /dev/null +++ b/src/__test__/__snapshots__/Answer.test.js.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Answer Correctly renders Answer component 1`] = ` +
+

+ 0 +

+
+`; diff --git a/src/__test__/__snapshots__/Calculator.test.js.snap b/src/__test__/__snapshots__/Calculator.test.js.snap new file mode 100644 index 0000000..c6876f4 --- /dev/null +++ b/src/__test__/__snapshots__/Calculator.test.js.snap @@ -0,0 +1,73 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Calculator Component renders correctly 1`] = ` +
+
+ + + + +
+
+ +
+
+ +
+
+ +
+
+`; diff --git a/src/__test__/__snapshots__/Equal.test.js.snap b/src/__test__/__snapshots__/Equal.test.js.snap new file mode 100644 index 0000000..bb3220c --- /dev/null +++ b/src/__test__/__snapshots__/Equal.test.js.snap @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Equal Component renders correctly 1`] = ` +
+ +
+`; diff --git a/src/__test__/__snapshots__/Navbar.test.js.snap b/src/__test__/__snapshots__/Navbar.test.js.snap new file mode 100644 index 0000000..e6b5d87 --- /dev/null +++ b/src/__test__/__snapshots__/Navbar.test.js.snap @@ -0,0 +1,44 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders Navbar Component correctly 1`] = ` + +`; diff --git a/src/__test__/__snapshots__/Numbers.test.js.snap b/src/__test__/__snapshots__/Numbers.test.js.snap new file mode 100644 index 0000000..d7a0312 --- /dev/null +++ b/src/__test__/__snapshots__/Numbers.test.js.snap @@ -0,0 +1,92 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders Numbers Component correctly 1`] = ` +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + +
+
+`; diff --git a/src/__test__/calculate.test.js b/src/__test__/calculate.test.js new file mode 100644 index 0000000..a94a488 --- /dev/null +++ b/src/__test__/calculate.test.js @@ -0,0 +1,77 @@ +import calculate from '../logic/calculate.js'; + +describe('Calculates user inputs correctly', () => { + it('AC input should return null for all object elements', () => { + const obj = { + total: '5', + next: '4', + operation: '+', + }; + expect(calculate(obj, 'AC')).toEqual({ + total: null, + next: null, + operation: null, + }); + }); + + it('should return empty object if total and next are zero values', () => { + const obj = { + total: '0', + next: '0', + operation: null, + }; + expect(calculate(obj, '0')).toEqual({}); + }); + + it('should return calculated sum of 10', () => { + const obj = { + total: '5', + next: '5', + operation: '+', + }; + expect(calculate(obj, '=')).toEqual({ + next: null, + operation: null, + total: '10', + }); + }); + + it('should return calculated product 0f 200', () => { + const obj = { + total: '10', + next: '20', + operation: 'x', + }; + expect(calculate(obj, '=')).toEqual({ + next: null, + operation: null, + total: '200', + }); + }); + + it('+/- input should return negative value', () => { + const obj = { + total: null, + next: '5', + operation: null, + }; + expect(calculate(obj, '+/-')).toEqual({ + next: '-5', + operation: null, + total: null, + }); + }); + + it('. input should return a decimal point', () => { + const obj = { + total: null, + next: '9', + operation: null, + }; + expect(calculate(obj, '.')).toEqual({ + next: '9.', + operation: null, + total: null, + }); + }); +}); diff --git a/src/__test__/operate.test.js b/src/__test__/operate.test.js new file mode 100644 index 0000000..d184de3 --- /dev/null +++ b/src/__test__/operate.test.js @@ -0,0 +1,44 @@ +import operate from '../logic/operate.js'; + +const one = 10; +const two = 50; + +test('the sum of one and two to equal 60', () => { + expect(operate(one, two, '+')).toEqual('60'); +}); + +test('the sum of one and two not to equal 30', () => { + expect(operate(one, two, '+')).not.toEqual('30'); +}); + +test('the difference of one and two to equal -40', () => { + expect(operate(one, two, '-')).toEqual('-40'); +}); + +test('the difference of one and two not to equal 70', () => { + expect(operate(one, two, '-')).not.toEqual('70'); +}); + +test('the multiplication of one and two to equal 500', () => { + expect(operate(one, two, 'x')).toEqual('500'); +}); + +test('the multiplication of one and two not to equal 50', () => { + expect(operate(one, two, 'x')).not.toEqual('50'); +}); + +test('the division of one and two to equal 0.2', () => { + expect(operate(one, two, '÷')).toEqual('0.2'); +}); + +test('the division of one and two not to equal 12', () => { + expect(operate(one, two, '÷')).not.toEqual('12'); +}); + +test('the modulus of one and two to equal 10', () => { + expect(operate(one, two, '%')).toEqual('10'); +}); + +test('the modulus of one and two not to equal 0.1', () => { + expect(operate(one, two, '%')).not.toEqual('0.1'); +});