-
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add some UI integration tests (end-to-end).
- Loading branch information
Showing
9 changed files
with
329 additions
and
0 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
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ restylers: | |
include: | ||
- "**/*.cc" | ||
- "**/*.hh" | ||
- prettier |
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 @@ | ||
.tui-test/ |
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,43 @@ | ||
FROM alpine:3.19.0 | ||
|
||
RUN ["apk", "add", "--no-cache", \ | ||
"bash", \ | ||
"cmake", \ | ||
"curl-dev", \ | ||
"g++", \ | ||
"gcc", \ | ||
"git", \ | ||
"libconfig-dev", \ | ||
"libsodium-dev", \ | ||
"libvpx-dev", \ | ||
"linux-headers", \ | ||
"make", \ | ||
"ncurses-dev", \ | ||
"opus-dev", \ | ||
"pkgconfig", \ | ||
"samurai", \ | ||
"yarn"] | ||
|
||
WORKDIR /build | ||
RUN yarn add --dev @microsoft/tui-test | ||
ENV PATH=$PATH:/build/node_modules/.bin | ||
|
||
WORKDIR /build | ||
RUN git clone --depth=1 --recursive https://github.com/TokTok/c-toxcore /build/c-toxcore \ | ||
&& cmake -GNinja -B/build/c-toxcore/_build -H/build/c-toxcore \ | ||
-DBOOTSTRAP_DAEMON=OFF \ | ||
-DENABLE_STATIC=OFF \ | ||
-DMUST_BUILD_TOXAV=ON \ | ||
&& cmake --build /build/c-toxcore/_build --target install | ||
|
||
WORKDIR /build/toxic | ||
COPY Makefile /build/toxic/ | ||
COPY cfg /build/toxic/cfg/ | ||
COPY misc /build/toxic/misc/ | ||
COPY sounds /build/toxic/sounds/ | ||
COPY src /build/toxic/src/ | ||
ENV CFLAGS="-D_GNU_SOURCE -Werror" | ||
RUN make "-j$(nproc)" install | ||
|
||
WORKDIR /build/toxic/test | ||
ENTRYPOINT ["tui-test"] |
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,9 @@ | ||
# Integration test suite | ||
|
||
`test/run` builds a docker image with tui-test and toxic in it and then runs | ||
integration tests, i.e. launch the toxic binary in a virtual terminal and | ||
mechanically interacts with it via stdin/stdout I/O. At the end of a test, it | ||
may take a "screenshot" (black and white copy of the current screen) and | ||
compare it against goldens, similar to Jest Snapshot Testing. | ||
|
||
To update the goldens (when changing something in the UI), run `test/run -u`. |
Large diffs are not rendered by default.
Oops, something went wrong.
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,6 @@ | ||
{ | ||
"type": "module", | ||
"devDependencies": { | ||
"@microsoft/tui-test": "^0.0.1" | ||
} | ||
} |
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,19 @@ | ||
#!/bin/sh | ||
|
||
set -eux | ||
|
||
docker build -t toxchat/toxic:test -f test/Dockerfile . | ||
if [ -t 1 ]; then | ||
docker run \ | ||
--volume "$PWD/test:/build/toxic/test" \ | ||
--tmpfs /build/toxic/test/.tui-test \ | ||
--rm \ | ||
-it \ | ||
toxchat/toxic:test "$@" | ||
else | ||
docker run \ | ||
--volume "$PWD/test:/build/toxic/test" \ | ||
--tmpfs /build/toxic/test/.tui-test \ | ||
--rm \ | ||
toxchat/toxic:test "$@" | ||
fi |
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,65 @@ | ||
import { test, expect, Shell } from "@microsoft/tui-test"; | ||
|
||
test.use({ shell: Shell.Bash, rows: 25, columns: 90 }); | ||
|
||
const fast = { timeout: 100 }; | ||
const slow = { timeout: 1000 }; | ||
|
||
async function startToxic(terminal: Shell.Terminal) { | ||
terminal.write("toxic\r"); | ||
return expect(terminal.getByText("Welcome to Toxic")).toBeVisible(slow); | ||
} | ||
|
||
test.describe("toxic", () => { | ||
test("toxic --help shows usage message", async ({ terminal }) => { | ||
terminal.write("toxic --help\r"); | ||
await expect(terminal.getByText("usage: toxic")).toBeVisible(fast); | ||
await expect(terminal).toMatchSnapshot(); | ||
}); | ||
|
||
test("toxic shows intro message", async ({ terminal }) => { | ||
terminal.write("toxic\r"); | ||
await expect( | ||
terminal.getByText("Would you like to encrypt it") | ||
).toBeVisible(fast); | ||
terminal.write("n\r"); | ||
await expect(terminal.getByText("Welcome to Toxic")).toBeVisible(slow); | ||
await expect(terminal).toMatchSnapshot(); | ||
}); | ||
|
||
test("help window works", async ({ terminal }) => { | ||
await startToxic(terminal); | ||
terminal.write("/help\r"); | ||
await expect(terminal.getByText("Help Menu")).toBeVisible(fast); | ||
await expect(terminal).toMatchSnapshot(); | ||
}); | ||
|
||
test("global help window works", async ({ terminal }) => { | ||
await startToxic(terminal); | ||
terminal.write("/help\r"); | ||
await expect(terminal.getByText("Help Menu")).toBeVisible(fast); | ||
terminal.write("g"); | ||
await expect(terminal.getByText("Global Commands")).toBeVisible(fast); | ||
await expect(terminal).toMatchSnapshot(); | ||
}); | ||
|
||
test("help window can be exited", async ({ terminal }) => { | ||
await startToxic(terminal); | ||
terminal.write("/help\r"); | ||
await expect(terminal.getByText("Help Menu")).toBeVisible(fast); | ||
terminal.write("x"); | ||
await expect(terminal.getByText("Help Menu")).not.toBeVisible(fast); | ||
await expect(terminal).toMatchSnapshot(); | ||
}); | ||
|
||
test("terminal resize works", async ({ terminal }) => { | ||
await startToxic(terminal); | ||
terminal.write("/help\r"); | ||
await expect(terminal.getByText("Help Menu")).toBeVisible(fast); | ||
terminal.resize(60, 20); | ||
await expect(terminal.getByText("Help Menu")).toBeVisible(fast); | ||
// Wait for one of the last things to be drawn before screenshotting. | ||
await expect(terminal.getByText("[Contacts]")).toBeVisible(fast); | ||
await expect(terminal).toMatchSnapshot(); | ||
}); | ||
}); |