mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-14 13:33:00 +00:00
Tests
This commit is contained in:
@@ -342,7 +342,7 @@ const ServerDashboard = (props) => {
|
|||||||
</td>
|
</td>
|
||||||
<EditUserCell user={user} />
|
<EditUserCell user={user} />
|
||||||
</tr>,
|
</tr>,
|
||||||
<tr>
|
<tr key={`${userServerName}-detail`}>
|
||||||
<td
|
<td
|
||||||
colSpan={6}
|
colSpan={6}
|
||||||
style={{ padding: 0 }}
|
style={{ padding: 0 }}
|
||||||
|
@@ -2,7 +2,13 @@ import React from "react";
|
|||||||
import "@testing-library/jest-dom";
|
import "@testing-library/jest-dom";
|
||||||
import { act } from "react-dom/test-utils";
|
import { act } from "react-dom/test-utils";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
import { render, screen, fireEvent, getByText } from "@testing-library/react";
|
import {
|
||||||
|
render,
|
||||||
|
screen,
|
||||||
|
fireEvent,
|
||||||
|
getByText,
|
||||||
|
getAllByRole,
|
||||||
|
} from "@testing-library/react";
|
||||||
import { HashRouter, Switch } from "react-router-dom";
|
import { HashRouter, Switch } from "react-router-dom";
|
||||||
import { Provider, useSelector } from "react-redux";
|
import { Provider, useSelector } from "react-redux";
|
||||||
import { createStore } from "redux";
|
import { createStore } from "redux";
|
||||||
@@ -697,3 +703,59 @@ test("Server delete button exists for named servers", async () => {
|
|||||||
expect(delete_button).toBeEnabled();
|
expect(delete_button).toBeEnabled();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Start server and confirm pending state", async () => {
|
||||||
|
let spy = mockAsync();
|
||||||
|
|
||||||
|
let mockStartServer = jest.fn(() => {
|
||||||
|
return new Promise(async (resolve) =>
|
||||||
|
clock.setTimeout(() => {
|
||||||
|
resolve({ status: 200 });
|
||||||
|
}, 100),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
let mockUpdateUsers = jest.fn(() => Promise.resolve(mockAppState()));
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
render(
|
||||||
|
<Provider store={createStore(mockReducers, {})}>
|
||||||
|
<HashRouter>
|
||||||
|
<Switch>
|
||||||
|
<ServerDashboard
|
||||||
|
updateUsers={mockUpdateUsers}
|
||||||
|
shutdownHub={spy}
|
||||||
|
startServer={mockStartServer}
|
||||||
|
stopServer={spy}
|
||||||
|
startAll={spy}
|
||||||
|
stopAll={spy}
|
||||||
|
/>
|
||||||
|
</Switch>
|
||||||
|
</HashRouter>
|
||||||
|
</Provider>,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
let actions = screen.getAllByTestId("user-row-server-activity")[1];
|
||||||
|
let buttons = getAllByRole(actions, "button");
|
||||||
|
|
||||||
|
expect(buttons.length).toBe(2);
|
||||||
|
expect(buttons[0].textContent).toBe("Start Server");
|
||||||
|
expect(buttons[1].textContent).toBe("Spawn Page");
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.click(buttons[0]);
|
||||||
|
});
|
||||||
|
expect(mockUpdateUsers.mock.calls).toHaveLength(1);
|
||||||
|
|
||||||
|
expect(buttons.length).toBe(2);
|
||||||
|
expect(buttons[0].textContent).toBe("Start Server");
|
||||||
|
expect(buttons[0]).toBeDisabled();
|
||||||
|
expect(buttons[1].textContent).toBe("Spawn Page");
|
||||||
|
expect(buttons[1]).toBeEnabled();
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
await clock.tick(100);
|
||||||
|
});
|
||||||
|
expect(mockUpdateUsers.mock.calls).toHaveLength(2);
|
||||||
|
});
|
||||||
|
@@ -985,7 +985,7 @@ async def test_start_stop_server_on_admin_page(
|
|||||||
|
|
||||||
async def click_spawn_page(browser, username):
|
async def click_spawn_page(browser, username):
|
||||||
"""spawn the server for one user via the Spawn page button, index = 0 or 1"""
|
"""spawn the server for one user via the Spawn page button, index = 0 or 1"""
|
||||||
spawn_btn_xpath = f'//a[contains(@href, "spawn/{username}")]/button[contains(@class, "secondary")]'
|
spawn_btn_xpath = f'//a[contains(@href, "spawn/{username}")]/button[contains(@class, "btn-light")]'
|
||||||
spawn_btn = browser.locator(spawn_btn_xpath)
|
spawn_btn = browser.locator(spawn_btn_xpath)
|
||||||
await expect(spawn_btn).to_be_enabled()
|
await expect(spawn_btn).to_be_enabled()
|
||||||
async with browser.expect_navigation(url=f"**/user/{username}/"):
|
async with browser.expect_navigation(url=f"**/user/{username}/"):
|
||||||
@@ -993,7 +993,7 @@ async def test_start_stop_server_on_admin_page(
|
|||||||
|
|
||||||
async def click_access_server(browser, username):
|
async def click_access_server(browser, username):
|
||||||
"""access to the server for users via the Access Server button"""
|
"""access to the server for users via the Access Server button"""
|
||||||
access_btn_xpath = f'//a[contains(@href, "user/{username}")]/button[contains(@class, "primary")]'
|
access_btn_xpath = f'//a[contains(@href, "user/{username}")]/button[contains(@class, "btn-primary")]'
|
||||||
access_btn = browser.locator(access_btn_xpath)
|
access_btn = browser.locator(access_btn_xpath)
|
||||||
await expect(access_btn).to_be_enabled()
|
await expect(access_btn).to_be_enabled()
|
||||||
await access_btn.click()
|
await access_btn.click()
|
||||||
|
Reference in New Issue
Block a user