Skip to content

Commit d88ce5c

Browse files
committed
Use context to pass the windowId prop around
1 parent 41e2a86 commit d88ce5c

File tree

87 files changed

+269
-158
lines changed

Some content is hidden

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

87 files changed

+269
-158
lines changed

__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 & 8 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,10 +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.findByTestId('test-window');
34-
await waitFor(() => {
35-
expect(document.querySelector('#xyz-gallery')).toBeInTheDocument(); // eslint-disable-line testing-library/no-node-access
36-
});
32+
expect(await screen.findByRole('region', { accessibleName: 'gallery section' })).toBeInTheDocument();
3733
});
3834
it('should render <CollectionDialog> and <SelectCollection> if manifest is collection and isCollectionDialogVisible', async () => {
3935
render(<div id="xyz" />);
@@ -42,9 +38,8 @@ describe('PrimaryWindow', () => {
4238
classes={{}}
4339
isCollection
4440
isCollectionDialogVisible
45-
windowId="xyz"
4641
/>,
47-
{ preloadedState: { windows: { xyz: { collectionPath: [{}] } } } },
42+
{ preloadedState: { windows: { xyz: { collectionPath: [{}] } } }, windowId: 'xyz' },
4843
);
4944
await screen.findByRole('button', { accessibleName: 'show collection' });
5045
});

__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
@@ -5,7 +5,6 @@ import { WindowSideBar } from '../../../src/components/WindowSideBar';
55
function createWrapper({ ...props }) {
66
return render(
77
<WindowSideBar
8-
windowId="xyz"
98
{...props}
109
/>,
1110
{
@@ -17,6 +16,7 @@ function createWrapper({ ...props }) {
1716
},
1817
},
1918
},
19+
windowId: 'xyz',
2020
},
2121
);
2222
}

__tests__/src/components/WindowSideBarAnnotationsPanel.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ function createWrapper(props, state) {
99
annotationCount={4}
1010
classes={{}}
1111
id="xyz"
12-
windowId="abc"
1312
{...props}
1413
/>,
15-
{ preloadedState: { companionWindows: { xyz: { content: 'annotations' } }, windows: { abc: {} }, ...state } },
14+
{ preloadedState: { companionWindows: { xyz: { content: 'annotations' } }, windows: { abc: {} }, ...state }, windowId: 'abc' },
1615
);
1716
}
1817

__tests__/utils/test-utils.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Mirador from '../../src/index';
1414

1515
export * from '@testing-library/react';
1616
export { renderWithProviders as render };
17+
import WindowContext from '../../src/contexts/WindowContext';
1718

1819
const rootReducer = createRootReducer();
1920
const theme = createTheme(settings.theme);
@@ -29,19 +30,24 @@ function renderWithProviders(
2930
preloadedState = {},
3031
// Automatically create a store instance if no store was passed in
3132
store = createStore(rootReducer, preloadedState, applyMiddleware(thunk)),
33+
windowId,
3234
...renderOptions
3335
} = {},
3436
) {
37+
const windowContext = windowId ? { id: windowId } : {};
38+
3539
/** :nodoc: */
3640
function Wrapper({ children }) {
3741
return (
38-
<I18nextProvider i18n={i18n}>
39-
<ThemeProvider theme={theme}>
40-
<Provider store={store}>
41-
{children}
42-
</Provider>
43-
</ThemeProvider>
44-
</I18nextProvider>
42+
<WindowContext.Provider value={windowContext}>
43+
<I18nextProvider i18n={i18n}>
44+
<ThemeProvider theme={theme}>
45+
<Provider store={store}>
46+
{children}
47+
</Provider>
48+
</ThemeProvider>
49+
</I18nextProvider>
50+
</WindowContext.Provider>
4551
);
4652
}
4753

src/components/AnnotationSettings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@ AnnotationSettings.propTypes = {
2828
displayAll: PropTypes.bool.isRequired,
2929
displayAllDisabled: PropTypes.bool.isRequired,
3030
toggleAnnotationDisplay: PropTypes.func.isRequired,
31-
windowId: PropTypes.string.isRequired, // eslint-disable-line react/no-unused-prop-types
3231
};

src/components/AttributionPanel.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export function AttributionPanel({
2626
manifestLogo = null,
2727
requiredStatement = null,
2828
rights = null,
29-
windowId,
3029
id,
3130
}) {
3231
const { t } = useTranslation();
@@ -37,7 +36,6 @@ export function AttributionPanel({
3736
<CompanionWindow
3837
title={t('attributionTitle')}
3938
paperClassName={ns('attribution-panel')}
40-
windowId={windowId}
4139
id={id}
4240
>
4341
<CompanionWindowSection>
@@ -86,5 +84,4 @@ AttributionPanel.propTypes = {
8684
value: PropTypes.string,
8785
})),
8886
rights: PropTypes.arrayOf(PropTypes.string),
89-
windowId: PropTypes.string.isRequired,
9087
};

src/components/CompanionArea.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function CompanionArea({
9797
className={`${ns('companion-windows')}`}
9898
>
9999
{companionWindowIds.map((id) => (
100-
<CompanionWindowFactory id={id} key={id} windowId={windowId} />
100+
<CompanionWindowFactory id={id} key={id} />
101101
))}
102102
</Container>
103103
</Slide>

0 commit comments

Comments
 (0)