Skip to content

Commit

Permalink
Merge pull request #3249 from metatoaster/pr3213_e2e_tests
Browse files Browse the repository at this point in the history
test: aria-current end-to-end tests (#3213)
  • Loading branch information
gbj authored Nov 17, 2024
2 parents 7f2237b + 6f35f8d commit 36132a5
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 6 deletions.
111 changes: 110 additions & 1 deletion examples/suspense_tests/e2e/features/check_aria_current.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,116 @@ Feature: Check aria-current being applied to make links bolded
Given I see the app

Scenario: Should see the base case working
Then I see the link Out-of-Order being bolded
Then I see the Out-of-Order link being bolded
And I see the following links being bolded
| Out-of-Order |
| Nested |
And I see the In-Order link not being bolded
And I see the following links not being bolded
| In-Order |
| Single |

Scenario: Should see client-side render the correct bolded links
When I select the link In-Order
And I select the link Single
Then I see the following links being bolded
| In-Order |
| Single |
And I see the following links not being bolded
| Out-of-Order |
| Nested |

Scenario: Should see server-side render the correct bolded links
When I select the link In-Order
And I select the link Single
And I reload the page
Then I see the following links being bolded
| In-Order |
| Single |
And I see the following links not being bolded
| Out-of-Order |
| Nested |

Scenario: Check that the base nested route links are working
When I select the link Instrumented
Then I see the Instrumented link being bolded
And I see the Item Listing link not being bolded

Scenario: Should see going deep down into nested routes bold links
When I select the link Instrumented
And I select the link Target 421
Then I see the following links being bolded
| Instrumented |
| Item Listing |
| Target 4## |
| Target 42# |
| Target 421 |
| field1 |

Scenario: Should see going deep down into nested routes in SSR bold links
When I select the link Instrumented
And I select the link Target 421
And I reload the page
Then I see the following links being bolded
| Instrumented |
| Item Listing |
| Target 4## |
| Target 42# |
| Target 421 |
| field1 |

Scenario: Going deep down navigate around nested links bold correctly
When I select the link Instrumented
And I select the link Target 421
And I select the link Inspect path2/field3
Then I see the following links being bolded
| Instrumented |
| Item Listing |
| Target 4## |
| Target 42# |
| field3 |
And I see the following links not being bolded
| Target 421 |
| field1 |

Scenario: Going deep down navigate around nested links bold correctly, SSR
When I select the link Instrumented
And I select the link Target 421
And I select the link Inspect path2/field3
And I reload the page
Then I see the following links being bolded
| Instrumented |
| Item Listing |
| Target 4## |
| Target 42# |
| field3 |
And I see the following links not being bolded
| Target 421 |
| field1 |

Scenario: Going deep down back out nested routes reset bolded states
When I select the link Instrumented
And I select the link Target 421
And I select the link Counters
Then I see the following links being bolded
| Instrumented |
| Counters |
And I see the following links not being bolded
| Item Listing |
| Target 4## |
| Target 42# |
| Target 421 |

Scenario: Going deep down back out nested routes reset bolded states, SSR
When I select the link Instrumented
And I select the link Target 421
And I select the link Counters
And I reload the page
Then I see the following links being bolded
| Instrumented |
| Counters |
And I see the following links not being bolded
| Item Listing |
| Target 4## |
| Target 42# |
| Target 421 |
8 changes: 8 additions & 0 deletions examples/suspense_tests/e2e/tests/fixtures/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,11 @@ pub async fn link_text_is_aria_current(client: &Client, text: &str) -> Result<()

Ok(())
}

pub async fn link_text_is_not_aria_current(client: &Client, text: &str) -> Result<()> {
let link = find::link_with_text(client, text).await?;

link.attr("aria-current").await?
.map(|_| anyhow::bail!("aria-current mistakenly set for {text}"))
.unwrap_or(Ok(()))
}
28 changes: 27 additions & 1 deletion examples/suspense_tests/e2e/tests/fixtures/world/check_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async fn i_see_the_second_count_is(
Ok(())
}

#[then(regex = r"^I see the link (.*) being bolded$")]
#[then(regex = r"^I see the (.*) link being bolded$")]
async fn i_see_the_link_being_bolded(
world: &mut AppWorld,
text: String,
Expand All @@ -106,6 +106,32 @@ async fn i_see_the_following_links_being_bolded(
Ok(())
}

#[then(regex = r"^I see the (.*) link not being bolded$")]
async fn i_see_the_link_being_not_bolded(
world: &mut AppWorld,
text: String,
) -> Result<()> {
let client = &world.client;
check::link_text_is_not_aria_current(client, &text).await?;

Ok(())
}

#[then(expr = "I see the following links not being bolded")]
async fn i_see_the_following_links_not_being_bolded(
world: &mut AppWorld,
step: &Step,
) -> Result<()> {
let client = &world.client;
if let Some(table) = step.table.as_ref() {
for row in table.rows.iter() {
check::link_text_is_not_aria_current(client, &row[0]).await?;
}
}

Ok(())
}

#[then(expr = "I see the following counters under section")]
#[then(expr = "the following counters under section")]
async fn i_see_the_following_counters_under_section(
Expand Down
5 changes: 1 addition & 4 deletions router/src/matching/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ where
} else {
(base.as_ref(), path)
};
match path.strip_prefix(base) {
Some(path) => path,
None => return None,
}
path.strip_prefix(base)?
}
};

Expand Down

0 comments on commit 36132a5

Please sign in to comment.