Skip to content

Commit

Permalink
fix: pagination controls with empty initial hrefs
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Apr 12, 2022
1 parent e6116ab commit 1b06349
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
54 changes: 39 additions & 15 deletions pagebreak/features/pagination-controls.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ Feature: Pagination Controls
"""
When I run Pagebreak
Then I should see a selector 'a' in "output/index.html" with the attributes:
| href | page/2/ |
| innerText | Next Page |
| href | page/2/ |
| innerText | Next Page |
Then I should see a selector 'a' in "output/page/2/index.html" with the attributes:
| href | ../3/ |
| innerText | Next Page |
| href | ../3/ |
| innerText | Next Page |
Then I should see a selector 'a' in "output/page/2/index.html" with the attributes:
| href | ../../ |
| innerText | Previous Page |
Expand All @@ -51,17 +51,17 @@ Feature: Pagination Controls
"""
When I run Pagebreak
Then I should see a selector 'a' in "output/red/blue/yellow/index.html" with the attributes:
| href | ../../page/2/test/ |
| innerText | Next Page |
| href | ../../page/2/test/ |
| innerText | Next Page |
Then I should see a selector 'a' in "output/red/page/2/test/index.html" with the attributes:
| href | ../../3/test/ |
| innerText | Next Page |
| href | ../../3/test/ |
| innerText | Next Page |
Then I should see a selector 'a' in "output/red/page/2/test/index.html" with the attributes:
| href | ../../../blue/yellow/ |
| innerText | Previous Page |
Then I should see a selector 'a' in "output/red/page/3/test/index.html" with the attributes:
| href | ../../2/test/ |
| innerText | Previous Page |
| href | ../../2/test/ |
| innerText | Previous Page |

Scenario: If I have inverse pagination controls, they should hide when next/prev pages exist
Given I have a "source/index.html" file with the body:
Expand All @@ -76,14 +76,38 @@ Feature: Pagination Controls
"""
When I run Pagebreak
Then I should see a selector 'a' in "output/index.html" with the attributes:
| href | page/2/ |
| innerText | Next Page |
| href | page/2/ |
| innerText | Next Page |
Then I should see a selector 'span' in "output/index.html" with the attributes:
| innerText | No Previous |
| innerText | No Previous |
Then I should see a selector 'a' in "output/page/2/index.html" with the attributes:
| href | ../../ |
| innerText | Previous Page |
Then I should see a selector 'span' in "output/page/2/index.html" with the attributes:
| innerText | No Next |
| innerText | No Next |
But I should not see "No Next" in "output/index.html"
And I should not see "No Previous" in "output/page/2/index.html"
And I should not see "No Previous" in "output/page/2/index.html"

# Prevent regression
Scenario: Pagination controls with no href should work
Given I have a "source/index.html" file with the body:
"""
<section data-pagebreak="1"><p></p><p></p><p></p></section>
<section>
<a href="" data-pagebreak-control="prev">Previous Page</a>
<a href="" data-pagebreak-control="next">Next Page</a>
</section>
"""
When I run Pagebreak
Then I should see a selector 'a' in "output/index.html" with the attributes:
| href | page/2/ |
| innerText | Next Page |
Then I should see a selector 'a' in "output/page/2/index.html" with the attributes:
| href | ../3/ |
| innerText | Next Page |
Then I should see a selector 'a' in "output/page/2/index.html" with the attributes:
| href | ../../ |
| innerText | Previous Page |
Then I should see a selector 'a' in "output/page/3/index.html" with the attributes:
| href | ../2/ |
| innerText | Previous Page |
3 changes: 2 additions & 1 deletion pagebreak/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ impl PagebreakState {
.filter(|element| {
let attributes = element.as_node().as_element().unwrap().attributes.borrow();
let url = attributes.get("href").unwrap();
!url.starts_with("http://")
url.len() > 0
&& !url.starts_with("http://")
&& !url.starts_with("https://")
&& !url.starts_with('/')
&& !url.starts_with('#')
Expand Down

0 comments on commit 1b06349

Please sign in to comment.