Skip to content

Commit

Permalink
test(guard): acceptance tests for guard (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinezanardi committed Jun 12, 2024
1 parent 06c6505 commit 7121e90
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .run/Defender Role.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Defender Role" type="cucumber.js" factoryName="Cucumber.js" folderName="Tags">
<option name="myFilePath" value="$PROJECT_DIR$/tests/acceptance" />
<option name="myNameFilter" value="" />
<option name="cucumberJsArguments" value="--config config/cucumber/cucumber.json --parallel 1 --tags @defender-role" />
<option name="workingDirectory" value="$PROJECT_DIR$" />
<envs>
<env name="NODE_OPTIONS" value="--import tsx/esm" />
</envs>
<method v="2" />
</configuration>
</component>
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ Werewolves Assistant Web is a Nuxt Web App using the Werewolves Assistant API. I
>>
>> </details>
>> <details>
>> <summary>🛡️ Defender protects Playground</summary>
>>
>> ![Defender protects Playground](https://github.com/antoinezanardi/werewolves-assistant-web-next/main/tests/acceptance/screenshots/darwin/Defender%20protects%20Playground.png)
>>
>> </details>
>> <details>
>> <summary>🔫 Hunter shoots Playground</summary>
>>
>> ![Hunter shoots Playground](https://github.com/antoinezanardi/werewolves-assistant-web-next/main/tests/acceptance/screenshots/darwin/Hunter%20shoots%20Playground.png)
Expand Down
112 changes: 112 additions & 0 deletions tests/acceptance/features/game/features/role/defender.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
@defender-role

Feature: 🛡️ Defender Role

Scenario: 🛡️ Defender protects from werewolf attack but can't choose twice in a row the same player

Given the user disables the sheriff in game options
And the user creates a game with the players with name and role
| name | role |
| Antoine | Defender |
| Bob | Werewolf |
| Charlie | Idiot |
| David | Villager |
When the user closes the toast
And the user skips the game event
And the user skips the game event
Then the game's event should display the text "The Defender wakes up and will protect anyone from the Werewolves."
And the game's event player card should have the name "Antoine"

When the user skips the game event
Then the game's current play title should be "Defender protects"
And the game's current play question should be "Which player does the Defender want to protect ?"
And the game's phase name should be "Night 1"
And the game's current play should have the following targets
| name |
| Antoine |
| Bob |
| Charlie |
| David |
And the page should match or creates the missing snapshot with name "Defender protects Playground"

When the defender protects the player with name "Antoine"
Then the player with name "Antoine" should have the attribute protected by defender in the game

When the user skips all game events
Then the game's current play title should be "Werewolves eat"

When the werewolves eat the player with name "Antoine"
And the user skips all game events
Then the player with name "Antoine" should be alive in the game
And the game's current play title should be "Survivors vote"

When the player or group skips his turn
And the user skips the game event
Then the game's event should display the text "The Defender wakes up and will protect anyone from the Werewolves except the last protected player."
And the game's event player card should have the name "Antoine"

When the user skips the game event
Then the game's current play title should be "Defender protects"
And the game's current play should have the following targets
| name |
| Bob |
| Charlie |
| David |

Scenario: 🛡️ Defender protects from werewolf attack and can choose anyone at any moment if the game master allows it

Given the user disables the sheriff in game options
And the user allows the defender to protect twice in a row in game options
And the user creates a game with the players with name and role
| name | role |
| Antoine | Defender |
| Bob | Werewolf |
| Charlie | Idiot |
| David | Villager |
When the user closes the toast

And the user skips the game event
And the user skips the game event
Then the game's event should display the text "The Defender wakes up and will protect anyone from the Werewolves."
And the game's event player card should have the name "Antoine"

When the user skips the game event
Then the game's current play title should be "Defender protects"
And the game's current play question should be "Which player does the Defender want to protect ?"
And the game's phase name should be "Night 1"
And the game's current play should have the following targets
| name |
| Antoine |
| Bob |
| Charlie |
| David |

When the defender protects the player with name "Antoine"
Then the player with name "Antoine" should have the attribute protected by defender in the game

When the user skips all game events
Then the game's current play title should be "Werewolves eat"

When the werewolves eat the player with name "Antoine"
And the user skips all game events
Then the player with name "Antoine" should be alive in the game
And the game's current play title should be "Survivors vote"

When the player or group skips his turn
And the user skips the game event
Then the game's event should display the text "The Defender wakes up and will protect anyone from the Werewolves."
And the game's event player card should have the name "Antoine"

When the user skips the game event
Then the game's current play title should be "Defender protects"
And the game's current play question should be "Which player does the Defender want to protect ?"
And the game's phase name should be "Night 2"
And the game's current play should have the following targets
| name |
| Antoine |
| Bob |
| Charlie |
| David |

When the defender protects the player with name "Antoine"
Then the player with name "Antoine" should have the attribute protected by defender in the game
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@ Given(/^the user makes the big bad wolf remaining powerful even if one werewolf
await openGameOptionsDialogInGameLobby(this);
await switchRoleOptionInGameOptionsHub(this, "#game-lobby-options-hub-roles-tab-big-bad-wolf-is-powerless-if-werewolf-dies-input", false);
await closeDialogWithHeaderButton(this);
});

Given(/^the user allows the defender to protect twice in a row in game options$/u, async function(this: CustomWorld): Promise<void> {
await goOnPage(this, "/game-lobby");
await openGameOptionsDialogInGameLobby(this);
await switchRoleOptionInGameOptionsHub(this, "#game-lobby-options-hub-roles-tab-defender-can-protect-twice-input", true);
await closeDialogWithHeaderButton(this);
});
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ When(/^the sheriff settles the vote with the player with name "(?<name>.+)"$/u,
When(/^the sheriff delegates his role to the player with name "(?<name>.+)"$/u, async function(this: CustomWorld, name: string): Promise<void> {
await targetPlayerInPlayground(this, name);
await makePlayInPlayground(this);
});

When(/^the defender protects the player with name "(?<name>.+)"$/u, async function(this: CustomWorld, name: string): Promise<void> {
await targetPlayerInPlayground(this, name);
await makePlayInPlayground(this);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { Then } from "@cucumber/cucumber";
import { expect } from "@playwright/test";
import type { CustomWorld } from "~/tests/acceptance/shared/types/word.types";

Then(/^the player with name "(?<name>.+)" should be alive in the game$/u, async function(this: CustomWorld, playerName: string): Promise<void> {
const gameTeamSidePlayerLocator = this.page.getByTestId(`game-team-side-player-${playerName}`).first();
await gameTeamSidePlayerLocator.waitFor({ state: "visible" });
const deadImage = gameTeamSidePlayerLocator.getByRole("img", { name: "This player is dead", exact: true });

await expect(deadImage).toBeHidden();
});

Then(/^the player with name "(?<name>.+)" should be dead in the game$/u, async function(this: CustomWorld, playerName: string): Promise<void> {
const gameTeamSidePlayerLocator = this.page.getByTestId(`game-team-side-player-${playerName}`).first();
await gameTeamSidePlayerLocator.waitFor({ state: "visible" });
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7121e90

Please sign in to comment.