From 7188572434a33475ab7d0d18152faccf0b768e53 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Thu, 11 Aug 2022 17:41:33 -0500 Subject: [PATCH 01/11] spinner render unit test --- squarenotsquare/__tests__/App-test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/squarenotsquare/__tests__/App-test.js b/squarenotsquare/__tests__/App-test.js index ed57c8d..7e4942a 100644 --- a/squarenotsquare/__tests__/App-test.js +++ b/squarenotsquare/__tests__/App-test.js @@ -14,6 +14,7 @@ import NineKey from '../src/components/NineKey'; import AdditionGame from '../src/screens/AdditionGame'; import Score from '../src/screens/Score'; import ScrollingPicker from '../src/components/ScrollingPicker'; +import Spinner from '../src/components/Spinner'; it('renders square stack', () => { const mockStore = ConfigStore; @@ -72,4 +73,8 @@ it('renders ninekey component', () => { it('renders scrolling picker component', () => { renderer.create( {return true}}/>) +}) + +it('renders spinner component', () => { + renderer.create() }) \ No newline at end of file From cdb1e3684b8281febe1f10f5ed804a0311c041cf Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Thu, 11 Aug 2022 18:10:30 -0500 Subject: [PATCH 02/11] move timeout to screen --- squarenotsquare/src/redux/actions/UserActions.js | 6 +++--- squarenotsquare/src/screens/AdditionGame.js | 2 +- squarenotsquare/src/screens/Game.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/squarenotsquare/src/redux/actions/UserActions.js b/squarenotsquare/src/redux/actions/UserActions.js index 6729c11..9675097 100644 --- a/squarenotsquare/src/redux/actions/UserActions.js +++ b/squarenotsquare/src/redux/actions/UserActions.js @@ -14,7 +14,7 @@ export function squareStartPressed(mode, username) { type: SQUARE_START, user: userState }); - } else if (mode === 'addition') { + } else { squareNav('AdditionGame'); dispatch({ type: ADDITION_START, @@ -26,7 +26,7 @@ export function squareStartPressed(mode, username) { export function squareFinished(answers, finalTime) { return (dispatch, getState) => { - setTimeout(() => squareNav('Score'), 3000); + squareNav('Score'); const userState = getState().user; let newUser = {...userState}; newUser.lastGameTime = finalTime; @@ -43,7 +43,7 @@ export function squareFinished(answers, finalTime) { export function addFinished(answers, finalTime) { return (dispatch, getState) => { - setTimeout(() => squareNav('Score'), 3000); + squareNav('Score'); const userState = getState().user; let newUser = {...userState}; newUser.lastGameTime = finalTime; diff --git a/squarenotsquare/src/screens/AdditionGame.js b/squarenotsquare/src/screens/AdditionGame.js index 3750184..0482952 100644 --- a/squarenotsquare/src/screens/AdditionGame.js +++ b/squarenotsquare/src/screens/AdditionGame.js @@ -108,7 +108,7 @@ function AdditionGame(props){ setHeaderColor(styles.darkGreen); setHeaderText(finalTime + ' s'); setTimerState(4); - dispatch(addFinished(answers.current, finalTime)); + setTimeout(() => dispatch(addFinished(answers.current, finalTime)),3000); } function generateLine(left, right, pairIndex) { diff --git a/squarenotsquare/src/screens/Game.js b/squarenotsquare/src/screens/Game.js index 6632002..b15d9dc 100644 --- a/squarenotsquare/src/screens/Game.js +++ b/squarenotsquare/src/screens/Game.js @@ -103,7 +103,7 @@ function Game(props){ setHeaderColor(styles.darkGreen); setHeaderText(finalTime + ' s'); setTimerState(4); - dispatch(squareFinished(answers.current, finalTime)); + setTimeout(() => dispatch(squareFinished(answers.current, finalTime)),3000); } function generateSquare(pairIndex){ From 03e035c92c0a7555c0bc3f2734773aeedfc81cae Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Thu, 11 Aug 2022 18:10:43 -0500 Subject: [PATCH 03/11] screen and component unit tests --- .../__tests__/Action-Creators-test.js | 57 +++++++++++++++++-- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/squarenotsquare/__tests__/Action-Creators-test.js b/squarenotsquare/__tests__/Action-Creators-test.js index 2bb560e..e9d581c 100644 --- a/squarenotsquare/__tests__/Action-Creators-test.js +++ b/squarenotsquare/__tests__/Action-Creators-test.js @@ -1,18 +1,63 @@ import 'react-native'; -import {appInit} from '../src/redux/actions/SystemActions'; -import { APP_INIT } from '../src/redux/types/SystemTypes'; +import {appInit, goHome, goToScores} from '../src/redux/actions/SystemActions'; +import { APP_INIT, NAV_HOME, NAV_SCORES } from '../src/redux/types/SystemTypes'; import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; +import { addFinished, squareFinished, squareStartPressed } from '../src/redux/actions/UserActions'; +import { ADDITION_FINISHED, ADDITION_START, SQUARE_FINISHED, SQUARE_START } from '../src/redux/types/UserTypes'; + jest.useRealTimers(); const middlewares = [thunk]; const mockStore = configureMockStore(middlewares); test('sends action app-init', () => { - const localStore = mockStore(); + const localStore = mockStore({user: {username: 'username'}}); return localStore.dispatch(appInit()) .then( () => { - const actualAction = localStore.getActions()[0]; - expect(actualAction.type).toEqual(APP_INIT); + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(APP_INIT); }) -}); \ No newline at end of file +}); + +test ('sends action nav-home', () => { + const localStore = mockStore({user: {username: 'username'}}); + localStore.dispatch(goHome()) + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(NAV_HOME); +}) + +test ('sends action nav-scores', () => { + const localStore = mockStore({user: {username: 'username'}}); + localStore.dispatch(goToScores()) + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(NAV_SCORES); +}) + +test ('starts square game with square-start', () => { + const localStore = mockStore({user: {username: 'username'}}); + localStore.dispatch(squareStartPressed('square', 'user')) + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(SQUARE_START); +}) + +test ('starts add game with addition-start', () => { + const localStore = mockStore({user: {username: 'username'}}); + localStore.dispatch(squareStartPressed('addition', 'user')) + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(ADDITION_START); +}) + +test ('completes square game with square-finished', () => { + const localStore = mockStore({user: {username: 'username'}}); + localStore.dispatch(squareFinished(10, 10)) + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(SQUARE_FINISHED); +}) + +test ('completes add game with addition-finished', () => { + const localStore = mockStore({user: {username: 'username'}}); + localStore.dispatch(addFinished(10, 10)) + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(ADDITION_FINISHED); +}) \ No newline at end of file From 0c44f6c5b1d0cab5dc41206bacfe0ce444255289 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Thu, 11 Aug 2022 18:27:41 -0500 Subject: [PATCH 04/11] fix an issue where local score cache was resized incorrectly --- squarenotsquare/src/realm/repos/ScoreRepo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/squarenotsquare/src/realm/repos/ScoreRepo.js b/squarenotsquare/src/realm/repos/ScoreRepo.js index 9138270..41e75a0 100644 --- a/squarenotsquare/src/realm/repos/ScoreRepo.js +++ b/squarenotsquare/src/realm/repos/ScoreRepo.js @@ -15,7 +15,7 @@ export default class ScoreRepo { this.scoreCache.sort((a, b) => b.value - a.value); if (this.scoreCache.length > 99) { - this.scoreCache = this.scoreCache.slice(99, this.scoreCache.length - 1); + this.scoreCache = this.scoreCache.slice(0, 100); } } From 0480144322bdb8b7421e31fe665cd853577efc29 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Thu, 11 Aug 2022 18:27:52 -0500 Subject: [PATCH 05/11] score cache unit test --- squarenotsquare/__tests__/Repo-test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/squarenotsquare/__tests__/Repo-test.js b/squarenotsquare/__tests__/Repo-test.js index 5cc5c5c..32e8eb6 100644 --- a/squarenotsquare/__tests__/Repo-test.js +++ b/squarenotsquare/__tests__/Repo-test.js @@ -118,4 +118,15 @@ test('SystemRepo gets multiple system values', () => { mockRealm.create(SystemEntity.name, systemKey2); let response = testRepo.getSystemKeyValue(systemKey1.key); expect(response).toEqual('Multiple system keys found for key1'); +}) + +test('Max out score repo cache', () => { + let mockRealm = new MockRealm({schemaVersion: 0}); + let testRepo = new ScoreRepo(mockRealm); + + for (let i = 0; i < 200; ++i) { + testRepo.updateScoreCache({value: i}) + } + + expect(testRepo.scoreCache.length).toEqual(100); }) \ No newline at end of file From 8a1165f83c3d910189d6d0e3ea6e239ce7dc7077 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Thu, 11 Aug 2022 18:35:57 -0500 Subject: [PATCH 06/11] Missed loop increment --- squarenotsquare/src/realm/repos/ScoreRepo.js | 1 + 1 file changed, 1 insertion(+) diff --git a/squarenotsquare/src/realm/repos/ScoreRepo.js b/squarenotsquare/src/realm/repos/ScoreRepo.js index 41e75a0..22ef826 100644 --- a/squarenotsquare/src/realm/repos/ScoreRepo.js +++ b/squarenotsquare/src/realm/repos/ScoreRepo.js @@ -44,6 +44,7 @@ export default class ScoreRepo { return highScores; } highScores.push({user: row.user, value: row.value}); + ++i; }); return highScores; } From 5b7643a9949eddb662992f23b4aefec28ef2f271 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Thu, 11 Aug 2022 18:36:09 -0500 Subject: [PATCH 07/11] score cache tests --- squarenotsquare/__tests__/Repo-test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/squarenotsquare/__tests__/Repo-test.js b/squarenotsquare/__tests__/Repo-test.js index 32e8eb6..f33f8aa 100644 --- a/squarenotsquare/__tests__/Repo-test.js +++ b/squarenotsquare/__tests__/Repo-test.js @@ -129,4 +129,30 @@ test('Max out score repo cache', () => { } expect(testRepo.scoreCache.length).toEqual(100); +}) + +test('Build score cache', () => { + let mockRealm = new MockRealm({schemaVersion: 0}); + let testRepo = new ScoreRepo(mockRealm); + + for (let i = 0; i < 100; ++i) { + testRepo.createScore({value: i, username: 'user'}) + } + + let queried = testRepo.getHighScores(); + + expect(queried.length).toEqual(100); +}) + +test('Build max score cache', () => { + let mockRealm = new MockRealm({schemaVersion: 0}); + let testRepo = new ScoreRepo(mockRealm); + + for (let i = 0; i < 200; ++i) { + testRepo.createScore({value: i, username: 'user'}) + } + + let queried = testRepo.getHighScores(); + + expect(queried.length).toEqual(100); }) \ No newline at end of file From e0786248518a14b0cca0e555d61966eabcef84a3 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Thu, 11 Aug 2022 18:38:28 -0500 Subject: [PATCH 08/11] score cache unit test --- squarenotsquare/__tests__/Repo-test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/squarenotsquare/__tests__/Repo-test.js b/squarenotsquare/__tests__/Repo-test.js index f33f8aa..83977e4 100644 --- a/squarenotsquare/__tests__/Repo-test.js +++ b/squarenotsquare/__tests__/Repo-test.js @@ -154,5 +154,18 @@ test('Build max score cache', () => { let queried = testRepo.getHighScores(); + expect(queried.length).toEqual(100); +}) + +test('Query score cache', () => { + let mockRealm = new MockRealm({schemaVersion: 0}); + let testRepo = new ScoreRepo(mockRealm); + + for (let i = 0; i < 100; ++i) { + testRepo.createScore({value: i, username: 'user'}) + } + + let queried = testRepo.getCachedScores(); + expect(queried.length).toEqual(100); }) \ No newline at end of file From 7a2b1dd893da5b59122d49a275aa6400c005b366 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Thu, 11 Aug 2022 18:42:59 -0500 Subject: [PATCH 09/11] user reducer tests --- squarenotsquare/__tests__/Redux-test.js | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/squarenotsquare/__tests__/Redux-test.js b/squarenotsquare/__tests__/Redux-test.js index aad7137..813c796 100644 --- a/squarenotsquare/__tests__/Redux-test.js +++ b/squarenotsquare/__tests__/Redux-test.js @@ -2,6 +2,8 @@ import configStore from '../src/redux/CreateStore'; import {systemReducer} from '../src/redux/reducers/SystemReducer'; import rootReducer from '../src/redux/reducers/RootReducer'; import { APP_INIT } from '../src/redux/types/SystemTypes'; +import { userReducer } from '../src/redux/reducers/UserReducer'; +import { ADDITION_FINISHED, ADDITION_START, SQUARE_FINISHED, SQUARE_START } from '../src/redux/types/UserTypes'; jest.useRealTimers(); test('configures redux store', () => { @@ -16,4 +18,29 @@ test('rootReducer constructs', () => { test('systemReducer response to app-init', () => { let nextState = systemReducer.system({}, {type: APP_INIT, system: {value: 0}}); expect(nextState.value).toEqual(0); +}) + +test('userReducer response to app-init', () => { + let nextState = userReducer.user({}, {type: APP_INIT, user: {username: 'unittest'}}); + expect(nextState.username).toEqual('unittest'); +}) + +test('userReducer response to square-start', () => { + let nextState = userReducer.user({}, {type: SQUARE_START, user: {username: 'unittest'}}); + expect(nextState.username).toEqual('unittest'); +}) + +test('userReducer response to addition-start', () => { + let nextState = userReducer.user({}, {type: ADDITION_START, user: {username: 'unittest'}}); + expect(nextState.username).toEqual('unittest'); +}) + +test('userReducer response to square-finished', () => { + let nextState = userReducer.user({}, {type: SQUARE_FINISHED, user: {username: 'unittest'}}); + expect(nextState.username).toEqual('unittest'); +}) + +test('userReducer response to addition-finished', () => { + let nextState = userReducer.user({}, {type: ADDITION_FINISHED, user: {username: 'unittest'}}); + expect(nextState.username).toEqual('unittest'); }) \ No newline at end of file From 961b51fd9a2908267ca12756f5db6a59b64292f1 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Thu, 11 Aug 2022 18:43:59 -0500 Subject: [PATCH 10/11] removed false check since db key will be resolved in every case here --- squarenotsquare/src/realm/DbInit.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/squarenotsquare/src/realm/DbInit.js b/squarenotsquare/src/realm/DbInit.js index d67ac30..6ab35b5 100644 --- a/squarenotsquare/src/realm/DbInit.js +++ b/squarenotsquare/src/realm/DbInit.js @@ -29,10 +29,8 @@ export async function initDB(dbKeyRef = 'squareDB', dbLocation = Realm.defaultPa } let dbKey = new Uint8Array(64); - if (fromStore !== false){ - for (let i = 0; i < 64; ++i){ - dbKey[i] = fromStore.charAt(i); - } + for (let i = 0; i < 64; ++i){ + dbKey[i] = fromStore.charAt(i); } let dbRef = null; From b609330c0e7b179ff6bc0d2c74f560afb8db4901 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Thu, 11 Aug 2022 18:44:55 -0500 Subject: [PATCH 11/11] build version --- squarenotsquare/src/screens/Home.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/squarenotsquare/src/screens/Home.js b/squarenotsquare/src/screens/Home.js index 911fc96..94bfb7c 100644 --- a/squarenotsquare/src/screens/Home.js +++ b/squarenotsquare/src/screens/Home.js @@ -93,7 +93,7 @@ function Home(){ - 0.0.1a Atonal Software Aug 10 2022 + 0.0.2a Atonal Software Aug 11 2022