Skip to content

Commit b471aeb

Browse files
committed
Use context to pass the windowId prop around
1 parent 741416d commit b471aeb

87 files changed

Lines changed: 303 additions & 182 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

__tests__/src/components/CompanionWindowFactory.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import { CompanionWindowFactory } from '../../../src/components/CompanionWindowF
66
function createWrapper({ content = 'closed', ...props }) {
77
return render(
88
<CompanionWindowFactory
9-
windowId="x"
109
id="123"
1110
content={content}
1211
{...props}
1312
/>,
14-
{ preloadedState: { companionWindows: { 123: { content }, thumb: {} }, windows: { x: { thumbnailNavigationId: 'thumb' } } } },
13+
{ preloadedState: { companionWindows: { 123: { content }, thumb: {} }, windows: { x: { thumbnailNavigationId: 'thumb' } } }, windowId: 'x' },
1514
);
1615
}
1716

__tests__/src/components/GalleryView.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ function createWrapper(props) {
99
return render(
1010
<GalleryView
1111
canvases={Utils.parseManifest(manifestJson).getSequences()[0].getCanvases()}
12-
windowId="1234"
1312
selectedCanvasIndex={0}
1413
{...props}
1514
/>,
15+
{ windowId: '1234' },
1616
);
1717
}
1818

__tests__/src/components/PrimaryWindow.test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ function createWrapper(props) {
66
return render(
77
<PrimaryWindow
88
classes={{}}
9-
windowId="xyz"
109
{...props}
1110
/>,
12-
{ preloadedState: { windows: { xyz: { collectionPath: [{}], companionWindowIds: [] } } } },
11+
{ preloadedState: { windows: { xyz: { collectionPath: [{}], companionWindowIds: [] } } }, windowId: 'xyz' },
1312
);
1413
}
1514

@@ -30,8 +29,7 @@ describe('PrimaryWindow', () => {
3029
});
3130
it('should render <GalleryView> if fetching is complete and view is gallery', async () => {
3231
createWrapper({ isFetching: false, view: 'gallery' });
33-
await screen.findByRole('region', { accessibleName: 'gallery section' });
34-
expect(document.querySelector('#xyz-gallery')).toBeInTheDocument(); // eslint-disable-line testing-library/no-node-access
32+
expect(await screen.findByRole('region', { accessibleName: 'gallery section' })).toBeInTheDocument();
3533
});
3634
it('should render <CollectionDialog> and <SelectCollection> if manifest is collection and isCollectionDialogVisible', async () => {
3735
render(<div id="xyz" />);
@@ -40,9 +38,8 @@ describe('PrimaryWindow', () => {
4038
classes={{}}
4139
isCollection
4240
isCollectionDialogVisible
43-
windowId="xyz"
4441
/>,
45-
{ preloadedState: { windows: { xyz: { collectionPath: [{}] } } } },
42+
{ preloadedState: { windows: { xyz: { collectionPath: [{}] } } }, windowId: 'xyz' },
4643
);
4744
await screen.findByRole('button', { accessibleName: 'show collection' });
4845
});

__tests__/src/components/SearchResults.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function createWrapper(props) {
6464
window: {},
6565
},
6666
},
67+
windowId: 'window',
6768
},
6869
);
6970
}

__tests__/src/components/WindowSideBar.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ function createWrapper({ ...props }) {
77
<WindowSideBar
88
classes={{ drawer: 'test-drawer' }}
99
t={k => k}
10-
windowId="xyz"
1110
{...props}
1211
/>,
1312
{
@@ -19,6 +18,7 @@ function createWrapper({ ...props }) {
1918
},
2019
},
2120
},
21+
windowId: 'xyz',
2222
},
2323
);
2424
}

__tests__/src/components/WindowSideBarAnnotationsPanel.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ function createWrapper(props, state) {
1212
classes={{}}
1313
id="xyz"
1414
t={i18next.t}
15-
windowId="abc"
1615
{...props}
1716
/>,
18-
{ preloadedState: { companionWindows: { xyz: { content: 'annotations' } }, windows: { abc: {} }, ...state } },
17+
{ preloadedState: { companionWindows: { xyz: { content: 'annotations' } }, windows: { abc: {} }, ...state }, windowId: 'abc' },
1918
);
2019
}
2120

__tests__/utils/test-utils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
44
import { createStore, applyMiddleware } from 'redux';
55
import thunkMiddleware from 'redux-thunk';
66
import createRootReducer from '../../src/state/reducers/rootReducer';
7+
import WindowContext from '../../src/contexts/WindowContext';
78

89
const rootReducer = createRootReducer();
910

@@ -16,12 +17,19 @@ function renderWithProviders(
1617
preloadedState = {},
1718
// Automatically create a store instance if no store was passed in
1819
store = createStore(rootReducer, preloadedState, applyMiddleware(thunkMiddleware)),
20+
windowId,
1921
...renderOptions
2022
} = {},
2123
) {
24+
const windowContext = windowId ? { id: windowId } : {};
25+
2226
/** :nodoc: */
2327
function Wrapper({ children }) {
24-
return <Provider store={store}>{children}</Provider>;
28+
return (
29+
<WindowContext.Provider value={windowContext}>
30+
<Provider store={store}>{children}</Provider>
31+
</WindowContext.Provider>
32+
);
2533
}
2634

2735
Wrapper.propTypes = {

src/components/AnnotationSettings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,4 @@ AnnotationSettings.propTypes = {
3535
displayAllDisabled: PropTypes.bool.isRequired,
3636
t: PropTypes.func.isRequired,
3737
toggleAnnotationDisplay: PropTypes.func.isRequired,
38-
windowId: PropTypes.string.isRequired, // eslint-disable-line react/no-unused-prop-types
3938
};

src/components/AttributionPanel.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export class AttributionPanel extends Component {
2222
manifestLogo,
2323
requiredStatement,
2424
rights,
25-
windowId,
2625
id,
2726
classes,
2827
t,
@@ -32,7 +31,6 @@ export class AttributionPanel extends Component {
3231
<CompanionWindow
3332
title={t('attributionTitle')}
3433
paperClassName={ns('attribution-panel')}
35-
windowId={windowId}
3634
id={id}
3735
>
3836
<div className={classes.section}>
@@ -85,7 +83,6 @@ AttributionPanel.propTypes = {
8583
})),
8684
rights: PropTypes.arrayOf(PropTypes.string),
8785
t: PropTypes.func,
88-
windowId: PropTypes.string.isRequired,
8986
};
9087

9188
AttributionPanel.defaultProps = {

src/components/CompanionArea.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class CompanionArea extends Component {
6161
<div className={[ns('companion-windows'), companionWindowIds.length > 0 && classes[position], this.areaLayoutClass()].join(' ')} style={{ display: companionAreaOpen ? 'flex' : 'none' }}>
6262
{
6363
companionWindowIds.map(id => (
64-
<CompanionWindowFactory id={id} key={id} windowId={windowId} />
64+
<CompanionWindowFactory id={id} key={id} />
6565
))
6666
}
6767
</div>

0 commit comments

Comments
 (0)