Skip to content

Commit fd7cc56

Browse files
authored
Merge pull request #4017 from ProjectMirador/useTranslation-hook
Replace withTranslation HOC with hooks and test against actual i18n'd values
2 parents 3c4de40 + bb3cbda commit fd7cc56

208 files changed

Lines changed: 494 additions & 662 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/AccessTokenSender.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { AccessTokenSender } from '../../../src/components/AccessTokenSender';
77
function createWrapper(props) {
88
return render(
99
<AccessTokenSender
10-
t={key => key}
1110
handleAccessTokenMessage={() => {}}
1211
{...props}
1312
/>,

__tests__/src/components/AnnotationSettings.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function createWrapper(props) {
88
<AnnotationSettings
99
displayAll={false}
1010
displayAllDisabled={false}
11-
t={k => k}
1211
toggleAnnotationDisplay={() => {}}
1312
windowId="abc123"
1413
{...props}

__tests__/src/components/AnnotationsOverlay.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const createWrapper = (props) => {
2525
windowId="base"
2626
config={{}}
2727
updateViewport={vi.fn()}
28-
t={k => k}
2928
canvasWorld={new CanvasWorld(canvases)}
3029
{...props}
3130
/>

__tests__/src/components/AttributionPanel.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ function createWrapper(props) {
1212
return render(
1313
<AttributionPanel
1414
id="xyz"
15-
t={str => str}
1615
windowId="window"
1716
{...props}
1817
/>,
@@ -34,14 +33,14 @@ describe('AttributionPanel', () => {
3433
it('renders the rights statement', () => {
3534
createWrapper({ rights: ['http://example.com', 'http://stanford.edu'] });
3635

37-
expect(screen.getByText('rights')).toBeInTheDocument();
36+
expect(screen.getByText('License')).toBeInTheDocument();
3837
expect(screen.getByRole('link', { name: 'http://example.com' })).toHaveAttribute('href', 'http://example.com');
3938
expect(screen.getByRole('link', { name: 'http://stanford.edu' })).toHaveAttribute('href', 'http://stanford.edu');
4039
});
4140

4241
it('does not render the rights statement if it is empty', () => {
4342
createWrapper({ rights: [] });
44-
expect(screen.queryByText('rights')).not.toBeInTheDocument();
43+
expect(screen.queryByText('License')).not.toBeInTheDocument();
4544
});
4645

4746
// Requires canvas to handle img loading.

__tests__/src/components/Branding.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Branding', () => {
1212
it('renders additional items for the wide variant', () => {
1313
render(<Branding variant="wide" />);
1414

15-
expect(screen.getByText('mirador')).toBeInTheDocument();
15+
expect(screen.getByText('Mirador')).toBeInTheDocument();
1616
expect(screen.getByRole('link')).toBeInTheDocument();
1717
});
1818
});

__tests__/src/components/CanvasAnnotations.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { render, screen } from '@tests/utils/test-utils';
22
import userEvent from '@testing-library/user-event';
3-
import { t } from 'i18next';
43

54
import { CanvasAnnotations } from '../../../src/components/CanvasAnnotations';
65
import { ScrollTo } from '../../../src/components/ScrollTo';
@@ -15,7 +14,6 @@ function createWrapper(props) {
1514
index={0}
1615
label="A Canvas Label"
1716
selectAnnotation={() => {}}
18-
t={t}
1917
totalSize={1}
2018
windowId="abc"
2119
{...props}

__tests__/src/components/CanvasInfo.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ describe('CanvasInfo', () => {
1515
canvasDescription="The Canvas Description"
1616
canvasMetadata={metadata}
1717
id="xyz"
18-
t={str => str}
1918
/>,
2019
);
2120
});
2221

2322
it('renders the content in a CollapsibleSection', async () => {
24-
expect(screen.getByRole('heading', { level: 4 })).toHaveTextContent('currentItem');
23+
expect(screen.getByRole('heading', { level: 4 })).toHaveTextContent('Current item');
2524
expect(screen.getByRole('heading', { level: 5 })).toHaveTextContent(/The Canvas Label/);
2625

2726
await user.click(screen.getByRole('button'));

__tests__/src/components/CanvasLayers.test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ function createWrapper(props) {
1414
label="A Canvas Label"
1515
layerMetadata={{}}
1616
layers={[]}
17-
t={t => t}
1817
totalSize={1}
1918
updateLayers={() => {}}
2019
windowId="abc"
@@ -28,7 +27,7 @@ describe('CanvasLayers', () => {
2827
it('displays the canvas label', () => {
2928
createWrapper({ totalSize: 2 });
3029

31-
expect(screen.getByText('annotationCanvasLabel', { container: '.MuiTypography-overline' })).toBeInTheDocument();
30+
expect(screen.getByText('Left: [A Canvas Label]', { container: '.MuiTypography-overline' })).toBeInTheDocument();
3231
});
3332
});
3433

@@ -44,9 +43,9 @@ describe('CanvasLayers', () => {
4443
expect(screen.getAllByRole('listitem')[0]).toHaveTextContent('1');
4544
expect(screen.getAllByRole('listitem')[1]).toHaveTextContent('2');
4645

47-
expect(screen.getAllByRole('button', { name: 'layer_hide' }).length).toEqual(2);
48-
expect(screen.getAllByRole('button', { name: 'layer_moveToTop' }).length).toEqual(2);
49-
expect(screen.getAllByRole('spinbutton', { name: 'layer_opacity' }).length).toEqual(2);
46+
expect(screen.getAllByRole('button', { name: 'Hide layer' }).length).toEqual(2);
47+
expect(screen.getAllByRole('button', { name: 'Move layer to top' }).length).toEqual(2);
48+
expect(screen.getAllByRole('spinbutton', { name: 'Layer opacity' }).length).toEqual(2);
5049
});
5150

5251
it('handles drag + drop of layers', async () => {
@@ -99,7 +98,7 @@ describe('CanvasLayers', () => {
9998
});
10099

101100
it('has a button for moving a layer to the top', async () => {
102-
await user.click(screen.getAllByLabelText('layer_moveToTop')[1]);
101+
await user.click(screen.getAllByLabelText('Move layer to top')[1]);
103102

104103
expect(updateLayers).toHaveBeenCalledWith('abc', 'https://prtd.app/hamilton/canvas/p1.json', {
105104
'https://prtd.app/image/iiif/2/hamilton%2fHL_524_1r_00_PSC/full/862,1024/0/default.jpg': {
@@ -112,7 +111,7 @@ describe('CanvasLayers', () => {
112111
});
113112

114113
it('has a button for toggling visibility', async () => {
115-
await user.click(screen.getAllByLabelText('layer_hide')[1]);
114+
await user.click(screen.getAllByLabelText('Hide layer')[1]);
116115

117116
expect(updateLayers).toHaveBeenCalledWith('abc', 'https://prtd.app/hamilton/canvas/p1.json', {
118117
'https://prtd.app/image/iiif/2/hamilton%2fHL_524_1r_00_TS_Blue/full/862,1024/0/default.png': {

__tests__/src/components/ChangeThemeDialog.test.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ function createWrapper(props) {
1212
handleClose={() => {}}
1313
open
1414
setSelectedTheme={() => {}}
15-
t={t => (t)}
1615
selectedTheme="light"
1716
themeIds={['light', 'dark']}
1817
{...props}
@@ -37,16 +36,16 @@ describe('ChangeThemeDialog', () => {
3736
const menuItems = screen.queryAllByRole('menuitem');
3837

3938
expect(menuItems.length).toBe(2);
40-
expect(menuItems[0]).toHaveTextContent('light');
41-
expect(menuItems[1]).toHaveTextContent('dark');
39+
expect(menuItems[0]).toHaveTextContent('Light theme');
40+
expect(menuItems[1]).toHaveTextContent('Dark theme');
4241
});
4342

4443
it('shows up theme selection properly', async () => {
4544
const user = userEvent.setup();
4645
const setSelectedTheme = vi.fn();
4746

4847
createWrapper({ setSelectedTheme });
49-
const menuItem = screen.getByRole('menuitem', { name: 'light' });
48+
const menuItem = screen.getByRole('menuitem', { name: 'Light theme' });
5049
expect(menuItem).toBeInTheDocument();
5150

5251
await user.click(menuItem);
@@ -58,7 +57,7 @@ describe('ChangeThemeDialog', () => {
5857
it('focuses the selected item', () => {
5958
createWrapper({ selectedTheme: 'light' });
6059

61-
const menuItem = screen.getByRole('menuitem', { name: 'light' });
60+
const menuItem = screen.getByRole('menuitem', { name: 'Light theme' });
6261
expect(menuItem).toHaveFocus();
6362
});
6463
});

__tests__/src/components/CollapsibleSection.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ function createWrapper(props) {
1111
classes={{}}
1212
id="abc123"
1313
label="The Section Label"
14-
t={k => k}
1514
{...props}
1615
>
1716
<span data-testid="child">Child content</span>
@@ -29,9 +28,9 @@ describe('CollapsibleSection', () => {
2928
});
3029

3130
it('renders the appropriate i18n label based on open state', async () => {
32-
expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'collapseSection');
31+
expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'Collapse "The Section Label" section');
3332
await userEvent.click(screen.getByRole('button'));
34-
expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'expandSection');
33+
expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'Expand "The Section Label" section');
3534
});
3635

3736
it('displays children based on the open state', async () => {

0 commit comments

Comments
 (0)