Skip to content

Commit

Permalink
fix: links for Recent Submissions on Dashboard (#9651)
Browse files Browse the repository at this point in the history
Co-authored-by: John Kim <[email protected]>
  • Loading branch information
thiagodallacqua-hpe and johnkim-det authored Jul 22, 2024
1 parent 1c7f4b5 commit 88b93a2
Show file tree
Hide file tree
Showing 7 changed files with 430 additions and 18 deletions.
60 changes: 60 additions & 0 deletions webui/react/src/components/JupyterLabButton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import UIProvider, { DefaultTheme } from 'hew/Theme';

import { ThemeProvider } from 'components/ThemeProvider';

import JupyterLabButton from './JupyterLabButton';

const SIMPLE_CONFIG_TEMPLATE_TEXT = 'Template';

vi.mock('services/api', () => ({
getTaskTemplates: () => Promise.resolve([]),
getWorkspaces: () => Promise.resolve({ workspaces: [] }),
}));

vi.mock('hooks/useSettings', async (importOriginal) => {
const useSettings = vi.fn(() => {
const settings = {
jupyterLab: {
alt: false,
ctrl: false,
key: 'L',
meta: true,
shift: true,
},
};
return { isLoading: false, settings };
});

return {
__esModule: true,
...(await importOriginal<typeof import('hooks/useSettings')>()),
useSettings,
};
});

const user = userEvent.setup();

const setup = (enabled: boolean) => {
render(
<UIProvider theme={DefaultTheme.Light}>
<ThemeProvider>
<JupyterLabButton enabled={enabled} />
</ThemeProvider>
</UIProvider>,
);
};

describe('Dashboard', () => {
it('shows disabled state', () => {
setup(false);
expect(screen.getByRole('button')).toBeDisabled();
});

it('opens JupyterLabModal', async () => {
setup(true);
await user.click(screen.getByRole('button'));
expect(screen.getByText(SIMPLE_CONFIG_TEMPLATE_TEXT)).toBeInTheDocument();
});
});
10 changes: 6 additions & 4 deletions webui/react/src/components/JupyterLabButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ const JupyterLabButton: React.FC<Props> = ({ enabled, workspace }: Props) => {
return (
<>
{enabled ? (
<Tooltip content={shortcutToString(jupyterLabShortcut)}>
<Button onClick={JupyterLabModal.open}>Launch JupyterLab</Button>
</Tooltip>
<>
<Tooltip content={shortcutToString(jupyterLabShortcut)}>
<Button onClick={JupyterLabModal.open}>Launch JupyterLab</Button>
</Tooltip>
<JupyterLabModal.Component workspace={workspace} />
</>
) : (
<Tooltip content="You do not have permission to launch JupyterLab" placement="leftBottom">
<div>
<Button disabled>Launch JupyterLab</Button>
</div>
</Tooltip>
)}
<JupyterLabModal.Component workspace={workspace} />
</>
);
};
Expand Down
Loading

0 comments on commit 88b93a2

Please sign in to comment.