Skip to content

Commit

Permalink
add test and externalize actions (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 authored May 11, 2021
1 parent 60936ba commit ba3f3df
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
9 changes: 8 additions & 1 deletion web/client/actions/__tests__/geostory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ import {
updateSetting,
removeResource, REMOVE_RESOURCE,
updateUrlOnScroll, SET_UPDATE_URL_SCROLL,
updateMediaEditorSettings
updateMediaEditorSettings,
geostoryScrolling,
GEOSTORY_SCROLLING
} from '../geostory';

describe('test geostory action creators', () => {
it('geostoryScrolling', () => {
const status = true;
const action = geostoryScrolling(status);
expect(action).toEqual({type: GEOSTORY_SCROLLING, status});
});
it('clearSaveError', () => {
const action = clearSaveError();
expect(action.type).toBe(CLEAR_SAVE_ERROR);
Expand Down
3 changes: 3 additions & 0 deletions web/client/actions/geostory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const EDIT_RESOURCE = "GEOSTORY:EDIT_RESOURCE";
export const EDIT_WEBPAGE = "GEOSTORY:EDIT_WEBPAGE";
export const ERRORS_LOGO = "GEOSTORY:ERRORS_LOGO";
export const GEOSTORY_LOADED = "GEOSTORY:GEOSTORY_LOADED";
export const GEOSTORY_SCROLLING = "GEOSTORY:SCROLLING";
export const LOAD_GEOSTORY = "GEOSTORY:LOAD_GEOSTORY";
export const LOAD_GEOSTORY_ERROR = "GEOSTORY:LOAD_GEOSTORY_ERROR";
export const LOADING_GEOSTORY = "GEOSTORY:LOADING_GEOSTORY";
Expand Down Expand Up @@ -241,3 +242,5 @@ export const setPendingChanges = value => ({type: SET_PENDING_CHANGES, value});
export const updateUrlOnScroll = value => ({type: SET_UPDATE_URL_SCROLL, value});

export const updateMediaEditorSettings = mediaEditorSettings => ({ type: UPDATE_MEDIA_EDITOR_SETTINGS, mediaEditorSettings });

export const geostoryScrolling = (status) => ({ type: GEOSTORY_SCROLLING, status});
29 changes: 27 additions & 2 deletions web/client/epics/__tests__/geostory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ import {
openWebPageComponentCreator,
editWebPageComponent,
handlePendingGeoStoryChanges,
loadStoryOnHistoryPop
loadStoryOnHistoryPop,
scrollOnLoad,
urlUpdateOnScroll
} from '../geostory';
import {
ADD,
LOADING_GEOSTORY,
loadGeostory,
SET_CURRENT_STORY,
setCurrentStory,
GEOSTORY_SCROLLING,
LOAD_GEOSTORY_ERROR,
add,
UPDATE,
Expand All @@ -57,7 +61,9 @@ import {
editWebPage,
setResource,
SET_PENDING_CHANGES,
LOAD_GEOSTORY
LOAD_GEOSTORY,
geostoryScrolling,
updateCurrentPage
} from '../../actions/geostory';
import { SET_CONTROL_PROPERTY } from '../../actions/controls';
import {
Expand Down Expand Up @@ -1630,6 +1636,25 @@ describe('Geostory Epics', () => {
});
});

it('urlUpdateOnScroll', (done) => {
const NUM_ACTIONS = 1;
testEpic(addTimeoutEpic(urlUpdateOnScroll, 1000), NUM_ACTIONS, [updateCurrentPage({sectionId: "sectionId"})],
(actions) => {
expect(actions[0].type).toBe(TEST_TIMEOUT);
done();
}, {geostory: {mode: "view", updateUrlOnScroll: true, resource: {id: "1"}}});
});
it('scrollOnLoad', (done) => {
const NUM_ACTIONS = 2;
testEpic(scrollOnLoad, NUM_ACTIONS, setCurrentStory({}),
(actions) => {
expect(actions[0].type).toBe(GEOSTORY_SCROLLING);
expect(actions[0].status).toBe(true);
expect(actions[1].type).toBe(GEOSTORY_SCROLLING);
expect(actions[1].status).toBe(false);
done();
});
});
describe('loadStoryOnHistoryPop', () => {
it('loadStoryOnHistoryPop without shared', (done) => {
const NUM_ACTIONS = 1;
Expand Down
11 changes: 6 additions & 5 deletions web/client/epics/geostory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import words from 'lodash/words';
import get from 'lodash/get';
import isArray from 'lodash/isArray';
import isEmpty from 'lodash/isEmpty';
import groupBy from "lodash/groupBy";

import { push, LOCATION_CHANGE } from 'connected-react-router';
import uuid from 'uuid/v1';
Expand Down Expand Up @@ -58,7 +57,9 @@ import {
EDIT_RESOURCE,
UPDATE_CURRENT_PAGE,
UPDATE_SETTING,
SET_CURRENT_STORY
SET_CURRENT_STORY,
geostoryScrolling,
GEOSTORY_SCROLLING
} from '../actions/geostory';
import { setControlProperty } from '../actions/controls';

Expand Down Expand Up @@ -519,7 +520,7 @@ const semaphore = (sem$, start = true, condition = (c) => c) => (stream$) =>
export const urlUpdateOnScroll = (action$, {getState}) =>
action$.ofType(UPDATE_CURRENT_PAGE)
.let(semaphore(
action$.ofType("GEOSTORY:SCROLLING")
action$.ofType(GEOSTORY_SCROLLING)
.map(a => !a.value)
))
.debounceTime(50) // little delay if too many UPDATE_CURRENT_PAGE actions come
Expand Down Expand Up @@ -558,8 +559,8 @@ export const scrollOnLoad = (action$) =>
}
)
.ignoreElements()
.startWith({type: "GEOSTORY:SCROLLING", value: true})
.concat(Observable.of({type: "GEOSTORY:SCROLLING", value: false}).delay(500));
.startWith(geostoryScrolling(true))
.concat(Observable.of(geostoryScrolling(false)).delay(500));
});

/**
Expand Down

0 comments on commit ba3f3df

Please sign in to comment.