Skip to content

Commit 69ff599

Browse files
committed
fix linting errors and warnings
1 parent f2af778 commit 69ff599

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

client/modules/IDE/components/Preferences/index.test.jsx

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { unmountComponentAtNode } from 'react-dom';
33
import { act } from 'react-dom/test-utils';
4-
import { fireEvent, render, screen, waitFor } from '../../../../test-utils';
4+
import { fireEvent, render, screen } from '../../../../test-utils';
55
import Preferences from './index';
66

77
/* props to pass in:
@@ -57,19 +57,17 @@ const renderComponent = (extraProps = {}, container) => {
5757
setSoundOutput: jest.fn(),
5858
...extraProps
5959
};
60-
render(<Preferences {...props} />, container);
60+
render(<Preferences {...props} />, { container });
6161

6262
return props;
6363
};
6464

65-
// TODOS
66-
// do I need to think about the component functions? like increaseFontSize?
67-
// is that possible?
6865
describe('<Preferences />', () => {
6966
let container = null;
7067
beforeEach(() => {
7168
// setup a DOM element as a render target
7269
container = document.createElement('div');
70+
container.classList.add('testing-container');
7371
document.body.appendChild(container);
7472
});
7573

@@ -82,98 +80,104 @@ describe('<Preferences />', () => {
8280

8381
describe('font tests', () => {
8482
it('font size increase button says increase', () => {
85-
let props;
86-
// render the component with autosave set to false as default
83+
// render the component
8784
act(() => {
88-
props = renderComponent({ fontSize: 12 }, container);
85+
renderComponent({}, container);
8986
});
9087

91-
// get ahold of the radio buttons for toggling autosave
88+
// get ahold of the button for increasing text size
9289
const fontPlusButton = screen.getByTestId('font-plus-button');
9390

94-
// make button says "Increase"
91+
// check that button says says "Increase"
9592
expect(fontPlusButton.textContent.toLowerCase()).toBe('increase');
9693
});
9794

9895
it('increase font size by 2 when clicking plus button', () => {
9996
let props;
100-
// render the component with autosave set to false as default
97+
// render the component with font size set to 12
10198
act(() => {
10299
props = renderComponent({ fontSize: 12 }, container);
103100
});
104101

105-
// get ahold of the radio buttons for toggling autosave
102+
// get ahold of the button for increasing text size
106103
const fontPlusButton = screen.getByTestId('font-plus-button');
107104

105+
// click the button
108106
act(() => {
109107
fireEvent.click(fontPlusButton);
110108
});
111109

110+
// expect that setFontSize has been called once with the argument 14
112111
expect(props.setFontSize).toHaveBeenCalledTimes(1);
113112
expect(props.setFontSize.mock.calls[0][0]).toBe(14);
114113
});
115114

116115
it('font size decrease button says decrease', () => {
117-
let props;
118-
// render the component with autosave set to false as default
116+
// render the component with font size set to 12
119117
act(() => {
120-
props = renderComponent({ fontSize: 12 }, container);
118+
renderComponent({ fontSize: 12 }, container);
121119
});
122120

123-
// get ahold of the radio buttons for toggling autosave
121+
// get ahold of the button for decreasing font size
124122
const fontPlusButton = screen.getByTestId('font-minus-button');
125123

126-
// make button says "decrease"
124+
// check that button says "decrease"
127125
expect(fontPlusButton.textContent.toLowerCase()).toBe('decrease');
128126
});
129127

130128
it('decrease font size by 2 when clicking minus button', () => {
131129
let props;
132-
// render the component with autosave set to false as default
130+
// render the component with font size set to 12
133131
act(() => {
134132
props = renderComponent({ fontSize: 12 }, container);
135133
});
136134

137-
// get ahold of the radio buttons for toggling autosave
135+
// get ahold of the button for decreasing text size
138136
const fontMinusButton = screen.getByTestId('font-minus-button');
139137

138+
// click it
140139
act(() => {
141140
fireEvent.click(fontMinusButton);
142141
});
143142

143+
// expect that setFontSize would have been called once with argument 10
144144
expect(props.setFontSize).toHaveBeenCalledTimes(1);
145145
expect(props.setFontSize.mock.calls[0][0]).toBe(10);
146146
});
147147

148148
it('font text field changes on manual text input', () => {
149149
let props;
150-
// render the component with autosave set to false as default
150+
// render the component with font size set to 12
151151
act(() => {
152152
props = renderComponent({ fontSize: 12 }, container);
153153
});
154154

155-
// get ahold of the radio buttons for toggling autosave
155+
// get ahold of the text field
156156
const input = screen.getByTestId('font-size-text-field');
157157

158+
// change input to 24
158159
act(() => {
159160
fireEvent.change(input, { target: { value: '24' } });
160161
});
162+
163+
// submit form
161164
act(() => {
162165
fireEvent.submit(screen.getByTestId('font-size-form'));
163166
});
164167

168+
// expect that setFontSize was called once with 24
165169
expect(props.setFontSize).toHaveBeenCalledTimes(1);
166170
expect(props.setFontSize.mock.calls[0][0]).toBe(24);
167171
});
168172

169173
it('font size CAN NOT go over 36', () => {
170174
let props;
171-
// render the component with autosave set to false as default
175+
// render the component
172176
act(() => {
173177
props = renderComponent({ fontSize: 12 }, container);
174178
});
175179

176-
// get ahold of the radio buttons for toggling autosave
180+
// get ahold of the text field
177181
const input = screen.getByTestId('font-size-text-field');
178182

179183
act(() => {
@@ -192,12 +196,12 @@ describe('<Preferences />', () => {
192196

193197
it('font size CAN NOT go under 8', () => {
194198
let props;
195-
// render the component with autosave set to false as default
199+
// render the component
196200
act(() => {
197201
props = renderComponent({ fontSize: 12 }, container);
198202
});
199203

200-
// get ahold of the radio buttons for toggling autosave
204+
// get ahold of the text field
201205
const input = screen.getByTestId('font-size-text-field');
202206

203207
act(() => {
@@ -218,38 +222,39 @@ describe('<Preferences />', () => {
218222
// h and then i, but it tests the same idea
219223
it('font size input field does NOT take non-integers', () => {
220224
let props;
221-
// render the component with autosave set to false as default
225+
// render the component
222226
act(() => {
223227
props = renderComponent({ fontSize: 12 }, container);
224228
});
225229

226-
// get ahold of the radio buttons for toggling autosave
230+
// get ahold of the text field
227231
const input = screen.getByTestId('font-size-text-field');
228232

229233
act(() => {
230234
fireEvent.change(input, { target: { value: 'hi' } });
231235
});
232236

237+
// it shouldnt have changed at all
233238
expect(input.value).toBe('12');
234239

240+
// we hit submit
235241
act(() => {
236242
fireEvent.submit(screen.getByTestId('font-size-form'));
237243
});
238244

245+
// it still sets the font size but it's still 12
239246
expect(props.setFontSize).toHaveBeenCalledTimes(1);
240247
expect(props.setFontSize.mock.calls[0][0]).toBe(12);
241248
});
242249

243-
// this case is a bit synthetic because we wouldn't be able to type
244-
// h and then i, but it tests the same idea
245250
it('font size input field does NOT take "-"', () => {
246251
let props;
247-
// render the component with autosave set to false as default
252+
// render the component
248253
act(() => {
249254
props = renderComponent({ fontSize: 12 }, container);
250255
});
251256

252-
// get ahold of the radio buttons for toggling autosave
257+
// get ahold of the text field
253258
const input = screen.getByTestId('font-size-text-field');
254259

255260
act(() => {
@@ -277,7 +282,7 @@ describe('<Preferences />', () => {
277282
expect(checkedRadio.checked).toBe(true);
278283
expect(uncheckedRadio.checked).toBe(false);
279284

280-
// click om the one already selected, the false one
285+
// click on the one already selected
281286
act(() => {
282287
fireEvent.click(checkedRadio);
283288
});
@@ -293,7 +298,7 @@ describe('<Preferences />', () => {
293298
fireEvent.click(uncheckedRadio);
294299
});
295300

296-
// expect that the setAutosave function was called with the value true
301+
// expect that the setter function was called with the value true
297302
expect(setter).toHaveBeenCalledTimes(1);
298303
expect(setter.mock.calls[0][0]).toBe(setterExpectedArgument);
299304
};
@@ -466,10 +471,9 @@ describe('<Preferences />', () => {
466471

467472
describe('can toggle between general settings and accessibility tabs successfully', () => {
468473
it('can toggle sucessfully', () => {
469-
let props;
470474
// render the component with lineNumbers prop set to false
471475
act(() => {
472-
props = renderComponent({}, container);
476+
renderComponent({}, container);
473477
});
474478

475479
// switch to accessibility
@@ -656,9 +660,8 @@ describe('<Preferences />', () => {
656660
});
657661

658662
it('multiple checkboxes can be selected', () => {
659-
let props;
660663
act(() => {
661-
props = renderComponent(
664+
renderComponent(
662665
{ textOutput: true, soundOutput: true, gridOutput: true },
663666
container
664667
);
@@ -679,9 +682,8 @@ describe('<Preferences />', () => {
679682
});
680683

681684
it('none of the checkboxes can be selected', () => {
682-
let props;
683685
act(() => {
684-
props = renderComponent(
686+
renderComponent(
685687
{ textOutput: false, soundOutput: false, gridOutput: false },
686688
container
687689
);

0 commit comments

Comments
 (0)