diff --git a/squarenotsquare/__tests__/Action-Creators-test.js b/squarenotsquare/__tests__/Action-Creators-test.js
index 4f7961e..2bb560e 100644
--- a/squarenotsquare/__tests__/Action-Creators-test.js
+++ b/squarenotsquare/__tests__/Action-Creators-test.js
@@ -3,6 +3,7 @@ import {appInit} from '../src/redux/actions/SystemActions';
import { APP_INIT } from '../src/redux/types/SystemTypes';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
+jest.useRealTimers();
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
diff --git a/squarenotsquare/__tests__/App-test.js b/squarenotsquare/__tests__/App-test.js
index ba745e2..ed57c8d 100644
--- a/squarenotsquare/__tests__/App-test.js
+++ b/squarenotsquare/__tests__/App-test.js
@@ -10,7 +10,10 @@ import Game from '../src/screens/Game';
import HighScore from '../src/screens/HighScore';
import Home from '../src/screens/Home';
import Splash from '../src/screens/Splash';
-jest.useFakeTimers()
+import NineKey from '../src/components/NineKey';
+import AdditionGame from '../src/screens/AdditionGame';
+import Score from '../src/screens/Score';
+import ScrollingPicker from '../src/components/ScrollingPicker';
it('renders square stack', () => {
const mockStore = ConfigStore;
@@ -25,6 +28,14 @@ it('renders game component', () => {
);
});
+it('renders addition game component', () => {
+ const mockStore = ConfigStore;
+ renderer.create(
+
+
+ );
+});
+
it('renders highscore component', () => {
const mockStore = ConfigStore;
renderer.create(
@@ -43,6 +54,22 @@ it('renders home component', () => {
);
});
+it ('renders score component', () => {
+ const mockStore = ConfigStore;
+ renderer.create(
+
+
+ );
+})
+
it('renders splash component', () => {
renderer.create();
-});
\ No newline at end of file
+});
+
+it('renders ninekey component', () => {
+ renderer.create()
+})
+
+it('renders scrolling picker component', () => {
+ renderer.create( {return true}}/>)
+})
\ No newline at end of file
diff --git a/squarenotsquare/__tests__/DB-test.js b/squarenotsquare/__tests__/DB-test.js
index 0907577..dd630d2 100644
--- a/squarenotsquare/__tests__/DB-test.js
+++ b/squarenotsquare/__tests__/DB-test.js
@@ -1,5 +1,6 @@
import { initDB } from '../src/realm/DbInit';
import DbAPI from '../src/realm/DbAPI';
+jest.useRealTimers();
test('Realm DB inits', () => {
return initDB('negTest', 'negTest')
diff --git a/squarenotsquare/__tests__/Libs-test.js b/squarenotsquare/__tests__/Libs-test.js
new file mode 100644
index 0000000..14b44a2
--- /dev/null
+++ b/squarenotsquare/__tests__/Libs-test.js
@@ -0,0 +1,32 @@
+import { calculateSquareScore } from "../src/libs/CalculateScore";
+import {shapes} from '../src/libs/ShapeEnum';
+import {generateKey, genSquareChallenge, generateAdditionChallenge} from '../src/libs/Random';
+
+test('calculates square score', () => {
+ let score = calculateSquareScore(10, 10);
+ expect(score).toEqual(60000);
+});
+
+test('calculates square score with negative time score', () => {
+ let score = calculateSquareScore(10, 65);
+ expect(score).toEqual(10000);
+});
+
+test ('shapes enum exists', () => {
+ expect(shapes).toEqual(expect.anything());
+});
+
+test ('generates 64 char key', () => {
+ let newKey = generateKey();
+ expect(newKey.length).toEqual(64);
+});
+
+test ('generates square challenge', () => {
+ let newChallenge = genSquareChallenge();
+ expect(newChallenge.length).toEqual(20);
+});
+
+test ('generates addition challenege', () => {
+ let newChallenge = generateAdditionChallenge();
+ expect(newChallenge.length).toEqual(20);
+})
\ No newline at end of file
diff --git a/squarenotsquare/__tests__/Migration-test.js b/squarenotsquare/__tests__/Migration-test.js
index 262e634..f25a27f 100644
--- a/squarenotsquare/__tests__/Migration-test.js
+++ b/squarenotsquare/__tests__/Migration-test.js
@@ -2,6 +2,7 @@ import { SystemEntity } from "../src/realm/entities/System";
import { migratev0 } from "../src/realm/migrations/MigrateV0";
import { migratev1 } from "../src/realm/migrations/MigrateV1";
import MockRealm from "../__mock__/mockRealmObject";
+jest.useRealTimers();
test('Realm migrates to V0', () => {
let oldRealm = new MockRealm({schemaVersion: 0});
diff --git a/squarenotsquare/__tests__/Nav-test.js b/squarenotsquare/__tests__/Nav-test.js
index 72a9255..02cb7af 100644
--- a/squarenotsquare/__tests__/Nav-test.js
+++ b/squarenotsquare/__tests__/Nav-test.js
@@ -1,4 +1,5 @@
import { squareRef, squareNav } from "../src/navigation/SquareNav";
+jest.useRealTimers();
test('SquareNav calls navigation ref', () => {
let postNav = squareNav('notascreen', {});
diff --git a/squarenotsquare/__tests__/Redux-test.js b/squarenotsquare/__tests__/Redux-test.js
index 63139ed..aad7137 100644
--- a/squarenotsquare/__tests__/Redux-test.js
+++ b/squarenotsquare/__tests__/Redux-test.js
@@ -2,6 +2,7 @@ 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';
+jest.useRealTimers();
test('configures redux store', () => {
const configgedStore = configStore;
diff --git a/squarenotsquare/__tests__/Repo-test.js b/squarenotsquare/__tests__/Repo-test.js
index 6cfad0b..5cc5c5c 100644
--- a/squarenotsquare/__tests__/Repo-test.js
+++ b/squarenotsquare/__tests__/Repo-test.js
@@ -5,6 +5,7 @@ import { SystemEntity } from "../src/realm/entities/System";
import MockRealm from "../__mock__/mockRealmObject";
import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';
+jest.useRealTimers();
test('ScoreRepo inits', () => {
let testRepo = new ScoreRepo({fakeRealm: true});
diff --git a/squarenotsquare/__tests__/Services-test.js b/squarenotsquare/__tests__/Services-test.js
index 74d89bd..83f13c4 100644
--- a/squarenotsquare/__tests__/Services-test.js
+++ b/squarenotsquare/__tests__/Services-test.js
@@ -1,4 +1,5 @@
import { removeKey, setKey, getKey } from "../src/services/Keystore";
+jest.useRealTimers();
test('calls set keystore key', () => {
return setKey('100', '100')
diff --git a/squarenotsquare/__tests__/Themes-test.js b/squarenotsquare/__tests__/Themes-test.js
index 4427c2f..cda008d 100644
--- a/squarenotsquare/__tests__/Themes-test.js
+++ b/squarenotsquare/__tests__/Themes-test.js
@@ -3,6 +3,7 @@ import Fonts from '../src/themes/Fonts';
import Icons from '../src/themes/Icons';
import Metrics, {buildTestMetrics} from "../src/themes/Metrics";
import {styles} from '../src/screens/styles/AppStyles';
+jest.useRealTimers();
test('Imported colors', () => {
expect(Colors).toEqual(expect.anything());
diff --git a/squarenotsquare/jest.config.js b/squarenotsquare/jest.config.js
index 9a7b2dd..721c413 100644
--- a/squarenotsquare/jest.config.js
+++ b/squarenotsquare/jest.config.js
@@ -4,6 +4,9 @@ module.exports = {
verbose: true,
setupFiles: ['./node_modules/react-native-gesture-handler/jestSetup.js'],
moduleDirectories: ['node_modules', 'src'],
+ fakeTimers: {
+ enableGlobally: true
+ },
moduleNameMapper: {
// '@react-native-firebase/messaging: '/__mock__/mockFirebase.js',
'react-native-keychain': '/__mock__/mockKeyStore.js',
diff --git a/squarenotsquare/package.json b/squarenotsquare/package.json
index 3707151..b1dfe1a 100644
--- a/squarenotsquare/package.json
+++ b/squarenotsquare/package.json
@@ -16,6 +16,7 @@
"testDB": "jest __tests__/DB-test.js --silent",
"testNav": "jest __tests__/Nav-test.js --silent",
"testThemes": "jest __tests__/Themes-test.js --silent",
+ "testLibs": "jest __tests__/Libs-test.js",
"lint": "eslint ."
},
"dependencies": {
diff --git a/squarenotsquare/src/libs/CalculateScore.js b/squarenotsquare/src/libs/CalculateScore.js
index 0dfc6c0..c3658ae 100644
--- a/squarenotsquare/src/libs/CalculateScore.js
+++ b/squarenotsquare/src/libs/CalculateScore.js
@@ -1,5 +1,10 @@
export function calculateSquareScore (answers, finalTime) {
let timeScore = Math.round((60 - finalTime) * 1000);
+
+ if (timeScore < 0) {
+ timeScore = 0;
+ }
+
let answerScore = answers * 1000;
let finalScore = timeScore + answerScore;
return finalScore;
diff --git a/squarenotsquare/src/libs/Random.js b/squarenotsquare/src/libs/Random.js
index fc3717d..4b72eec 100644
--- a/squarenotsquare/src/libs/Random.js
+++ b/squarenotsquare/src/libs/Random.js
@@ -10,7 +10,7 @@ export function generateKey() {
for (let i = 0; i < 64; i++) {
let newCharIndex = newKey[i];
- while(newCharIndex > charactersLength){
+ while(newCharIndex >= charactersLength){
newCharIndex -= charactersLength;
}
result.push(