Skip to content

Commit

Permalink
Add and update unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouder committed Jan 5, 2024
1 parent 6b55eb5 commit 49ff79e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
13 changes: 10 additions & 3 deletions jhub_apps/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,20 @@ def test_api_update_server(create_server, client):
create_server_response = {"user": "aktech"}
create_server.return_value = create_server_response
user_options = mock_user_options()
body = {"servername": "panel-app", "user_options": user_options}
response = client.put("/server/panel-app", json=body)
thumbnail = b"contents of thumbnail"
in_memory_file = io.BytesIO(thumbnail)
response = client.put(
"/server/panel-app",
data={'data': json.dumps({"servername": "panel-app", "user_options": user_options})},
files={'thumbnail': ('image.jpeg', in_memory_file)}
)
final_user_options = UserOptions(**user_options)
final_user_options.thumbnail = "data:image/jpeg;base64,Y29udGVudHMgb2YgdGh1bWJuYWls"
create_server.assert_called_once_with(
username=MOCK_USER.name,
servername="panel-app",
edit=True,
user_options=UserOptions(**user_options),
user_options=final_user_options,
)
assert response.json() == create_server_response

Expand Down
43 changes: 43 additions & 0 deletions ui/src/pages/home/app-form/app-form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,49 @@ describe('AppForm', () => {
}
});

test('simulates creating a standard app with thumbnail', async () => {
mock.onGet(new RegExp('/frameworks')).reply(200, frameworks);
mock.onPost(new RegExp('/server')).reply(200);
queryClient.setQueryData(['app-frameworks'], frameworks);
const { baseElement } = render(
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<AppForm />
</QueryClientProvider>
</RecoilRoot>,
);

const displayNameField = baseElement.querySelector(
'#display_name',
) as HTMLInputElement;
const thumbnailField = baseElement.querySelector(
'#thumbnail',
) as HTMLInputElement;
const frameworkField = baseElement.querySelector(
'#framework',
) as HTMLSelectElement;
if (displayNameField && thumbnailField && frameworkField) {
// Attempt submitting without filling in required fields
const btn = baseElement.querySelector('#submit-btn') as HTMLButtonElement;
await act(async () => {
btn.click();
});

const file = new File(['File contents'], 'image.png', {
type: 'image/png',
});
await userEvent.upload(thumbnailField, file);

await userEvent.type(displayNameField, 'App 1');
fireEvent.change(frameworkField, { target: { value: 'panel' } });

// Submit with all required fields filled in
await act(async () => {
btn.click();
});
}
});

test('simulates creating a standard app with onSubmit', async () => {
mock.onGet(new RegExp('/frameworks')).reply(200, frameworks);
mock.onPost(new RegExp('/server')).reply(200);
Expand Down

0 comments on commit 49ff79e

Please sign in to comment.