Skip to content

Commit 2033507

Browse files
RobbyTiptonfscgoldenjoeeparkdavidkim7773khobread
committed
Resolved install error for puppeteer dependency. Changed puppeteerServer port to 5001 from 5000 since Apple uses port 5000 for Air Play. Added tests to masterState.test and wrote routes.test file.
Co-authored-by: Chris LeBrett <[email protected]> Co-authored-by: Robby Tipton <[email protected]> Co-authored-by: Joseph Park <[email protected]> Co-authored-by: David Kim <[email protected]> Co-authored-by: Kevin HoEun Lee <[email protected]>
1 parent 0c4d376 commit 2033507

File tree

6 files changed

+1426
-1205
lines changed

6 files changed

+1426
-1205
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"build": "webpack --mode production",
1717
"dev": "webpack --mode development --watch",
1818
"test": "jest --verbose --coverage",
19+
"test-on": "./node_modules/.bin/jest $1",
1920
"docker-test-lint": "eslint --ext .js --ext .jsx src",
2021
"docs": "typedoc --json docs --inputFiles src/app --inputFiles src/backend --readme docs/readme.md"
2122
},
@@ -111,9 +112,10 @@
111112
"jest": "^26.1.0",
112113
"jest-cli": "^26.1.0",
113114
"jest-diff": "^26.1.0",
115+
"jest-puppeteer": "^3.4.0",
114116
"jest-runner-eslint": "^0.7.7",
115117
"jscharting-react": "^1.2.1",
116-
"puppeteer": "^5.1.0",
118+
"puppeteer": "^1.9.0",
117119
"sass": "^1.26.10",
118120
"sass-loader": "^7.3.1",
119121
"sinon-chrome": "^3.0.1",

src/backend/__tests__/linkFiber.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import puppeteer from 'puppeteer';
1515

1616
const SERVER = require('../puppeteerServer');
1717

18-
const APP = 'http://localhost:5000';
18+
// Apple uses port 5000 for Air Play.
19+
const APP = 'http://localhost:5001';
1920

2021
let linkFiber;
2122
let mode;
Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,61 @@
1-
import masterState from '../masterState'
1+
import masterState from '../masterState';
22
import {
33
// eslint-disable-next-line @typescript-eslint/no-unused-vars
44
HookStateItem,
5-
HookStates
5+
HookStates,
66
} from '../types/backendTypes';
77

88
describe('Testing masterState functionality', () => {
9-
let hookOne : HookStateItem = {state: 'A', component: 'counter1'};
10-
let hookTwo : HookStateItem = {state: 'B', component: 'counter2'};
11-
let allHooks : HookStates = [hookOne, hookTwo];
12-
masterState.saveNew(hookOne.state, hookOne.component);
13-
masterState.saveNew(hookTwo.state, hookTwo.component);
9+
const hookOne : HookStateItem = { state: 'A', component: 'counter1' };
10+
const hookTwo : HookStateItem = { state: 'B', component: 'counter2' };
11+
const hookThree : HookStateItem = { state: 'C', component: 'counter3' };
12+
const allHooks : HookStates = [hookOne, hookTwo];
1413

15-
describe('Save new', () => {
16-
masterState.saveNew(hookOne.state, hookOne.component);
17-
masterState.saveNew(hookTwo.state, hookTwo.component);
18-
})
14+
describe('saveNew', () => {
15+
it('Should return the index of the saved component', () => {
16+
expect(masterState.saveNew(hookOne.state, hookOne.component)).toBe(0);
17+
expect(masterState.saveNew(hookTwo.state, hookTwo.component)).toBe(1);
18+
});
19+
});
1920

2021
describe('getComponentByIndex', () => {
21-
it('should be able to get both hook states component', () => {
22+
it('Should return the component when given a valid index', () => {
2223
expect(masterState.getComponentByIndex(0)).toEqual(hookOne.component);
2324
expect(masterState.getComponentByIndex(1)).toEqual(hookTwo.component);
24-
})
25-
})
25+
});
26+
it('Should return undefined when given an invalid index', () => {
27+
expect(masterState.getComponentByIndex(2)).toBe(undefined);
28+
});
29+
});
2630

