Skip to content

Commit

Permalink
Merge pull request #2944 from lutzhelm/toc-attempt
Browse files Browse the repository at this point in the history
Additional TOC implementations
  • Loading branch information
mejackreed authored Mar 5, 2020
2 parents 91247a9 + 8950dce commit f473552
Show file tree
Hide file tree
Showing 14 changed files with 996 additions and 14 deletions.
254 changes: 254 additions & 0 deletions __tests__/fixtures/version-2/structures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
{
"@context": "http://iiif.io/api/presentation/2/context.json",
"@type": "sc:Manifest",
"@id": "http://foo.test/1/manifest",
"label": "Manifest to be used for SidebarIndexTableOfContents.test.js",
"sequences" : [
{
"@type": "sc:Sequence",
"canvases": [
{
"@id": "http://foo.test/1/canvas/c1",
"@type": "sc:Canvas",
"label": "Canvas: 1"
},
{
"@id": "http://foo.test/1/canvas/c2",
"@type": "sc:Canvas",
"label": "Canvas: 2"
},
{
"@id": "http://foo.test/1/canvas/c3",
"@type": "sc:Canvas",
"label": "Canvas: 3"
},
{
"@id": "http://foo.test/1/canvas/c4",
"@type": "sc:Canvas",
"label": "Canvas: 4"
},
{
"@id": "http://foo.test/1/canvas/c5",
"@type": "sc:Canvas",
"label": "Canvas: 5"
},
{
"@id": "http://foo.test/1/canvas/c6",
"@type": "sc:Canvas",
"label": "Canvas: 6"
},
{
"@id": "http://foo.test/1/canvas/c7",
"@type": "sc:Canvas",
"label": "Canvas: 7"
},
{
"@id": "http://foo.test/1/canvas/c8",
"@type": "sc:Canvas",
"label": "Canvas: 8"
},
{
"@id": "http://foo.test/1/canvas/c9",
"@type": "sc:Canvas",
"label": "Canvas: 9"
},
{
"@id": "http://foo.test/1/canvas/c10",
"@type": "sc:Canvas",
"label": "Canvas: 9"
},
{
"@id": "http://foo.test/1/canvas/c11",
"@type": "sc:Canvas",
"label": "Canvas: 9"
},
{
"@id": "http://foo.test/1/canvas/c12",
"@type": "sc:Canvas",
"label": "Canvas: 9"
}
]
}
],
"structures": [
{
"@id": "http://foo.test/1/range/root",
"@type": "sc:Range",
"viewingHint": "top",
"ranges": [
"http://foo.test/1/range/0-0",
"http://foo.test/1/range/0-1",
"http://foo.test/1/range/0-2"
],
"canvases": []
},
{
"@id": "http://foo.test/1/range/0-0",
"@type": "sc:Range",
"ranges": [
"http://foo.test/1/range/0-0-0",
"http://foo.test/1/range/0-0-1",
"http://foo.test/1/range/0-0-2"
],
"canvases": [
"http://foo.test/1/canvas/c1",
"http://foo.test/1/canvas/c2",
"http://foo.test/1/canvas/c3",
"http://foo.test/1/canvas/c4"
]
},
{
"@id": "http://foo.test/1/range/0-0-0",
"@type": "sc:Range",
"ranges": [],
"canvases": [
"http://foo.test/1/canvas/c1",
"http://foo.test/1/canvas/c2"
]
},
{
"@id": "http://foo.test/1/range/0-0-1",
"@type": "sc:Range",
"ranges": [],
"canvases": [
"http://foo.test/1/canvas/c2",
"http://foo.test/1/canvas/c3"
]
},
{
"@id": "http://foo.test/1/range/0-0-2",
"@type": "sc:Range",
"ranges": [],
"canvases": [
"http://foo.test/1/canvas/c4"
]
},
{
"@id": "http://foo.test/1/range/0-1",
"@type": "sc:Range",
"ranges": [
"http://foo.test/1/range/0-1-0",
"http://foo.test/1/range/0-1-1",
"http://foo.test/1/range/0-1-2"
],
"canvases": []
},
{
"@id": "http://foo.test/1/range/0-1-0",
"@type": "sc:Range",
"ranges": [],
"canvases": []
},
{
"@id": "http://foo.test/1/range/0-1-1",
"@type": "sc:Range",
"ranges": [
"http://foo.test/1/range/0-1-1-0",
"http://foo.test/1/range/0-1-1-1"
],
"canvases": [
"http://foo.test/1/canvas/c6"
]
},
{
"@id": "http://foo.test/1/range/0-1-1-0",
"@type": "sc:Range",
"ranges": [],
"canvases": [
"http://foo.test/1/canvas/c5",
"http://foo.test/1/canvas/c6"
]
},
{
"@id": "http://foo.test/1/range/0-1-1-1",
"@type": "sc:Range",
"ranges": [],
"canvases": [
"http://foo.test/1/canvas/c6",
"http://foo.test/1/canvas/c7",
"http://foo.test/1/canvas/c8"
]
},
{
"@id": "http://foo.test/1/range/0-1-2",
"@type": "sc:Range",
"ranges": [],
"canvases": [
"http://foo.test/1/canvas/c8"
]
},
{
"@id": "http://foo.test/1/range/0-1-2-0",
"@type": "sc:Range",
"ranges": [],
"canvases": [
"http://foo.test/1/canvas/c8",
"http://foo.test/1/canvas/c9"
]
},
{
"@id": "http://foo.test/1/range/0-2",
"@type": "sc:Range",
"ranges": [
"http://foo.test/1/range/0-2-0",
"http://foo.test/1/range/0-2-1",
"http://foo.test/1/range/0-2-2"
],
"canvases": []
},
{
"@id": "http://foo.test/1/range/0-2-0",
"@type": "sc:Range",
"ranges": [],
"canvases": []
},
{
"@id": "http://foo.test/1/range/0-2-1",
"@type": "sc:Range",
"ranges": [
"http://foo.test/1/range/0-2-1-0",
"http://foo.test/1/range/0-2-1-1"
],
"canvases": [
"http://foo.test/1/canvas/c10"
]
},
{
"@id": "http://foo.test/1/range/0-2-1-0",
"@type": "sc:Range",
"ranges": [],
"canvases": [
"http://foo.test/1/canvas/c9"
]
},
{
"@id": "http://foo.test/1/range/0-2-1-1",
"@type": "sc:Range",
"ranges": [],
"canvases": []
},
{
"@id": "http://foo.test/1/range/0-2-2",
"@type": "sc:Range",
"ranges": [
"http://foo.test/1/range/0-2-2-0",
"http://foo.test/1/range/0-2-2-1"
],
"canvases": []
},
{
"@id": "http://foo.test/1/range/0-2-2-0",
"@type": "sc:Range",
"ranges": [],
"canvases": []
},
{
"@id": "http://foo.test/1/range/0-2-2-1",
"@type": "sc:Range",
"ranges": [],
"canvases": [
"http://foo.test/1/canvas/c9"
]
}
]
}
7 changes: 7 additions & 0 deletions __tests__/integration/mirador/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
defaultSideBarPanel: 'canvas'
},
manifests: {
'https://iiif.bodleian.ox.ac.uk/iiif/manifest/390fd0e8-9eae-475d-9564-ed916ab9035c.json': { provider: 'Bodleian Libraries' },
'http://dams.llgc.org.uk/iiif/newspaper/issue/3100021/manifest.json': { provider: 'The National Library of Wales' },
'https://iiif.lib.harvard.edu/manifests/drs:5981093': { provider: 'Houghton Library (Harvard University)' },
'https://cudl.lib.cam.ac.uk/iiif/MS-ADD-03965' : {},
'https://iiif.bodleian.ox.ac.uk/iiif/manifest/ca3dc326-4a7b-479f-a754-5aed9d2f2cb4.json': {},
// 'https://gist.githubusercontent.com/jeffreycwitt/90b33c1c4e119e7a48b7a66ea41a48c1/raw/522b132409d6c67a78f8f26b0ceb7346a52cfe62/test-manifest-with-complicated-toc.json': {},
// 'https://gist.githubusercontent.com/jeffreycwitt/1a75fdb4a97e1c2a98bd35797aad263d/raw/859104cb6cd7bd99f3be668f064066f4b3ba2b29/manifest-with-three-level-deep-toc.json': {},
}
});
</script>
Expand Down
69 changes: 69 additions & 0 deletions __tests__/src/actions/companionWindow.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as actions from '../../../src/state/actions';
import ActionTypes from '../../../src/state/actions/action-types';

