Skip to content

Commit f2b92f5

Browse files
committed
Don't store the IntlShape in DesignModeCursorDescriptionBuilder
1 parent a884750 commit f2b92f5

5 files changed

Lines changed: 22 additions & 28 deletions

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export class App extends React.Component<AppProps, AppState> {
261261

262262
this.characterDescriptionBuilder = new CharacterDescriptionBuilder();
263263

264-
this.designModeCursorDescriptionBuilder = new DesignModeCursorDescriptionBuilder(this.props.intl);
264+
this.designModeCursorDescriptionBuilder = new DesignModeCursorDescriptionBuilder();
265265

266266
this.programChangeController = new ProgramChangeController(this,
267267
this.props.intl, this.audioManager);

src/CharacterAriaLive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ class CharacterAriaLive extends React.Component<CharacterAriaLiveProps, {}> {
8383
this.props.designModeCursorDescriptionBuilder.buildDescription(
8484
this.props.designModeCursorState,
8585
this.props.world,
86-
this.props.customBackground
86+
this.props.customBackground,
87+
this.props.intl
8788
)
8889
);
8990
}

src/CharacterAriaLive.test.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React from 'react';
44
import Adapter from 'enzyme-adapter-react-16';
55
import { configure, mount } from 'enzyme';
6-
import { createIntl, IntlProvider } from 'react-intl';
6+
import { IntlProvider } from 'react-intl';
77
import CharacterAriaLive from './CharacterAriaLive';
88
import CharacterDescriptionBuilder from './CharacterDescriptionBuilder';
99
import CharacterState from './CharacterState';
@@ -16,12 +16,6 @@ import messages from './messages.json';
1616

1717
configure({ adapter: new Adapter() });
1818

19-
const intl = createIntl({
20-
locale: 'en',
21-
defaultLocale: 'en',
22-
messages: messages.en
23-
});
24-
2519
beforeEach(() => {
2620
const liveRegionDiv = document.createElement('div');
2721
liveRegionDiv.setAttribute('id', 'someAriaLiveRegionId');
@@ -46,7 +40,7 @@ const defaultCharacterAriaLiveProps = {
4640
customBackground: emptyCustomBackground,
4741
customBackgroundDesignMode: false,
4842
characterDescriptionBuilder: new CharacterDescriptionBuilder(),
49-
designModeCursorDescriptionBuilder: new DesignModeCursorDescriptionBuilder(intl),
43+
designModeCursorDescriptionBuilder: new DesignModeCursorDescriptionBuilder(),
5044
message: null
5145
};
5246

src/DesignModeCursorDescriptionBuilder.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ import { getBackgroundSquareDescription } from './Utils';
77
import type { WorldName } from './Worlds';
88

99
export default class DesignModeCursorDescriptionBuilder {
10-
intl: IntlShape;
11-
12-
constructor(intl: IntlShape) {
13-
this.intl = intl;
14-
}
15-
1610
buildDescription(designModeCursorState: DesignModeCursorState,
17-
world: WorldName, customBackground: CustomBackground): string {
11+
world: WorldName, customBackground: CustomBackground,
12+
intl: IntlShape): string {
1813

1914
const columnLabel = designModeCursorState.getColumnLabel();
2015
const rowLabel = designModeCursorState.getRowLabel();
@@ -25,11 +20,11 @@ export default class DesignModeCursorDescriptionBuilder {
2520
designModeCursorState.sceneDimensions,
2621
world,
2722
customBackground,
28-
this.intl
23+
intl
2924
);
3025

3126
if (itemLabel) {
32-
return this.intl.formatMessage(
27+
return intl.formatMessage(
3328
{
3429
id:'DesignModeCursorDescriptionBuilder.positionAndItem'
3530
},
@@ -40,7 +35,7 @@ export default class DesignModeCursorDescriptionBuilder {
4035
}
4136
);
4237
} else {
43-
return this.intl.formatMessage(
38+
return intl.formatMessage(
4439
{
4540
id:'DesignModeCursorDescriptionBuilder.position'
4641
},

src/DesignModeCursorDescriptionBuilder.test.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,46 @@ const sceneDimensions = new SceneDimensions(1, 12, 1, 8);
1717
const emptyCustomBackground = new CustomBackground(sceneDimensions);
1818

1919
test('Space, background description: no, custom background tile: no', () => {
20-
const builder = new DesignModeCursorDescriptionBuilder(intl);
20+
const builder = new DesignModeCursorDescriptionBuilder();
2121
expect(builder.buildDescription(
2222
new DesignModeCursorState(3, 2, sceneDimensions),
2323
'Space',
24-
emptyCustomBackground
24+
emptyCustomBackground,
25+
intl
2526
)).toBe('At C 2');
2627
});
2728

2829
test('Space, background description: no, custom background tile: yes', () => {
29-
const builder = new DesignModeCursorDescriptionBuilder(intl);
30+
const builder = new DesignModeCursorDescriptionBuilder();
3031
expect(builder.buildDescription(
3132
new DesignModeCursorState(3, 2, sceneDimensions),
3233
'Space',
3334
new CustomBackground(sceneDimensions, [
3435
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
3536
'0', '0', '1'
36-
])
37+
]),
38+
intl
3739
)).toBe('At C 2 on wall');
3840
});
3941

4042
test('Space, background description: yes, custom background tile: no', () => {
41-
const builder = new DesignModeCursorDescriptionBuilder(intl);
43+
const builder = new DesignModeCursorDescriptionBuilder();
4244
expect(builder.buildDescription(
4345
new DesignModeCursorState(3, 1, sceneDimensions),
4446
'Space',
45-
emptyCustomBackground
47+
emptyCustomBackground,
48+
intl
4649
)).toBe('At C 1 on the Moon');
4750
});
4851

4952
test('Space, background description: yes, custom background tile: yes', () => {
50-
const builder = new DesignModeCursorDescriptionBuilder(intl);
53+
const builder = new DesignModeCursorDescriptionBuilder();
5154
expect(builder.buildDescription(
5255
new DesignModeCursorState(3, 1, sceneDimensions),
5356
'Space',
5457
new CustomBackground(sceneDimensions, [
5558
'0', '0', '1'
56-
])
59+
]),
60+
intl
5761
)).toBe('At C 1 on wall');
5862
});

0 commit comments

Comments
 (0)