Skip to content

Commit

Permalink
atomicized code block checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ps48 committed Jan 8, 2024
1 parent 0b31f91 commit 482806e
Showing 1 changed file with 117 additions and 2 deletions.
119 changes: 117 additions & 2 deletions public/components/notebooks/components/__tests__/notebook.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,45 @@ describe('<Notebook /> spec', () => {
});
});

it('Checks code block operations', async () => {
it('Adds a code block', async () => {
httpClient.get = jest.fn(() => Promise.resolve((emptyNotebook as unknown) as HttpResponse));
let postFlag = 1;
httpClient.post = jest.fn(() => {
if (postFlag === 1) {
postFlag += 1;
return Promise.resolve((addCodeBlockResponse as unknown) as HttpResponse);
} else return Promise.resolve((runCodeBlockResponse as unknown) as HttpResponse);
});
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
setBreadcrumbs={setBreadcrumbs}
renameNotebook={renameNotebook}
cloneNotebook={cloneNotebook}
deleteNotebook={deleteNotebook}
setToast={setToast}
location={location}
history={history}
/>
);
await waitFor(() => {
expect(utils.getByText('sample-notebook-1')).toBeInTheDocument();
});

act(() => {
utils.getByText('Add code block').click();
});

await waitFor(() => {
expect(utils.getByPlaceholderText(codePlaceholderText)).toBeInTheDocument();
});
});

it('toggles show input in code block', async () => {
httpClient.get = jest.fn(() => Promise.resolve((emptyNotebook as unknown) as HttpResponse));
let postFlag = 1;
httpClient.post = jest.fn(() => {
Expand Down Expand Up @@ -165,9 +203,43 @@ describe('<Notebook /> spec', () => {
await waitFor(() => {
expect(utils.queryByPlaceholderText(codePlaceholderText)).toBeNull();
});
});

it('runs a code block and checks the output', async () => {
httpClient.get = jest.fn(() => Promise.resolve((emptyNotebook as unknown) as HttpResponse));
let postFlag = 1;
httpClient.post = jest.fn(() => {
if (postFlag === 1) {
postFlag += 1;
return Promise.resolve((addCodeBlockResponse as unknown) as HttpResponse);
} else return Promise.resolve((runCodeBlockResponse as unknown) as HttpResponse);
});
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
setBreadcrumbs={setBreadcrumbs}
renameNotebook={renameNotebook}
cloneNotebook={cloneNotebook}
deleteNotebook={deleteNotebook}
setToast={setToast}
location={location}
history={history}
/>
);
await waitFor(() => {
expect(utils.getByText('sample-notebook-1')).toBeInTheDocument();
});

act(() => {
utils.getByLabelText('Toggle show input').click();
utils.getByText('Add code block').click();
});

await waitFor(() => {
expect(utils.getByPlaceholderText(codePlaceholderText)).toBeInTheDocument();
});

act(() => {
Expand All @@ -181,6 +253,49 @@ describe('<Notebook /> spec', () => {
expect(utils.queryByText('Run')).toBeNull();
expect(utils.getByText('hello')).toBeInTheDocument();
});
});

it('toggles between input/output only views', async () => {
httpClient.get = jest.fn(() => Promise.resolve((emptyNotebook as unknown) as HttpResponse));
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
setBreadcrumbs={setBreadcrumbs}
renameNotebook={renameNotebook}
cloneNotebook={cloneNotebook}
deleteNotebook={deleteNotebook}
setToast={setToast}
location={location}
history={history}
/>
);
await waitFor(() => {
expect(utils.getByText('sample-notebook-1')).toBeInTheDocument();
});

act(() => {
utils.getByText('Add code block').click();
});

await waitFor(() => {
expect(utils.getByPlaceholderText(codePlaceholderText)).toBeInTheDocument();
});

act(() => {
utils.getByLabelText('Toggle show input').click();
});

await waitFor(() => {
expect(utils.queryByPlaceholderText(codePlaceholderText)).toBeNull();
});

act(() => {
utils.getByLabelText('Toggle show input').click();
});

act(() => {
fireEvent.click(utils.getByTestId('input_only'));
Expand Down

0 comments on commit 482806e

Please sign in to comment.