Skip to content
Snippets Groups Projects
Commit 2cddf26d authored by Jack Reed's avatar Jack Reed Committed by Chris Beer
Browse files

Add tests around sagas updates for window

parent fd2ba187
Branches
Tags
No related merge requests found
...@@ -17,6 +17,7 @@ import { ...@@ -17,6 +17,7 @@ import {
} from '../../../src/state/selectors'; } from '../../../src/state/selectors';
import { fetchManifests } from '../../../src/state/sagas/iiif'; import { fetchManifests } from '../../../src/state/sagas/iiif';
import { import {
determineAndShowCollectionDialog,
fetchWindowManifest, fetchWindowManifest,
setWindowDefaultSearchQuery, setWindowDefaultSearchQuery,
setWindowStartingCanvas, setWindowStartingCanvas,
...@@ -30,6 +31,7 @@ import { ...@@ -30,6 +31,7 @@ import {
setCollectionPath, setCollectionPath,
} from '../../../src/state/sagas/windows'; } from '../../../src/state/sagas/windows';
import fixture from '../../fixtures/version-2/019.json'; import fixture from '../../fixtures/version-2/019.json';
import collectionFixture from '../../fixtures/version-2/collection.json';
describe('window-level sagas', () => { describe('window-level sagas', () => {
describe('fetchWindowManifest', () => { describe('fetchWindowManifest', () => {
...@@ -40,10 +42,12 @@ describe('window-level sagas', () => { ...@@ -40,10 +42,12 @@ describe('window-level sagas', () => {
manifestId: 'manifest.json', manifestId: 'manifest.json',
}, },
}; };
const manifest = Utils.parseManifest(fixture);
return expectSaga(fetchWindowManifest, action) return expectSaga(fetchWindowManifest, action)
.provide([ .provide([
[select(getManifests), {}], [select(getManifests), {}],
[select(getManifestoInstance, { manifestId: 'manifest.json' }), manifest],
[call(fetchManifests, 'manifest.json'), {}], [call(fetchManifests, 'manifest.json'), {}],
[call(setWindowStartingCanvas, action)], [call(setWindowStartingCanvas, action)],
[call(setWindowDefaultSearchQuery, action)], [call(setWindowDefaultSearchQuery, action)],
...@@ -66,9 +70,11 @@ describe('window-level sagas', () => { ...@@ -66,9 +70,11 @@ describe('window-level sagas', () => {
[call(setWindowStartingCanvas, action)], [call(setWindowStartingCanvas, action)],
[call(setWindowDefaultSearchQuery, action)], [call(setWindowDefaultSearchQuery, action)],
[call(setCollectionPath, { manifestId: 'manifest.json', windowId: 'x' })], [call(setCollectionPath, { manifestId: 'manifest.json', windowId: 'x' })],
[call(determineAndShowCollectionDialog, 'manifest.json', 'x')],
]) ])
.call(setWindowStartingCanvas, action) .call(setWindowStartingCanvas, action)
.call(setWindowDefaultSearchQuery, action) .call(setWindowDefaultSearchQuery, action)
.call(determineAndShowCollectionDialog, 'manifest.json', 'x')
.run(); .run();
}); });
}); });
...@@ -434,4 +440,42 @@ describe('window-level sagas', () => { ...@@ -434,4 +440,42 @@ describe('window-level sagas', () => {
.run(); .run();
}); });
}); });
describe('determineAndShowCollectionDialog', () => {
it('shows the collection dialog if it is a collection', () => {
const manifest = Utils.parseManifest(collectionFixture);
return expectSaga(determineAndShowCollectionDialog, 'manifest.json', 'x')
.provide([
[select(getManifestoInstance, { manifestId: 'manifest.json' }), manifest],
])
.put.like({
action: {
collectionPath: [],
manifestId: 'manifest.json',
type: 'mirador/SHOW_WINDOW_COLLECTION_DIALOG',
windowId: 'x',
},
})
.run();
});
it('does nothing if not a collection', () => {
const manifest = Utils.parseManifest(fixture);
return expectSaga(determineAndShowCollectionDialog, 'manifest.json', 'x')
.provide([
[select(getManifestoInstance, { manifestId: 'manifest.json' }), manifest],
])
.not.put.like({
action: {
collectionPath: [],
manifestId: 'manifest.json',
type: 'mirador/SHOW_WINDOW_COLLECTION_DIALOG',
windowId: 'x',
},
})
.run();
});
});
}); });
...@@ -235,8 +235,7 @@ export function* fetchInfoResponses({ visibleCanvases: visibleCanvasIds, windowI ...@@ -235,8 +235,7 @@ export function* fetchInfoResponses({ visibleCanvases: visibleCanvasIds, windowI
/** */ /** */
export function* determineAndShowCollectionDialog(manifestId, windowId) { export function* determineAndShowCollectionDialog(manifestId, windowId) {
const manifestoInstance = yield select(getManifestoInstance, { manifestId }); const manifestoInstance = yield select(getManifestoInstance, { manifestId });
const isCollection = manifestoInstance.isCollection(); if (manifestoInstance && manifestoInstance.isCollection()) {
if (isCollection) {
yield put(showWindowCollectionDialog(manifestId, [], windowId)); yield put(showWindowCollectionDialog(manifestId, [], windowId));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment