Skip to content

Commit 302bc31

Browse files
committed
test: Add test for TextField to throw when explanation is defined but label is not
1 parent 7042b96 commit 302bc31

2 files changed

Lines changed: 99 additions & 68 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { TextField } from './TextField';
2+
import { render } from 'src/tests/browsertest-utils';
3+
4+
test('Throws if providing explanation without label', async () => {
5+
expect(() => render(<TextField explanation="test explanation" />)).toThrow();
6+
});

src/organisms/TopBar/Account/ImpersonateMenu/CreateOrEditUser/CreateOrEditUser.test.tsx

Lines changed: 93 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from 'src/tests/browsertest-utils';
1111
import { FAKE_FIELDS, FAKE_ROLES, FAKE_WELLS } from 'src/tests/mockHandlers';
1212

13-
test('Able to open/close create new', async () => {
13+
test.sequential('Able to open/close create new', async () => {
1414
renderWithProviders(<Account />);
1515
const user = userEvent.setup();
1616
const button = screen.getByRole('button');
@@ -31,7 +31,7 @@ test('Able to open/close create new', async () => {
3131
await user.click(screen.getByRole('button', { name: /cancel/i }));
3232
});
3333

34-
test(
34+
test.sequential(
3535
'Able to open/close edit',
3636
async () => {
3737
renderWithProviders(
@@ -79,7 +79,7 @@ test(
7979
{ timeout: 6000 }
8080
);
8181

82-
test('OnClose runs as expected in create new', async () => {
82+
test.sequential('OnClose runs as expected in create new', async () => {
8383
renderWithProviders(
8484
<>
8585
<Account />
@@ -172,92 +172,117 @@ test.each(['email', 'no-email', 'field-well'])(
172172
{ timeout: 8000 }
173173
);
174174

175-
test('Initially selected field and wells works as expected', async () => {
176-
renderWithProviders(
177-
<Account availableFields={FAKE_FIELDS} availableWells={FAKE_WELLS} />
178-
);
179-
const user = userEvent.setup();
175+
test.sequential(
176+
'Initially selected field and wells works as expected',
177+
async () => {
178+
renderWithProviders(
179+
<Account availableFields={FAKE_FIELDS} availableWells={FAKE_WELLS} />
180+
);
181+
const user = userEvent.setup();
180182

181-
await user.click(screen.getByRole('button'));
182-
await user.click(await screen.findByRole('button', { name: 'Impersonate' }));
183+
await user.click(screen.getByRole('button'));
184+
await user.click(
185+
await screen.findByRole('button', { name: 'Impersonate' })
186+
);
183187

184-
const menuItems = await screen.findAllByTestId('impersonation-user');
185-
expect(menuItems.length).toBeGreaterThan(0);
188+
const menuItems = await screen.findAllByTestId('impersonation-user');
189+
expect(menuItems.length).toBeGreaterThan(0);
186190

187-
// Click edit on the first one
188-
await user.click(within(menuItems[0]).getByRole('button'));
189-
await user.click(screen.getByRole('button', { name: /edit user/i }));
191+
// Click edit on the first one
192+
await user.click(within(menuItems[0]).getByRole('button'));
193+
await user.click(screen.getByRole('button', { name: /edit user/i }));
190194

191-
await waitForElementToBeRemoved(() => screen.getAllByRole('progressbar'));
195+
await waitForElementToBeRemoved(() => screen.getAllByRole('progressbar'));
192196

193-
const fieldLabel = await screen.findByRole('combobox', { name: /field/i });
194-
expect(fieldLabel).toBeInTheDocument();
195-
});
197+
const fieldLabel = await screen.findByRole('combobox', { name: /field/i });
198+
expect(fieldLabel).toBeInTheDocument();
199+
}
200+
);
196201

197-
test('shows field selector if availableFields array has items', async () => {
198-
renderWithProviders(
199-
<Account
200-
availableFields={[
201-
...FAKE_FIELDS,
202-
{
203-
country: null,
204-
uuid: null,
205-
name: null,
206-
},
207-
]}
208-
/>
209-
);
210-
const user = userEvent.setup();
202+
test.sequential(
203+
'shows field selector if availableFields array has items',
204+
async () => {
205+
renderWithProviders(
206+
<Account
207+
availableFields={[
208+
...FAKE_FIELDS,
209+
{
210+
country: null,
211+
uuid: null,
212+
name: null,
213+
},
214+
]}
215+
/>
216+
);
217+
const user = userEvent.setup();
211218

212-
await user.click(screen.getByRole('button'));
213-
await user.click(await screen.findByRole('button', { name: 'Impersonate' }));
219+
await user.click(screen.getByRole('button'));
220+
await user.click(
221+
await screen.findByRole('button', { name: 'Impersonate' })
222+
);
214223

215-
await user.click(screen.getByRole('button', { name: /create/i }));
224+
await user.click(screen.getByRole('button', { name: /create/i }));
216225

217-
const fieldLabel = await screen.findByRole('combobox', { name: /field/i });
218-
expect(fieldLabel).toBeInTheDocument();
219-
});
226+
const fieldLabel = await screen.findByRole('combobox', { name: /field/i });
227+
expect(fieldLabel).toBeInTheDocument();
228+
}
229+
);
220230

221-
test('does not show field selector if availableFields array is empty', async () => {
222-
renderWithProviders(<Account availableFields={[]} />);
223-
const user = userEvent.setup();
231+
test.sequential(
232+
'does not show field selector if availableFields array is empty',
233+
async () => {
234+
renderWithProviders(<Account availableFields={[]} />);
235+
const user = userEvent.setup();
224236

225-
await user.click(screen.getByRole('button'));
226-
await user.click(await screen.findByRole('button', { name: 'Impersonate' }));
237+
await user.click(screen.getByRole('button'));
238+
await user.click(
239+
await screen.findByRole('button', { name: 'Impersonate' })
240+
);
227241

228-
await user.click(screen.getByRole('button', { name: /create/i }));
242+
await user.click(screen.getByRole('button', { name: /create/i }));
229243

230-
const fieldLabel = screen.queryByRole('combobox', { name: /field/i });
231-
expect(fieldLabel).not.toBeInTheDocument();
232-
});
244+
const fieldLabel = screen.queryByRole('combobox', { name: /field/i });
245+
expect(fieldLabel).not.toBeInTheDocument();
246+
}
247+
);
233248

234-
test('shows well selector if availableWells array has items', async () => {
235-
renderWithProviders(<Account availableWells={FAKE_WELLS} />);
236-
const user = userEvent.setup();
249+
test.sequential(
250+
'shows well selector if availableWells array has items',
251+
async () => {
252+
renderWithProviders(<Account availableWells={FAKE_WELLS} />);
253+
const user = userEvent.setup();
237254

238-
await user.click(screen.getByRole('button'));
239-
await user.click(await screen.findByRole('button', { name: 'Impersonate' }));
255+
await user.click(screen.getByRole('button'));
256+
await user.click(
257+
await screen.findByRole('button', { name: 'Impersonate' })
258+
);
240259

241-
await user.click(screen.getByRole('button', { name: /create/i }));
260+
await user.click(screen.getByRole('button', { name: /create/i }));
242261

243-
const wellSelect = await screen.findByRole('combobox', { name: /well/i });
244-
expect(wellSelect).toBeInTheDocument();
245-
});
262+
const wellSelect = await screen.findByRole('combobox', { name: /well/i });
263+
expect(wellSelect).toBeInTheDocument();
264+
}
265+
);
246266

247-
test('does not show well selector if availableWells array is empty', async () => {
248-
renderWithProviders(<Account availableWells={[]} />);
249-
const user = userEvent.setup();
267+
test.sequential(
268+
'does not show well selector if availableWells array is empty',
269+
async () => {
270+
renderWithProviders(<Account availableWells={[]} />);
271+
const user = userEvent.setup();
250272

251-
await user.click(screen.getByRole('button'));
252-
await user.click(await screen.findByRole('button', { name: 'Impersonate' }));
273+
await user.click(screen.getByRole('button'));
274+
await user.click(
275+
await screen.findByRole('button', { name: 'Impersonate' })
276+
);
253277

254-
await user.click(screen.getByRole('button', { name: /create/i }));
278+
await user.click(screen.getByRole('button', { name: /create/i }));
255279

256-
const wellSelect = screen.queryByRole('combobox', { name: /well/i });
257-
expect(wellSelect).not.toBeInTheDocument();
258-
});
280+
const wellSelect = screen.queryByRole('combobox', { name: /well/i });
281+
expect(wellSelect).not.toBeInTheDocument();
282+
}
283+
);
259284

260-
test('Edit another user clears the form as expected', async () => {
285+
test.sequential('Edit another user clears the form as expected', async () => {
261286
renderWithProviders(<Account />);
262287
const user = userEvent.setup();
263288
const button = screen.getByRole('button');
@@ -377,7 +402,7 @@ test.each(['email', 'no-email', 'field-well'])(
377402
{ timeout: 8000 }
378403
);
379404

380-
test(
405+
test.sequential(
381406
'Able to edit active user impersonation',
382407
async () => {
383408
renderWithProviders(<Account />);

0 commit comments

Comments
 (0)