-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdb8035
commit e94ee1f
Showing
10 changed files
with
439 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* | ||
* Copyright 2024 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* / | ||
*/ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
test.describe("Dropdown", () => { | ||
test("should be able to select a value", async ({ page }) => { | ||
await page.goto(`iframe.html?viewMode=story&id=dropdown--default`, { | ||
waitUntil: "networkidle", | ||
}); | ||
|
||
await page.getByRole("combobox").click(); | ||
await expect(page).toHaveScreenshot({ fullPage: true }); | ||
|
||
await page.getByRole("option", { name: "Option 2" }).click(); | ||
await expect(page.getByRole("combobox")).toHaveText("Option 2"); | ||
|
||
await page.getByRole("combobox").click(); | ||
await expect(page).toHaveScreenshot({ fullPage: true }); | ||
}); | ||
}); |
Binary file added
BIN
+12.4 KB
...est.ts-snapshots/Dropdown-should-be-able-to-select-a-value-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.2 KB
...est.ts-snapshots/Dropdown-should-be-able-to-select-a-value-2-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.51 KB
playwright/visual.test.ts-snapshots/Dropdown-Default-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.95 KB
...right/visual.test.ts-snapshots/Dropdown-With-Default-Value-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.72 KB
playwright/visual.test.ts-snapshots/Dropdown-With-Error-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.4 KB
playwright/visual.test.ts-snapshots/Dropdown-With-Help-Label-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* | ||
* Copyright 2024 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* / | ||
*/ | ||
|
||
import { describe, expect, it } from "vitest"; | ||
import { composeStories } from "@storybook/react"; | ||
import * as stories from "./Dropdown.stories"; | ||
import { act, render, waitFor } from "@testing-library/react"; | ||
import React from "react"; | ||
import { userEvent } from "@storybook/test"; | ||
|
||
const { Default, WithHelpLabel, WithError, WithDefaultValue } = | ||
composeStories(stories); | ||
|
||
describe("Dropdown", () => { | ||
it("renders a Default dropdown", () => { | ||
const { container } = render(<Default />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
it("renders a dropdown with a help label", () => { | ||
const { container } = render(<WithHelpLabel />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
it("renders a dropdown with an error ", () => { | ||
const { container } = render(<WithError />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
it("renders a dropdown with a default value ", () => { | ||
const { container } = render(<WithDefaultValue />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
it("can be opened", async () => { | ||
const { getByRole, container } = render(<Default />); | ||
await act(async () => { | ||
await userEvent.click(getByRole("combobox")); | ||
}); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
it("can select a value", async () => { | ||
const { getByRole, container } = render(<Default />); | ||
await act(async () => { | ||
await userEvent.click(getByRole("combobox")); | ||
}); | ||
|
||
await waitFor(() => | ||
expect(getByRole("option", { name: "Option 2" })).toBeInTheDocument(), | ||
); | ||
|
||
await act(async () => { | ||
await userEvent.click(getByRole("option", { name: "Option 2" })); | ||
}); | ||
|
||
expect(getByRole("combobox")).toHaveTextContent("Option 2"); | ||
|
||
await act(async () => { | ||
await userEvent.click(getByRole("combobox")); | ||
}); | ||
|
||
await waitFor(() => | ||
expect(getByRole("option", { name: "Option 2" })).toHaveAttribute( | ||
"aria-selected", | ||
"true", | ||
), | ||
); | ||
|
||
// Option 2 should be selected | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.