Skip to content
Snippets Groups Projects
Unverified Commit 03b96de9 authored by aeschylus's avatar aeschylus Committed by GitHub
Browse files

Merge pull request #1575 from ProjectMirador/splitout-actioncreators

splits out action creators to individual files, and adds tests for co…
parents 863325d0 4db9bfc1
No related branches found
No related tags found
No related merge requests found
import * as actions from '../../../src/actions/index';
import ActionTypes from '../../../src/action-types';
describe('canvas actions', () => {
describe('nextCanvas', () => {
it('moves to the next canvas', () => {
const id = 'abc123';
const expectedAction = {
type: ActionTypes.NEXT_CANVAS,
windowId: id,
};
expect(actions.nextCanvas(id)).toEqual(expectedAction);
});
});
describe('previousCanvas', () => {
it('moves to the previous canvas', () => {
const id = 'abc123';
const expectedAction = {
type: ActionTypes.PREVIOUS_CANVAS,
windowId: id,
};
expect(actions.previousCanvas(id)).toEqual(expectedAction);
});
});
});
import * as actions from '../../../src/actions/index';
import ActionTypes from '../../../src/action-types';
describe('config actions', () => {
describe('setConfig', () => {
it('sets the config', () => {
const config = { foo: 'bar' };
const expectedAction = {
type: ActionTypes.SET_CONFIG,
config,
};
expect(actions.setConfig(config)).toEqual(expectedAction);
});
});
describe('updateConfig', () => {
it('updates the config', () => {
const config = { foo: 'bar' };
const expectedAction = {
type: ActionTypes.UPDATE_CONFIG,
config,
};
expect(actions.updateConfig(config)).toEqual(expectedAction);
});
});
});
...@@ -7,132 +7,7 @@ import ActionTypes from '../../../src/action-types'; ...@@ -7,132 +7,7 @@ import ActionTypes from '../../../src/action-types';
const middlewares = [thunk]; const middlewares = [thunk];
const mockStore = configureMockStore(middlewares); const mockStore = configureMockStore(middlewares);
describe('actions', () => { describe('infoResponse actions', () => {
describe('addWindow', () => {
it('should create a new window with merged defaults', () => {
const options = {
id: 'helloworld',
canvasIndex: 1,
};
const expectedAction = {
type: ActionTypes.ADD_WINDOW,
payload: {
id: 'helloworld',
canvasIndex: 1,
collectionIndex: 0,
manifestId: null,
rangeId: null,
xywh: [0, 0, 400, 400],
rotation: null,
},
};
expect(actions.addWindow(options)).toEqual(expectedAction);
});
});
describe('removeWindow', () => {
it('removes the window and returns windowId', () => {
const id = 'abc123';
const expectedAction = {
type: ActionTypes.REMOVE_WINDOW,
windowId: id,
};
expect(actions.removeWindow(id)).toEqual(expectedAction);
});
});
describe('nextCanvas', () => {
it('moves to the next canvas', () => {
const id = 'abc123';
const expectedAction = {
type: ActionTypes.NEXT_CANVAS,
windowId: id,
};
expect(actions.nextCanvas(id)).toEqual(expectedAction);
});
});
describe('previousCanvas', () => {
it('moves to the previous canvas', () => {
const id = 'abc123';
const expectedAction = {
type: ActionTypes.PREVIOUS_CANVAS,
windowId: id,
};
expect(actions.previousCanvas(id)).toEqual(expectedAction);
});
});
describe('requestManifest', () => {
it('requests a manifest given a url', () => {
const id = 'abc123';
const expectedAction = {
type: ActionTypes.REQUEST_MANIFEST,
manifestId: id,
};
expect(actions.requestManifest(id)).toEqual(expectedAction);
});
});
describe('receiveManifest', () => {
it('moves to the previous canvas', () => {
const id = 'abc123';
const json = {
id,
content: 'lots of metadata, canvases, and other IIIFy things',
};
const expectedAction = {
type: ActionTypes.RECEIVE_MANIFEST,
manifestId: id,
manifestJson: json,
};
expect(actions.receiveManifest(id, json)).toEqual(expectedAction);
});
});
describe('fetchManifest', () => {
let store = null;
beforeEach(() => {
store = mockStore({});
});
describe('success response', () => {
beforeEach(() => {
fetch.mockResponseOnce(JSON.stringify({ data: '12345' })); // eslint-disable-line no-undef
});
it('dispatches the REQUEST_MANIFEST action', () => {
store.dispatch(actions.fetchManifest('https://purl.stanford.edu/sn904cj3429/iiif/manifest'));
expect(store.getActions()).toEqual([
{ manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest', type: 'REQUEST_MANIFEST' },
]);
});
it('dispatches the REQUEST_MANIFEST and then RECEIVE_MANIFEST', () => {
store.dispatch(actions.fetchManifest('https://purl.stanford.edu/sn904cj3429/iiif/manifest'))
.then(() => {
const expectedActions = store.getActions();
expect(expectedActions).toEqual([
{ manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest', type: 'REQUEST_MANIFEST' },
{ manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest', manifestJson: { data: '12345' }, type: 'RECEIVE_MANIFEST' },
]);
});
});
});
describe('error response', () => {
it('dispatches the REQUEST_MANIFEST and then RECEIVE_MANIFEST', () => {
store.dispatch(actions.fetchManifest('https://purl.stanford.edu/sn904cj3429/iiif/manifest'))
.then(() => {
const expectedActions = store.getActions();
expect(expectedActions).toEqual([
{ manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest', type: 'REQUEST_MANIFEST' },
{ manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest', error: new Error('invalid json response body at undefined reason: Unexpected end of JSON input'), type: 'RECEIVE_MANIFEST_FAILURE' },
]);
});
});
});
});
describe('removeManifest', () => {
it('removes an existing manifest', () => {
const expectedAction = {
type: ActionTypes.REMOVE_MANIFEST,
manifestId: 'foo',
};
expect(actions.removeManifest('foo')).toEqual(expectedAction);
});
});
describe('requestInfoResponse', () => { describe('requestInfoResponse', () => {
it('requests an infoResponse from given a url', () => { it('requests an infoResponse from given a url', () => {
const id = 'abc123'; const id = 'abc123';
......
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import * as actions from '../../../src/actions/index';
import ActionTypes from '../../../src/action-types';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
describe('manifest actions', () => {
describe('requestManifest', () => {
it('requests a manifest given a url', () => {
const id = 'abc123';
const expectedAction = {
type: ActionTypes.REQUEST_MANIFEST,
manifestId: id,
};
expect(actions.requestManifest(id)).toEqual(expectedAction);
});
});
describe('receiveManifest', () => {
it('moves to the previous canvas', () => {
const id = 'abc123';
const json = {
id,
content: 'lots of metadata, canvases, and other IIIFy things',
};
const expectedAction = {
type: ActionTypes.RECEIVE_MANIFEST,
manifestId: id,
manifestJson: json,
};
expect(actions.receiveManifest(id, json)).toEqual(expectedAction);
});
});
describe('fetchManifest', () => {
let store = null;
beforeEach(() => {
store = mockStore({});
});
describe('success response', () => {
beforeEach(() => {
fetch.mockResponseOnce(JSON.stringify({ data: '12345' })); // eslint-disable-line no-undef
});
it('dispatches the REQUEST_MANIFEST action', () => {
store.dispatch(actions.fetchManifest('https://purl.stanford.edu/sn904cj3429/iiif/manifest'));
expect(store.getActions()).toEqual([
{ manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest', type: 'REQUEST_MANIFEST' },
]);
});
it('dispatches the REQUEST_MANIFEST and then RECEIVE_MANIFEST', () => {
store.dispatch(actions.fetchManifest('https://purl.stanford.edu/sn904cj3429/iiif/manifest'))
.then(() => {
const expectedActions = store.getActions();
expect(expectedActions).toEqual([
{ manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest', type: 'REQUEST_MANIFEST' },
{ manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest', manifestJson: { data: '12345' }, type: 'RECEIVE_MANIFEST' },
]);
});
});
});
describe('error response', () => {
it('dispatches the REQUEST_MANIFEST and then RECEIVE_MANIFEST', () => {
store.dispatch(actions.fetchManifest('https://purl.stanford.edu/sn904cj3429/iiif/manifest'))
.then(() => {
const expectedActions = store.getActions();
expect(expectedActions).toEqual([
{ manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest', type: 'REQUEST_MANIFEST' },
{ manifestId: 'https://purl.stanford.edu/sn904cj3429/iiif/manifest', error: new Error('invalid json response body at undefined reason: Unexpected end of JSON input'), type: 'RECEIVE_MANIFEST_FAILURE' },
]);
});
});
});
});
describe('removeManifest', () => {
it('removes an existing manifest', () => {
const expectedAction = {
type: ActionTypes.REMOVE_MANIFEST,
manifestId: 'foo',
};
expect(actions.removeManifest('foo')).toEqual(expectedAction);
});
});
});
import * as actions from '../../../src/actions/index';
import ActionTypes from '../../../src/action-types';
describe('window actions', () => {
describe('addWindow', () => {
it('should create a new window with merged defaults', () => {
const options = {
id: 'helloworld',
canvasIndex: 1,
};
const expectedAction = {
type: ActionTypes.ADD_WINDOW,
payload: {
id: 'helloworld',
canvasIndex: 1,
collectionIndex: 0,
manifestId: null,
rangeId: null,
xywh: [0, 0, 400, 400],
rotation: null,
},
};
expect(actions.addWindow(options)).toEqual(expectedAction);
});
});
describe('removeWindow', () => {
it('removes the window and returns windowId', () => {
const id = 'abc123';
const expectedAction = {
type: ActionTypes.REMOVE_WINDOW,
windowId: id,
};
expect(actions.removeWindow(id)).toEqual(expectedAction);
});
});
});
import ActionTypes from '../action-types';
/**
* nextCanvas - action creator
*
* @param {String} windowId
* @memberof ActionCreators
*/
export function nextCanvas(windowId) {
return { type: ActionTypes.NEXT_CANVAS, windowId };
}
/**
* previousCanvas - action creator
*
* @param {String} windowId
* @memberof ActionCreators
*/
export function previousCanvas(windowId) {
return { type: ActionTypes.PREVIOUS_CANVAS, windowId };
}
import ActionTypes from '../action-types';
/**
* setConfig - action creator
*
* @param {Object} config
* @memberof ActionCreators
*/
export function setConfig(config) {
return { type: ActionTypes.SET_CONFIG, config };
}
/**
* updateConfig - action creator
*
* @param {Object} config
* @memberof ActionCreators
*/
export function updateConfig(config) {
return { type: ActionTypes.UPDATE_CONFIG, config };
}
import fetch from 'node-fetch';
import ActionTypes from '../action-types';
/** /**
* Action Creators for Mirador * Action Creators for Mirador
* @namespace ActionCreators * @namespace ActionCreators
*/ */
export * from './config';
export * from './window';
/** export * from './manifest';
* setConfig - action creator export * from './infoResponse';
* export * from './canvas';
* @param {Object} config
* @memberof ActionCreators
*/
export function setConfig(config) {
return { type: ActionTypes.SET_CONFIG, config };
}
/**
* updateConfig - action creator
*
* @param {Object} config
* @memberof ActionCreators
*/
export function updateConfig(config) {
return { type: ActionTypes.UPDATE_CONFIG, config };
}
/**
* focusWindow - action creator
*
* @param {String} windowId
* @memberof ActionCreators
*/
export function focusWindow(windowId) {
return { type: ActionTypes.FOCUS_WINDOW, windowId };
}
/**
* addWindow - action creator
*
* @param {Object} options
* @memberof ActionCreators
*/
export function addWindow(options) {
const defaultOptions = {
// TODO: Windows should be a hash with id's as keys for easy lookups
// https://redux.js.org/faq/organizing-state#how-do-i-organize-nested-or-duplicate-data-in-my-state
id: `window-${new Date().valueOf()}`,
canvasIndex: 0,
collectionIndex: 0,
manifestId: null,
rangeId: null,
xywh: [0, 0, 400, 400],
rotation: null,
};
return { type: ActionTypes.ADD_WINDOW, payload: Object.assign({}, defaultOptions, options) };
}
/**
* removeWindow - action creator
*
* @param {String} windowId
* @memberof ActionCreators
*/
export function removeWindow(windowId) {
return { type: ActionTypes.REMOVE_WINDOW, windowId };
}
/**
* nextCanvas - action creator
*
* @param {String} windowId
* @memberof ActionCreators
*/
export function nextCanvas(windowId) {
return { type: ActionTypes.NEXT_CANVAS, windowId };
}
/**
* previousCanvas - action creator
*
* @param {String} windowId
* @memberof ActionCreators
*/
export function previousCanvas(windowId) {
return { type: ActionTypes.PREVIOUS_CANVAS, windowId };
}
/**
* requestManifest - action creator
*
* @param {String} manifestId
* @memberof ActionCreators
*/
export function requestManifest(manifestId) {
return {
type: ActionTypes.REQUEST_MANIFEST,
manifestId,
};
}
/**
* receiveManifest - action creator
*
* @param {String} windowId
* @param {Object} manifestJson
* @memberof ActionCreators
*/
export function receiveManifest(manifestId, manifestJson) {
return {
type: ActionTypes.RECEIVE_MANIFEST,
manifestId,
manifestJson,
};
}
/**
* receiveManifestFailure - action creator
*
* @param {String} windowId
* @param {String} error
* @memberof ActionCreators
*/
export function receiveManifestFailure(manifestId, error) {
return {
type: ActionTypes.RECEIVE_MANIFEST_FAILURE,
manifestId,
error,
};
}
/**
* fetchManifest - action creator
*
* @param {String} manifestId
* @memberof ActionCreators
*/
export function fetchManifest(manifestId) {
return ((dispatch) => {
dispatch(requestManifest(manifestId));
return fetch(manifestId)
.then(response => response.json())
.then(json => dispatch(receiveManifest(manifestId, json)))
.catch(error => dispatch(receiveManifestFailure(manifestId, error)));
});
}
/**
* removeManifest - action creator
*
* @param {String} manifestId
* @memberof ActionCreators
*/
export function removeManifest(manifestId) {
return { type: ActionTypes.REMOVE_MANIFEST, manifestId };
}
/**
* requestInfoResponse - action creator
*
* @param {String} infoId
* @memberof ActionCreators
*/
export function requestInfoResponse(infoId) {
return {
type: ActionTypes.REQUEST_INFO_RESPONSE,
infoId,
};
}
/**
* receiveInfoResponse - action creator
*
* @param {String} infoId
* @param {Object} manifestJson
* @memberof ActionCreators
*/
export function receiveInfoResponse(infoId, infoJson) {
return {
type: ActionTypes.RECEIVE_INFO_RESPONSE,
infoId,
infoJson,
};
}
/**
* receiveInfoResponseFailure - action creator
*
* @param {String} infoId
* @param {String} error
* @memberof ActionCreators
*/
export function receiveInfoResponseFailure(infoId, error) {
return {
type: ActionTypes.RECEIVE_INFO_RESPONSE_FAILURE,
infoId,
error,
};
}
/**
* fetchInfoResponse - action creator
*
* @param {String} infoId
* @memberof ActionCreators
*/
export function fetchInfoResponse(infoId) {
return ((dispatch) => {
dispatch(requestInfoResponse(infoId));
return fetch(infoId)
.then(response => response.json())
.then(json => dispatch(receiveInfoResponse(infoId, json)))
.catch(error => dispatch(receiveInfoResponseFailure(infoId, error)));
});
}
/**
* removeInfoResponse - action creator
*
* @param {String} infoId
* @memberof ActionCreators
*/
export function removeInfoResponse(infoId) {
return { type: ActionTypes.REMOVE_INFO_RESPONSE, infoId };
}
import fetch from 'node-fetch';
import ActionTypes from '../action-types';
/**
* requestInfoResponse - action creator
*
* @param {String} infoId
* @memberof ActionCreators
*/
export function requestInfoResponse(infoId) {
return {
type: ActionTypes.REQUEST_INFO_RESPONSE,
infoId,
};
}
/**
* receiveInfoResponse - action creator
*
* @param {String} infoId
* @param {Object} manifestJson
* @memberof ActionCreators
*/
export function receiveInfoResponse(infoId, infoJson) {
return {
type: ActionTypes.RECEIVE_INFO_RESPONSE,
infoId,
infoJson,
};
}
/**
* receiveInfoResponseFailure - action creator
*
* @param {String} infoId
* @param {String} error
* @memberof ActionCreators
*/
export function receiveInfoResponseFailure(infoId, error) {
return {
type: ActionTypes.RECEIVE_INFO_RESPONSE_FAILURE,
infoId,
error,
};
}
/**
* fetchInfoResponse - action creator
*
* @param {String} infoId
* @memberof ActionCreators
*/
export function fetchInfoResponse(infoId) {
return ((dispatch) => {
dispatch(requestInfoResponse(infoId));
return fetch(infoId)
.then(response => response.json())
.then(json => dispatch(receiveInfoResponse(infoId, json)))
.catch(error => dispatch(receiveInfoResponseFailure(infoId, error)));
});
}
/**
* removeInfoResponse - action creator
*
* @param {String} infoId
* @memberof ActionCreators
*/
export function removeInfoResponse(infoId) {
return { type: ActionTypes.REMOVE_INFO_RESPONSE, infoId };
}
import fetch from 'node-fetch';
import ActionTypes from '../action-types';
/**
* requestManifest - action creator
*
* @param {String} manifestId
* @memberof ActionCreators
*/
export function requestManifest(manifestId) {
return {
type: ActionTypes.REQUEST_MANIFEST,
manifestId,
};
}
/**
* receiveManifest - action creator
*
* @param {String} windowId
* @param {Object} manifestJson
* @memberof ActionCreators
*/
export function receiveManifest(manifestId, manifestJson) {
return {
type: ActionTypes.RECEIVE_MANIFEST,
manifestId,
manifestJson,
};
}
/**
* receiveManifestFailure - action creator
*
* @param {String} windowId
* @param {String} error
* @memberof ActionCreators
*/
export function receiveManifestFailure(manifestId, error) {
return {
type: ActionTypes.RECEIVE_MANIFEST_FAILURE,
manifestId,
error,
};
}
/**
* fetchManifest - action creator
*
* @param {String} manifestId
* @memberof ActionCreators
*/
export function fetchManifest(manifestId) {
return ((dispatch) => {
dispatch(requestManifest(manifestId));
return fetch(manifestId)
.then(response => response.json())
.then(json => dispatch(receiveManifest(manifestId, json)))
.catch(error => dispatch(receiveManifestFailure(manifestId, error)));
});
}
/**
* removeManifest - action creator
*
* @param {String} manifestId
* @memberof ActionCreators
*/
export function removeManifest(manifestId) {
return { type: ActionTypes.REMOVE_MANIFEST, manifestId };
}
import ActionTypes from '../action-types';
/**
* focusWindow - action creator
*
* @param {String} windowId
* @memberof ActionCreators
*/
export function focusWindow(windowId) {
return { type: ActionTypes.FOCUS_WINDOW, windowId };
}
/**
* addWindow - action creator
*
* @param {Object} options
* @memberof ActionCreators
*/
export function addWindow(options) {
const defaultOptions = {
// TODO: Windows should be a hash with id's as keys for easy lookups
// https://redux.js.org/faq/organizing-state#how-do-i-organize-nested-or-duplicate-data-in-my-state
id: `window-${new Date().valueOf()}`,
canvasIndex: 0,
collectionIndex: 0,
manifestId: null,
rangeId: null,
xywh: [0, 0, 400, 400],
rotation: null,
};
return { type: ActionTypes.ADD_WINDOW, payload: Object.assign({}, defaultOptions, options) };
}
/**
* removeWindow - action creator
*
* @param {String} windowId
* @memberof ActionCreators
*/
export function removeWindow(windowId) {
return { type: ActionTypes.REMOVE_WINDOW, windowId };
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment