Skip to content

Commit

Permalink
Clean up based on review
Browse files Browse the repository at this point in the history
- Refactor some of the tests with a new utility function to be more readable
  • Loading branch information
mofojed committed May 24, 2024
1 parent 0708745 commit f0d9c49
Showing 1 changed file with 5 additions and 38 deletions.
43 changes: 5 additions & 38 deletions plugins/ui/src/js/src/widget/WidgetHandler.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import type { dh } from '@deephaven/jsapi-types';
import WidgetHandler, { WidgetHandlerProps } from './WidgetHandler';
import { DocumentHandlerProps } from './DocumentHandler';
import {
makeDocumentUpdatedJsonRpcString,
makeJsonRpcResponseString,
makeWidget,
makeWidgetDescriptor,
makeWidgetEventDocumentUpdated,
Expand Down Expand Up @@ -97,22 +95,10 @@ it('updates the document when event is received', async () => {
// Send the initial document
await act(async () => {
// Respond to the setState call first
listener({
detail: {
getDataAsString: jest.fn(() => makeJsonRpcResponseString(1, {})),
exportedObjects: [],
},
});
listener(makeWidgetEventJsonRpcResponse(1));

// Then send the initial document update
listener({
detail: {
getDataAsString: jest.fn(() =>
makeDocumentUpdatedJsonRpcString(initialDocument)
),
exportedObjects: [],
},
});
listener(makeWidgetEventDocumentUpdated(initialDocument));
});

expect(mockDocumentHandler).toHaveBeenCalledWith(
Expand All @@ -129,14 +115,7 @@ it('updates the document when event is received', async () => {

// Send the updated document
await act(async () => {
listener({
detail: {
getDataAsString: jest.fn(() =>
makeDocumentUpdatedJsonRpcString(updatedDocument)
),
exportedObjects: [],
},
});
listener(makeWidgetEventDocumentUpdated(updatedDocument));
});
expect(mockDocumentHandler).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down Expand Up @@ -288,22 +267,10 @@ it('updates the initial data only when fetch has changed', async () => {
// Send the initial document
await act(async () => {
// Respond to the setState call first
listener({
detail: {
getDataAsString: jest.fn(() => makeJsonRpcResponseString(1, {})),
exportedObjects: [],
},
});
listener(makeWidgetEventJsonRpcResponse(1));

// Then send the initial document update
listener({
detail: {
getDataAsString: jest.fn(() =>
makeDocumentUpdatedJsonRpcString(document2)
),
exportedObjects: [],
},
});
listener(makeWidgetEventDocumentUpdated(document2));
});

expect(mockDocumentHandler).toHaveBeenCalledWith(
Expand Down

0 comments on commit f0d9c49

Please sign in to comment.