Browse Source

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

Reviewed-on: #10
pull/13/head
Tim Glasgow 2 years ago
parent
commit
598bc71508
  1. 1
      squarenotsquare/__tests__/Action-Creators-test.js
  2. 29
      squarenotsquare/__tests__/App-test.js
  3. 1
      squarenotsquare/__tests__/DB-test.js
  4. 32
      squarenotsquare/__tests__/Libs-test.js
  5. 1
      squarenotsquare/__tests__/Migration-test.js
  6. 1
      squarenotsquare/__tests__/Nav-test.js
  7. 1
      squarenotsquare/__tests__/Redux-test.js
  8. 1
      squarenotsquare/__tests__/Repo-test.js
  9. 1
      squarenotsquare/__tests__/Services-test.js
  10. 1
      squarenotsquare/__tests__/Themes-test.js
  11. 3
      squarenotsquare/jest.config.js
  12. 1
      squarenotsquare/package.json
  13. 5
      squarenotsquare/src/libs/CalculateScore.js
  14. 2
      squarenotsquare/src/libs/Random.js

1
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);

29
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', () => {
</Provider>);
});
it('renders addition game component', () => {
const mockStore = ConfigStore;
renderer.create(
<Provider store={mockStore}>
<AdditionGame/>
</Provider>);
});
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(
<Provider store={mockStore}>
<Score/>
</Provider>);
})
it('renders splash component', () => {
renderer.create(<Splash />);
});
it('renders ninekey component', () => {
renderer.create(<NineKey />)
})
it('renders scrolling picker component', () => {
renderer.create(<ScrollingPicker mode='square' modeSetter={() => {return true}}/>)
})

1
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')

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

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

1
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', {});

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

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

1
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')

1
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());

3
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: '<rootDir>/__mock__/mockFirebase.js',
'react-native-keychain': '<rootDir>/__mock__/mockKeyStore.js',

1
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": {

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

2
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(

Loading…
Cancel
Save