Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the Workbench's broken "Open" button #1486

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion workbench/src/renderer/components/OpenButton/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class OpenButton extends React.Component {
if (!data.canceled) {
let datastack;
try {
datastack = await fetchDatastackFromFile(data.filePaths[0]);
datastack = await fetchDatastackFromFile({ filepath: data.filePaths[0] });
} catch (error) {
logger.error(error);
alert(
Expand Down
32 changes: 32 additions & 0 deletions workbench/tests/renderer/openbutton.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import React from 'react';
import { render, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import { ipcRenderer } from 'electron';

import OpenButton from '../../src/renderer/components/OpenButton';
import { fetchDatastackFromFile } from '../../src/renderer/server_requests';

jest.mock('../../src/renderer/server_requests');

test('Open File: displays a tooltip on hover', async () => {
const { findByRole, findByText, queryByText } = render(
Expand All @@ -22,3 +26,31 @@ test('Open File: displays a tooltip on hover', async () => {
expect(queryByText(hoverText)).toBeNull();
});
});

test('Open File: sends correct payload', async () => {
const mockDatastack = {
model_run_name: 'foo',
model_human_name: 'Foo',
args: {},
};
const filename = 'data.json';
const mockDialogData = { canceled: false, filePaths: [filename] };
ipcRenderer.invoke.mockResolvedValue(mockDialogData);
fetchDatastackFromFile.mockResolvedValue(mockDatastack);
const { findByRole } = render(
<OpenButton
openInvestModel={() => {}}
batchUpdateArgs={() => {}}
/>
);

const openButton = await findByRole('button', { name: 'Open' });
await userEvent.click(openButton);

await waitFor(() => {
expect(fetchDatastackFromFile).toHaveBeenCalled();
});
const payload = fetchDatastackFromFile.mock.calls[0][0];
expect(Object.keys(payload)).toEqual(['filepath']);
expect(payload['filepath']).toEqual(filename);
});