Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 22, 2024
1 parent 729b563 commit 1d6e8d4
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 83 deletions.
32 changes: 26 additions & 6 deletions binderhub/static/js/components/LinkGenerator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ function ProviderSelector({
>
{selectedProvider.displayName}
</button>
<ul id="repository-type-dropdown" className="dropdown-menu dropdown-menu-start">
<ul
id="repository-type-dropdown"
className="dropdown-menu dropdown-menu-start"
>
{providers.map((p) => (
<li key={p.id}>
<button className="dropdown-item" onClick={() => setSelectedProvider(p)} type="button">{p.displayName}</button>
<button
className="dropdown-item"
onClick={() => setSelectedProvider(p)}
type="button"
>
{p.displayName}
</button>
</li>
))}
</ul>
Expand Down Expand Up @@ -70,7 +79,9 @@ function UrlSelector({ setUrlPath }) {

return (
<>
<label htmlFor="path" className="form-label">{kind.label}</label>
<label htmlFor="path" className="form-label">
{kind.label}
</label>
<div className="input-group">
<input
className="form-control"
Expand All @@ -91,7 +102,13 @@ function UrlSelector({ setUrlPath }) {
<ul className="dropdown-menu dropdown-menu-end">
{KINDS.map((k) => (
<li key={k.id}>
<button className="dropdown-item" onClick={() => setKind(k)} type="button">{k.displayName}</button>
<button
className="dropdown-item"
onClick={() => setKind(k)}
type="button"
>
{k.displayName}
</button>
</li>
))}
</ul>
Expand Down Expand Up @@ -187,7 +204,9 @@ export function LinkGenerator({

<div className="row align-items-end">
<div className="col-5">
<label htmlFor="ref" className="form-label">Git ref (branch, tag, or commit)</label>
<label htmlFor="ref" className="form-label">
Git ref (branch, tag, or commit)
</label>
<div className="input-group">
<input
className="form-control"
Expand Down Expand Up @@ -223,7 +242,8 @@ export function LinkGenerator({
<div>
<div className="input-group">
<div className="form-control font-monospace">
{launchUrl || "Fill in the fields to see a URL for sharing your Binder."}
{launchUrl ||
"Fill in the fields to see a URL for sharing your Binder."}
</div>
<button
className="btn btn-outline-secondary"
Expand Down
178 changes: 123 additions & 55 deletions binderhub/static/js/pages/HomePage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,100 +6,168 @@ import { HomePage } from "./HomePage";
test("updates launch URL with git repo", async () => {
const user = userEvent.setup();

render(<HomePage
providers={window.pageConfig.repoProviders}
baseUrl={"http://local.com"}
publicBaseUrl={"http://local.com"}
/>);

expect(screen.getByText(/Fill in the fields to see a URL for sharing your Binder./)).toBeInTheDocument();
const repositoryField = screen.getByRole("textbox", {name: "Enter repository URL"});
render(
<HomePage
providers={window.pageConfig.repoProviders}
baseUrl={"http://local.com"}
publicBaseUrl={"http://local.com"}
/>,
);

expect(
screen.getByText(
/Fill in the fields to see a URL for sharing your Binder./,
),
).toBeInTheDocument();
const repositoryField = screen.getByRole("textbox", {
name: "Enter repository URL",
});
await user.type(repositoryField, "org/repo");
expect(screen.getByText("http://local.com/v2/gh/org/repo/HEAD")).toBeInTheDocument();
expect(
screen.getByText("http://local.com/v2/gh/org/repo/HEAD"),
).toBeInTheDocument();
});

test("updates launch URL with git ref", async () => {
const user = userEvent.setup();

render(<HomePage
providers={window.pageConfig.repoProviders}
baseUrl={"http://local.com"}
publicBaseUrl={"http://local.com"}
/>);

expect(screen.getByText(/Fill in the fields to see a URL for sharing your Binder./)).toBeInTheDocument();
const repositoryField = screen.getByRole("textbox", {name: "Enter repository URL"});
render(
<HomePage
providers={window.pageConfig.repoProviders}
baseUrl={"http://local.com"}
publicBaseUrl={"http://local.com"}
/>,
);

expect(
screen.getByText(
/Fill in the fields to see a URL for sharing your Binder./,
),
).toBeInTheDocument();
const repositoryField = screen.getByRole("textbox", {
name: "Enter repository URL",
});
await user.type(repositoryField, "org/repo");
expect(screen.getByText("http://local.com/v2/gh/org/repo/HEAD")).toBeInTheDocument();
expect(
screen.getByText("http://local.com/v2/gh/org/repo/HEAD"),
).toBeInTheDocument();

const refField = screen.getByRole("textbox", {name: "Git ref (branch, tag, or commit)"});
const refField = screen.getByRole("textbox", {
name: "Git ref (branch, tag, or commit)",
});
await user.type(refField, "main");
expect(screen.getByText("http://local.com/v2/gh/org/repo/main")).toBeInTheDocument();
expect(
screen.getByText("http://local.com/v2/gh/org/repo/main"),
).toBeInTheDocument();
});

test("updates launch URL with file", async () => {
const user = userEvent.setup();

render(<HomePage
providers={window.pageConfig.repoProviders}
baseUrl={"http://local.com"}
publicBaseUrl={"http://local.com"}
/>);

expect(screen.getByText(/Fill in the fields to see a URL for sharing your Binder./)).toBeInTheDocument();
const repositoryField = screen.getByRole("textbox", {name: "Enter repository URL"});
render(
<HomePage
providers={window.pageConfig.repoProviders}
baseUrl={"http://local.com"}
publicBaseUrl={"http://local.com"}
/>,
);

expect(
screen.getByText(
/Fill in the fields to see a URL for sharing your Binder./,
),
).toBeInTheDocument();
const repositoryField = screen.getByRole("textbox", {
name: "Enter repository URL",
});
await user.type(repositoryField, "org/repo");
expect(screen.getByText("http://local.com/v2/gh/org/repo/HEAD")).toBeInTheDocument();
expect(
screen.getByText("http://local.com/v2/gh/org/repo/HEAD"),
).toBeInTheDocument();

const fileField = screen.getByRole("textbox", {name: "File to open (in JupyterLab)"});
const fileField = screen.getByRole("textbox", {
name: "File to open (in JupyterLab)",
});
await user.type(fileField, "test.py");
expect(screen.getByText("http://local.com/v2/gh/org/repo/HEAD?urlpath=%2Fdoc%2Ftree%2Ftest.py")).toBeInTheDocument();
expect(
screen.getByText(
"http://local.com/v2/gh/org/repo/HEAD?urlpath=%2Fdoc%2Ftree%2Ftest.py",
),
).toBeInTheDocument();
});

test("updates launch URL with URL", async () => {
const user = userEvent.setup();

render(<HomePage
providers={window.pageConfig.repoProviders}
baseUrl={"http://local.com"}
publicBaseUrl={"http://local.com"}
/>);

expect(screen.getByText(/Fill in the fields to see a URL for sharing your Binder./)).toBeInTheDocument();
const repositoryField = screen.getByRole("textbox", {name: "Enter repository URL"});
render(
<HomePage
providers={window.pageConfig.repoProviders}
baseUrl={"http://local.com"}
publicBaseUrl={"http://local.com"}
/>,
);

expect(
screen.getByText(
/Fill in the fields to see a URL for sharing your Binder./,
),
).toBeInTheDocument();
const repositoryField = screen.getByRole("textbox", {
name: "Enter repository URL",
});
await user.type(repositoryField, "org/repo");
expect(screen.getByText("http://local.com/v2/gh/org/repo/HEAD")).toBeInTheDocument();
expect(
screen.getByText("http://local.com/v2/gh/org/repo/HEAD"),
).toBeInTheDocument();

// TODO: There are two buttons name "File" in the DOM, so we need queryAllByRole here.
// Ideally, these buttons have distinct labels
await(user.click(screen.queryAllByRole("button", {name: "File"})[0]));
await(user.click(screen.getByText("URL")));
await user.click(screen.queryAllByRole("button", { name: "File" })[0]);
await user.click(screen.getByText("URL"));

const fileField = screen.getByRole("textbox", {name: "URL to open"});
const fileField = screen.getByRole("textbox", { name: "URL to open" });
await user.type(fileField, "http://example.com");
expect(screen.getByText("http://local.com/v2/gh/org/repo/HEAD?urlpath=http%3A%2F%2Fexample.com")).toBeInTheDocument();
expect(
screen.getByText(
"http://local.com/v2/gh/org/repo/HEAD?urlpath=http%3A%2F%2Fexample.com",
),
).toBeInTheDocument();
});

test("change source type", async () => {
const user = userEvent.setup();

render(<HomePage
providers={window.pageConfig.repoProviders}
baseUrl={"http://local.com"}
publicBaseUrl={"http://local.com"}
/>);

expect(screen.getByText(/Fill in the fields to see a URL for sharing your Binder./)).toBeInTheDocument();
render(
<HomePage
providers={window.pageConfig.repoProviders}
baseUrl={"http://local.com"}
publicBaseUrl={"http://local.com"}
/>,
);

expect(
screen.getByText(
/Fill in the fields to see a URL for sharing your Binder./,
),
).toBeInTheDocument();
user.click(screen.getByRole("button", { name: "GitHub" }));

const zenodoButton = screen.getByRole("button", {name: "Zenodo DOI"});
const zenodoButton = screen.getByRole("button", { name: "Zenodo DOI" });
await expect(zenodoButton).toBeVisible();

await user.click(zenodoButton);
const refField = screen.getByRole("textbox", {name: "Git ref (branch, tag, or commit)"});
const refField = screen.getByRole("textbox", {
name: "Git ref (branch, tag, or commit)",
});
expect(refField).toBeDisabled();

const repositoryField = screen.getByRole("textbox", {name: "Enter repository URL"});
const repositoryField = screen.getByRole("textbox", {
name: "Enter repository URL",
});
await user.type(repositoryField, "10.5282/zenodo.3242075");
expect(screen.getByText("http://local.com/v2/zenodo/10.5282/zenodo.3242075/undefined")).toBeInTheDocument();
expect(
screen.getByText(
"http://local.com/v2/zenodo/10.5282/zenodo.3242075/undefined",
),
).toBeInTheDocument();
});
45 changes: 23 additions & 22 deletions setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,31 @@ Object.defineProperty(window, "matchMedia", {
window.pageConfig = {
repoProviders: [
{
"detect": {
"regex": "^(https?://github.com/)?(?<repo>.*)"
detect: {
regex: "^(https?://github.com/)?(?<repo>.*)",
},
"displayName": "GitHub",
"id": "gh",
"ref": {
"default": "HEAD",
"enabled": true
displayName: "GitHub",
id: "gh",
ref: {
default: "HEAD",
enabled: true,
},
repo: {
label: "GitHub repository name or URL",
placeholder:
"example: yuvipanda/requirements or https://github.com/yuvipanda/requirements",
},
"repo": {
"label": "GitHub repository name or URL",
"placeholder": "example: yuvipanda/requirements or https://github.com/yuvipanda/requirements"
}
},
{
"displayName": "Zenodo DOI",
"id": "zenodo",
"ref": {
"enabled": false
displayName: "Zenodo DOI",
id: "zenodo",
ref: {
enabled: false,
},
repo: {
label: "Zenodo DOI",
placeholder: "example: 10.5281/zenodo.3242074",
},
"repo": {
"label": "Zenodo DOI",
"placeholder": "example: 10.5281/zenodo.3242074"
}
}
]
}
},
],
};

0 comments on commit 1d6e8d4

Please sign in to comment.