jest.mock('../../../src/state/selectors', () => ({
getManuallyExpandedNodeIds: (state, args, expanded) => (expanded ? ['openVisible', 'open'] : ['closedVisible', 'closed']),
getVisibleNodeIds: (state, args) => ['openVisible', 'closedVisible', 'visible'],
}));

describe('companionWindow actions', () => {
describe('addCompanionWindow', () => {
it('should return correct action object', () => {
Expand Down Expand Up @@ -96,4 +101,68 @@ describe('companionWindow actions', () => {
expect(action.windowId).toBe('window');
});
});

describe('toggleNode', () => {
let mockDispatch;
let mockGetState;

beforeEach(() => {
mockDispatch = jest.fn(() => ({}));
mockGetState = jest.fn(() => ({}));
});

it('returns a collapsing action for visible nodes that are not present in the state', () => {
const thunk = actions.toggleNode('window1', 'cw1', 'visible');
thunk(mockDispatch, mockGetState);

const action = mockDispatch.mock.calls[0][0];
expect(action.id).toBe('cw1');
expect(action.windowId).toBe('window1');
expect(action.type).toBe(ActionTypes.TOGGLE_TOC_NODE);
expect(action.payload).toMatchObject({ visible: { expanded: false } });
});

it('returns an expanding action for non visible nodes that are not present in the state', () => {
const thunk = actions.toggleNode('window1', 'cw1', 'foo');
thunk(mockDispatch, mockGetState);

const action = mockDispatch.mock.calls[0][0];
expect(action.id).toBe('cw1');
expect(action.windowId).toBe('window1');
expect(action.type).toBe(ActionTypes.TOGGLE_TOC_NODE);
expect(action.payload).toMatchObject({ foo: { expanded: true } });
});

it('returns a correct action any node that is present in the state', () => {
const openVisibleThunk = actions.toggleNode('window1', 'cw1', 'openVisible');
openVisibleThunk(mockDispatch, mockGetState);

const openThunk = actions.toggleNode('window1', 'cw1', 'open');
openThunk(mockDispatch, mockGetState);

const closedVisibleThunk = actions.toggleNode('window1', 'cw1', 'closedVisible');
closedVisibleThunk(mockDispatch, mockGetState);

const closedThunk = actions.toggleNode('window1', 'cw1', 'closed');
closedThunk(mockDispatch, mockGetState);

const actionForOpenVisible = mockDispatch.mock.calls[0][0];
expect(actionForOpenVisible.id).toBe('cw1');
expect(actionForOpenVisible.windowId).toBe('window1');
expect(actionForOpenVisible.type).toBe(ActionTypes.TOGGLE_TOC_NODE);
expect(actionForOpenVisible.payload).toMatchObject({ openVisible: { expanded: false } });

const actionForOpen = mockDispatch.mock.calls[1][0];
expect(actionForOpen.type).toBe(ActionTypes.TOGGLE_TOC_NODE);
expect(actionForOpen.payload).toMatchObject({ open: { expanded: false } });

const actionForClosedVisible = mockDispatch.mock.calls[2][0];
expect(actionForClosedVisible.type).toBe(ActionTypes.TOGGLE_TOC_NODE);
expect(actionForClosedVisible.payload).toMatchObject({ closedVisible: { expanded: true } });

const actionForClosed = mockDispatch.mock.calls[3][0];
expect(actionForClosed.type).toBe(ActionTypes.TOGGLE_TOC_NODE);
expect(actionForClosed.payload).toMatchObject({ closed: { expanded: true } });
});
});
});
Loading

0 comments on commit f473552

Please sign in to comment.