Skip to content

Commit

Permalink
First cut of the fixtures and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
metatoaster committed Oct 12, 2024
1 parent 6a809c0 commit bc73aa0
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/suspense_tests/e2e/features/check_instrumented.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@check_instrument
Feature: Check Instrumented

Background:

Given I see the app

@check_instrumented-initial
Scenario Outline: Should see fresh counters
Given I select the mode Instrumented
When I select the component Counters
When I click on Reset Counters
Then I see under Counters the <heading> count is <n>

Examples:
| heading | n |
| item_listing | 0 |
| item_overview | 0 |
| item_inspect | 0 |
| list_items | 0 |
| get_item | 0 |
| inspect_item_root | 0 |
| inspect_item_field | 0 |
8 changes: 8 additions & 0 deletions examples/suspense_tests/e2e/tests/fixtures/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ pub async fn click_second_button(client: &Client) -> Result<()> {

Ok(())
}

pub async fn click_reset_counters_button(client: &Client) -> Result<()> {
let reset_counter = find::reset_counter(client).await?;

reset_counter.click().await?;

Ok(())
}
11 changes: 11 additions & 0 deletions examples/suspense_tests/e2e/tests/fixtures/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,14 @@ pub async fn second_count_is(client: &Client, expected: u32) -> Result<()> {

Ok(())
}

pub async fn instrumented_count_is(
client: &Client,
selector: &str,
expected: u32,
) -> Result<()> {
let actual = find::instrumented_count(client, selector).await?;
assert_eq!(actual, expected);

Ok(())
}
27 changes: 27 additions & 0 deletions examples/suspense_tests/e2e/tests/fixtures/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,33 @@ pub async fn second_button(client: &Client) -> Result<Element> {
Ok(counter_button)
}

pub async fn instrumented_count(
client: &Client,
selector: &str,
) -> Result<u32> {
let element = client
.wait()
.for_element(Locator::Id(selector))
.await
.expect(format!("Element #{selector} not found.")
.as_str());
let text = element.text().await?;
let count = text.parse::<u32>()
.expect(format!("Element #{selector} does not contain a number.")
.as_str());
Ok(count)
}

pub async fn reset_counter(client: &Client) -> Result<Element> {
let reset_button = client
.wait()
.for_element(Locator::Id("reset-counters"))
.await
.expect("Reset counter not found");

Ok(reset_button)
}

async fn component_message(client: &Client, id: &str) -> Result<String> {
let element =
client.wait().for_element(Locator::Id(id)).await.expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,11 @@ async fn i_click_the_second_button_n_times(

Ok(())
}

#[when(expr = "I click on Reset Counters")]
async fn i_click_on_reset_counters(world: &mut AppWorld) -> Result<()> {
let client = &world.client;
action::click_reset_counters_button(client).await?;

Ok(())
}
12 changes: 12 additions & 0 deletions examples/suspense_tests/e2e/tests/fixtures/world/check_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,15 @@ async fn i_see_the_second_count_is(

Ok(())
}

#[then(expr = "I see under Counters the {word} count is {int}")]
async fn i_see_the_counter_for_listing_is(
world: &mut AppWorld,
which: String,
expected: u32,
) -> Result<()> {
let client = &world.client;
check::instrumented_count_is(client, &which, expected).await?;

Ok(())
}

0 comments on commit bc73aa0

Please sign in to comment.