Browse Source

Merge pull request 'dev' (#11) from dev into master

Reviewed-on: #11
pull/13/head
Tim Glasgow 2 years ago
parent
commit
c35d32c22e
  1. 51
      squarenotsquare/__tests__/Action-Creators-test.js
  2. 5
      squarenotsquare/__tests__/App-test.js
  3. 27
      squarenotsquare/__tests__/Redux-test.js
  4. 50
      squarenotsquare/__tests__/Repo-test.js
  5. 2
      squarenotsquare/src/realm/DbInit.js
  6. 3
      squarenotsquare/src/realm/repos/ScoreRepo.js
  7. 6
      squarenotsquare/src/redux/actions/UserActions.js
  8. 2
      squarenotsquare/src/screens/AdditionGame.js
  9. 2
      squarenotsquare/src/screens/Game.js
  10. 2
      squarenotsquare/src/screens/Home.js

51
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);
})
});
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);
})

5
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;
@ -73,3 +74,7 @@ it('renders ninekey component', () => {
it('renders scrolling picker component', () => {
renderer.create(<ScrollingPicker mode='square' modeSetter={() => {return true}}/>)
})
it('renders spinner component', () => {
renderer.create(<Spinner/>)
})

27
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', () => {
@ -17,3 +19,28 @@ 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');
})

50
squarenotsquare/__tests__/Repo-test.js

@ -119,3 +119,53 @@ test('SystemRepo gets multiple system values', () => {
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);
})
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);
})
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);
})

2
squarenotsquare/src/realm/DbInit.js

@ -29,11 +29,9 @@ 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);
}
}
let dbRef = null;

3
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);
}
}
@ -44,6 +44,7 @@ export default class ScoreRepo {
return highScores;
}
highScores.push({user: row.user, value: row.value});
++i;
});
return highScores;
}

6
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;

2
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) {

2
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){

2
squarenotsquare/src/screens/Home.js

@ -93,7 +93,7 @@ function Home(){
</View>
<View style={[styles.footer, styles.centeredJustify]}>
<Text style={[styles.greyText, styles.tinyFont, styles.centeredText]}>
0.0.1a Atonal Software Aug 10 2022
0.0.2a Atonal Software Aug 11 2022
</Text>
</View>
</SafeAreaView>

Loading…
Cancel
Save