mirror of
https://gitlab.com/walljm/dynamicbible.git
synced 2025-07-23 07:19:50 -04:00
add unit tests
This commit is contained in:
parent
72bcf32915
commit
0805e2846e
@ -1,4 +1,4 @@
|
||||
import { Error, DisplaySettings, PageSettings, User, Settings } from '../models/app-state';
|
||||
import { Error, User, Settings } from '../models/app-state';
|
||||
import { IStorable } from '../common/storable';
|
||||
import { NoteItem } from '../models/note-state';
|
||||
import { MoveDirection } from '../common/move-direction';
|
||||
@ -7,13 +7,6 @@ import { CardItem } from '../models/card-state';
|
||||
import { Overlap } from '../common/bible-reference';
|
||||
|
||||
export class AppActionFactory {
|
||||
static newGetSavedPage(pageId: string): AppAction {
|
||||
return {
|
||||
type: 'GET_SAVED_PAGE',
|
||||
pageId,
|
||||
} as AppAction;
|
||||
}
|
||||
|
||||
static newSavePage(title: string): AppAction {
|
||||
return {
|
||||
type: 'SAVE_PAGE',
|
||||
@ -190,10 +183,6 @@ export class AppActionFactory {
|
||||
}
|
||||
|
||||
export type AppAction =
|
||||
| {
|
||||
type: 'GET_SAVED_PAGE';
|
||||
pageId: string;
|
||||
}
|
||||
| {
|
||||
type: 'SAVE_PAGE';
|
||||
title: string;
|
||||
|
@ -120,8 +120,6 @@ describe('AppService Reducer', () => {
|
||||
}
|
||||
});
|
||||
|
||||
// UPDATE_PAGE_SETTINGS
|
||||
|
||||
it('UPDATE_SETTINGS', () => {
|
||||
const settings = {
|
||||
createdOn: new Date(2020, 1, 1, 0, 0, 0, 0).toISOString(),
|
||||
@ -258,8 +256,25 @@ describe('AppService Reducer', () => {
|
||||
expect(preState.currentSavedPage.queries.length).toBe(0);
|
||||
});
|
||||
|
||||
// 'SAVE_PAGE';
|
||||
// 'GET_SAVED_PAGE';
|
||||
it('SAVE_PAGE', () => {
|
||||
const card1: CardItem = {
|
||||
qry: 'jn 3:16',
|
||||
data: null,
|
||||
type: CardType.Passage,
|
||||
};
|
||||
|
||||
const action1 = AppActionFactory.newAddCard(card1, null);
|
||||
const preState2 = reducer(preState, action1);
|
||||
|
||||
const action = AppActionFactory.newSavePage('my saved page');
|
||||
const testState = reducer(preState2, action);
|
||||
|
||||
expect(testState.savedPages.value[2].queries.length).toBe(
|
||||
1,
|
||||
'Updated savedPages first object has the wrong number of queries'
|
||||
);
|
||||
expect(testState.savedPages.value[2].title).toBe('my saved page');
|
||||
});
|
||||
|
||||
it('MOVE_SAVED_PAGE_CARD', () => {
|
||||
const page = preState.savedPages.value[1];
|
||||
@ -269,7 +284,16 @@ describe('AppService Reducer', () => {
|
||||
expect(testState.savedPages.value[1].queries[0].qry).toBe('G1', 'Failed to move card in saved page');
|
||||
});
|
||||
|
||||
// 'ADD_CARD_TO_SAVED_PAGE';
|
||||
it('ADD_CARD_TO_SAVED_PAGE', () => {
|
||||
const card1: CardItem = {
|
||||
qry: 'jn 3:16',
|
||||
data: null,
|
||||
type: CardType.Passage,
|
||||
};
|
||||
const action1 = AppActionFactory.newAddCardToSavedPage(card1, 'myid1');
|
||||
const testState = reducer(preState, action1);
|
||||
expect(testState.savedPages.value[0].queries[1].qry).toBe('jn 3:16', 'Failed to add card to saved page');
|
||||
});
|
||||
|
||||
//#endregion
|
||||
|
||||
|
@ -189,19 +189,6 @@ export function reducer(state: AppState, action: AppAction): AppState {
|
||||
savedPages,
|
||||
});
|
||||
}
|
||||
case 'GET_SAVED_PAGE': {
|
||||
const page = state.savedPages.value.find((o) => o.id.toString() === action.pageId);
|
||||
|
||||
if (!page) {
|
||||
return state;
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
currentSavedPage: page,
|
||||
currentCards: [...page.queries],
|
||||
};
|
||||
}
|
||||
case 'MOVE_SAVED_PAGE_CARD': {
|
||||
const queries = moveItem(action.savedPage.queries, action.fromIndex, action.toIndex);
|
||||
const savedPage = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user