Skip to content

Commit

Permalink
Rebase off the latest
Browse files Browse the repository at this point in the history
  • Loading branch information
mofojed committed Apr 27, 2023
1 parent 33c9673 commit 8e15103
Show file tree
Hide file tree
Showing 66 changed files with 2,020 additions and 481 deletions.
85 changes: 77 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/app-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
"@deephaven/auth-plugins": "file:../auth-plugins",
"@deephaven/components": "file:../components",
"@deephaven/jsapi-bootstrap": "file:../jsapi-bootstrap",
"@deephaven/jsapi-components": "file:../jsapi-components",
"@deephaven/jsapi-types": "file:../jsapi-types",
"@deephaven/jsapi-utils": "file:../jsapi-utils",
"@deephaven/log": "file:../log",
"@deephaven/redux": "file:../redux",
"@deephaven/react-hooks": "file:../react-hooks",
"@paciolan/remote-component": "2.13.0",
"@paciolan/remote-module-loader": "^3.0.2",
"fira": "mozilla/fira#4.202"
Expand Down
69 changes: 41 additions & 28 deletions packages/app-utils/src/components/AppBootstrap.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { AUTH_HANDLER_TYPE_ANONYMOUS } from '@deephaven/auth-plugins';
import { ApiContext } from '@deephaven/jsapi-bootstrap';
import { BROADCAST_LOGIN_MESSAGE } from '@deephaven/jsapi-utils';
import {
CoreClient,
IdeConnection,
Expand All @@ -19,13 +20,42 @@ jest.mock('../plugins', () => ({
loadModulePlugins: jest.fn(() => mockPluginsPromise),
}));

const mockChannel = {
postMessage: jest.fn(),
};
jest.mock('@deephaven/jsapi-components', () => ({
...jest.requireActual('@deephaven/jsapi-components'),
RefreshTokenBootstrap: jest.fn(({ children }) => children),
useBroadcastChannel: jest.fn(() => mockChannel),
useBroadcastLoginListener: jest.fn(),
}));

const mockChildText = 'Mock Child';
const mockChild = <div>{mockChildText}</div>;

function expectMockChild() {
return expect(screen.queryByText(mockChildText));
}

function renderComponent(client: CoreClient) {
const api = TestUtils.createMockProxy<DhType>({
CoreClient: (jest
.fn()
.mockImplementation(() => client) as unknown) as CoreClient,
});
return render(
<ApiContext.Provider value={api}>
<AppBootstrap apiUrl={API_URL} pluginsUrl={PLUGINS_URL}>
{mockChild}
</AppBootstrap>
</ApiContext.Provider>
);
}

beforeEach(() => {
jest.clearAllMocks();
});

it('should throw if api has not been bootstrapped', () => {
expect(() =>
render(
Expand All @@ -49,19 +79,7 @@ it('should display an error if no login plugin matches the provided auth handler
getAuthConfigValues: mockGetAuthConfigValues,
login: mockLogin,
});
const api = TestUtils.createMockProxy<DhType>({
CoreClient: (jest
.fn()
.mockImplementation(() => client) as unknown) as CoreClient,
});

render(
<ApiContext.Provider value={api}>
<AppBootstrap apiUrl={API_URL} pluginsUrl={PLUGINS_URL}>
{mockChild}
</AppBootstrap>
</ApiContext.Provider>
);
renderComponent(client);
expectMockChild().toBeNull();
expect(mockGetAuthConfigValues).toHaveBeenCalled();

Expand Down Expand Up @@ -105,19 +123,8 @@ it('should log in automatically when the anonymous handler is supported', async
login: mockLogin,
getAsIdeConnection: mockGetAsConnection,
});
const api = TestUtils.createMockProxy<DhType>({
CoreClient: (jest
.fn()
.mockImplementation(() => client) as unknown) as CoreClient,
});

render(
<ApiContext.Provider value={api}>
<AppBootstrap apiUrl={API_URL} pluginsUrl={PLUGINS_URL}>
<div>{mockChild}</div>
</AppBootstrap>
</ApiContext.Provider>
);
renderComponent(client);

expectMockChild().toBeNull();
expect(mockLogin).not.toHaveBeenCalled();
Expand All @@ -127,25 +134,31 @@ it('should log in automatically when the anonymous handler is supported', async
await mockPluginsPromise;
});

expect(mockChannel.postMessage).not.toHaveBeenCalled();
expectMockChild().toBeNull();
expect(mockLogin).toHaveBeenCalled();
expect(screen.queryByTestId('auth-anonymous-loading')).not.toBeNull();
expect(screen.queryByTestId('auth-base-loading')).not.toBeNull();

// Wait for login to complete
await act(async () => {
mockLoginResolve();
});

expect(screen.queryByTestId('auth-anonymous-loading')).toBeNull();
expect(screen.queryByTestId('auth-base-loading')).toBeNull();
expect(screen.queryByTestId('connection-bootstrap-loading')).not.toBeNull();
expect(screen.queryByText(mockChildText)).toBeNull();
expect(mockChannel.postMessage).toHaveBeenCalledWith(
expect.objectContaining({
message: BROADCAST_LOGIN_MESSAGE,
})
);

// Wait for IdeConnection to resolve
await act(async () => {
mockConnectionResolve(mockConnection);
});

expect(screen.queryByTestId('auth-anonymous-loading')).toBeNull();
expect(screen.queryByTestId('auth-base-loading')).toBeNull();
expect(screen.queryByTestId('connection-bootstrap-loading')).toBeNull();
expectMockChild().not.toBeNull();
});
Loading

0 comments on commit 8e15103

Please sign in to comment.