Skip to content

Commit 29a21d4

Browse files
committed
Enforce more strict calling of port list event handlers
Ensure the event handlers are called as expected and not twice for example.
1 parent d18d4a6 commit 29a21d4

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/web/pages/portlists/__tests__/PortListComponent.test.jsx

+15-11
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ describe('Port List Component tests', () => {
159159
const saveButton = getDialogSaveButton();
160160
fireEvent.click(saveButton);
161161
await wait();
162+
162163
expect(screen.queryByText('New Port List')).not.toBeInTheDocument();
163164
expect(onCreated).toHaveBeenCalledWith(newPortList);
164165
expect(onCreateError).not.toHaveBeenCalled();
@@ -324,7 +325,7 @@ describe('Port List Component tests', () => {
324325
const savePortListButton = getDialogSaveButton(portListDialog);
325326
fireEvent.click(savePortListButton);
326327
await wait();
327-
expect(createPortRange).toHaveBeenCalledWith({
328+
expect(createPortRange).toHaveBeenCalledExactlyOnceWith({
328329
end: 20,
329330
entityType: 'portrange',
330331
id: '123',
@@ -335,7 +336,7 @@ describe('Port List Component tests', () => {
335336
port_type: 'tcp',
336337
protocol_type: 'tcp',
337338
});
338-
expect(save).toHaveBeenCalledWith({
339+
expect(save).toHaveBeenCalledExactlyOnceWith({
339340
comment: '',
340341
from_file: 0,
341342
id: '123',
@@ -352,7 +353,7 @@ describe('Port List Component tests', () => {
352353
},
353354
],
354355
});
355-
expect(onSaved).toHaveBeenCalledWith(portList);
356+
expect(onSaved).toHaveBeenCalledExactlyOnceWith(portList);
356357
expect(onSaveError).not.toHaveBeenCalled();
357358
expect(onInteraction).toHaveBeenCalled();
358359
expect(screen.queryByText('Edit Port List foo')).not.toBeInTheDocument();
@@ -410,18 +411,20 @@ describe('Port List Component tests', () => {
410411
const savePortListButton = getDialogSaveButton();
411412
fireEvent.click(savePortListButton);
412413
await wait();
413-
expect(deletePortRange).toHaveBeenCalledWith(portList.port_ranges[0]);
414-
expect(onSaveError).not.toHaveBeenCalled();
415414

416-
expect(save).toHaveBeenCalledWith({
415+
expect(deletePortRange).toHaveBeenCalledExactlyOnceWith(
416+
portList.port_ranges[0],
417+
);
418+
expect(onSaveError).not.toHaveBeenCalled();
419+
expect(save).toHaveBeenCalledExactlyOnceWith({
417420
comment: '',
418421
from_file: 0,
419422
id: '123',
420423
name: 'foo',
421424
port_range: 'T:1-5,7,9,U:1-3,5,7,9',
422425
port_ranges: [],
423426
});
424-
expect(onSaved).toHaveBeenCalledWith(portList);
427+
expect(onSaved).toHaveBeenCalledExactlyOnceWith(portList);
425428
expect(onInteraction).toHaveBeenCalled();
426429
expect(screen.queryByText('Edit Port List foo')).not.toBeInTheDocument();
427430
});
@@ -460,9 +463,10 @@ describe('Port List Component tests', () => {
460463
const saveButton = getDialogSaveButton();
461464
fireEvent.click(saveButton);
462465
await wait();
466+
463467
expect(screen.queryByText('Edit Port List foo')).not.toBeInTheDocument();
464468
expect(onSaved).not.toHaveBeenCalled();
465-
expect(onSaveError).toHaveBeenCalledWith(error);
469+
expect(onSaveError).toHaveBeenCalledExactlyOnceWith(error);
466470
expect(onInteraction).toHaveBeenCalled();
467471
});
468472

@@ -528,7 +532,7 @@ describe('Port List Component tests', () => {
528532

529533
fireEvent.click(screen.getByTestId('button'));
530534
await wait();
531-
expect(onCloned).toHaveBeenCalledWith(cloned);
535+
expect(onCloned).toHaveBeenCalledExactlyOnceWith(cloned);
532536
expect(onCloneError).not.toHaveBeenCalled();
533537
expect(onInteraction).toHaveBeenCalledOnce();
534538
});
@@ -559,7 +563,7 @@ describe('Port List Component tests', () => {
559563

560564
fireEvent.click(screen.getByTestId('button'));
561565
await wait();
562-
expect(onCloneError).toHaveBeenCalledWith(error);
566+
expect(onCloneError).toHaveBeenCalledExactlyOnceWith(error);
563567
expect(onCloned).not.toHaveBeenCalled();
564568
expect(onInteraction).toHaveBeenCalledOnce();
565569
});
@@ -619,7 +623,7 @@ describe('Port List Component tests', () => {
619623

620624
fireEvent.click(screen.getByTestId('button'));
621625
await wait();
622-
expect(onDeleteError).toHaveBeenCalledWith(error);
626+
expect(onDeleteError).toHaveBeenCalledExactlyOnceWith(error);
623627
expect(onDeleted).not.toHaveBeenCalled();
624628
expect(onInteraction).toHaveBeenCalledOnce();
625629
});

0 commit comments

Comments
 (0)