1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-10 19:37:31 +02:00
comprehensive-rust/tests/src/speaker-notes.test.ts
michael-kerscher 48b2b5c312
Add a test framework to test the JS part of the course (#2471)
This is a first draft for a test framework for testing the JS part of
the book that is discussed in #2462

It is using [webdriverIO](https://webdriver.io/) and the webdriverIO
[Expect API](https://webdriver.io/docs/api/expect-webdriverio/) in
combination with [Mocha](https://mochajs.org/). WebdriverIO is taking
care of accessing the webpage with a real browser and can access the
state of the page so behavior can be asserted.

Currently only a small test for the speaker-notes implementation demos
the functionality.

The [Static Server
Service](https://webdriver.io/docs/static-server-service/) is used to
serve the book in a way that the test runner can access it.

A CI integration can look like https://webdriver.io/docs/githubactions/
and is implemented with a headless setup. In CI it uses the language
variable to set environment variable that configures where the built
book should be mounted from

---------

Co-authored-by: Martin Geisler <martin@geisler.net>
2024-12-04 09:06:58 +00:00

32 lines
1.1 KiB
TypeScript

import { describe, it } from "mocha";
import { $, expect, browser } from "@wdio/globals";
describe("speaker-notes", () => {
beforeEach(async () => {
await browser.url("/");
});
it("contains summary with heading and button", async () => {
const summary$ = await $("details summary");
await expect(summary$).toExist();
await expect(summary$.$("#speaker-notes")).toHaveText("Speaker Notes");
await expect(summary$.$(".pop-out")).toExist();
});
it("opens a new window on button click and hide details on main page", async () => {
const details$ = await $("details");
const button$ = await $("details summary .pop-out");
await expect(details$).toBeDisplayed();
button$.scrollIntoView();
await button$.click();
await expect(details$).not.toBeDisplayed();
// a new window should have opened, it should be the second one
const handles = await browser.getWindowHandles();
await browser.switchToWindow(handles[1]);
await expect(browser).toHaveUrl(
expect.stringContaining("#speaker-notes-open")
);
});
});