2731
describe('getRecordByIndex', () => {
28-
it('should be able to get both hook states', () => {
32+
it('Should return the record when given a valid index', () => {
2933
expect(masterState.getRecordByIndex(0)).toEqual(hookOne);
3034
expect(masterState.getRecordByIndex(1)).toEqual(hookTwo);
31-
})
32-
})
35+
});
36+
it('Should return undefined when given an invalid index', () => {
37+
expect(masterState.getRecordByIndex(2)).toBe(undefined);
38+
});
39+
});
3340

34-
35-
})
41+
describe('getComponentByIndexHooks', () => {
42+
it('Should return an array of components when given an a valid array of indices', () => {
43+
expect(masterState.getComponentByIndexHooks([0, 1])).toEqual([hookOne.component, hookTwo.component]);
44+
});
45+
it('Should return an empty array when given an invalid array of indices', () => {
46+
expect(masterState.getComponentByIndexHooks([2])).toEqual([]);
47+
});
48+
});
49+
50+
describe('clear', () => {
51+
it('Should return undefined', () => {
52+
expect(masterState.clear()).toBe(undefined);
53+
});
54+
it('Should reset the componentActionRecord index', () => {
55+
expect(masterState.saveNew(hookThree.state, hookThree.component)).toBe(0);
56+
});
57+
it('Should empty the componentActionRecord array', () => {
58+
expect(masterState.getComponentByIndex(0)).toEqual(hookThree.component);
59+
});
60+
});
61+
});

src/backend/__tests__/routes.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import routes from '../routes';
2+
3+
describe('Unit Tests for routes.ts', () => {
4+
describe('addRoute', () => {
5+
it('If given a url that doesn\'t match the current route, it should return a new route object and add the route object to its values array.', () => {
6+
const newRoute = routes.addRoute('http://localhost:8080/');
7+
expect(newRoute.url).toBe('http://localhost:8080/');
8+
expect(newRoute.id).toBe(1);
9+
expect(routes.values[1].url).toBe('http://localhost:8080/');
10+
expect(routes.values[1].id).toBe(1);
11+
});
12+
13+
it('If given a url that does match the current route, it should return the current route object and not add anything to its values array.', () => {
14+
const sameRoute = routes.addRoute('http://localhost:8080/');
15+
expect(sameRoute).toBe(routes.values[1]);
16+
expect(routes.values.length).toBe(2);
17+
});
18+
19+
it('Should give route objects unique ids.', () => {
20+
routes.addRoute('http://localhost:8080/test');
21+
expect(routes.values[1].id).not.toBe(routes.values[2].id);
22+
});
23+
24+
it('Should reassign current to point to the last index in the values array.', () => {
25+
expect(routes.current).toBe(routes.values.length - 1);
26+
});
27+
});
28+
29+
describe('navigate', () => {
30+
it('Should correctly calculate delta between current and target route.', () => {
31+
routes.addRoute('http://localhost:8080/test1');
32+
routes.navigate({ url: 'http://localhost:8080/', id: 1 });
33+
expect(routes.current).toBe(1);
34+
routes.navigate({ url: 'http://localhost:8080/test1', id: 3 });
35+
expect(routes.current).toBe(3);
36+
});
37+
38+
it('Should return true if it navigated.', () => {
39+
expect(routes.navigate({ url: 'http://localhost:8080/', id: 1 })).toBe(true);
40+
});
41+
42+
it('Should return false if it didn\'t navigate.', () => {
43+
expect(routes.navigate({ url: 'http://localhost:8080/', id: 1 })).toBe(false);
44+
});
45+
});
46+
});

src/backend/puppeteerServer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const app = express();
88

99
app.use(express.static(path.resolve(__dirname)));
1010

11-
const server = app.listen(5000);
11+
// Apple uses port 5000 for Air Play.
12+
const server = app.listen(5001);
1213

1314
module.exports = server;

0 commit comments

Comments
 (0)