-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic Sphinx-Needs JS test framework
- Loading branch information
Showing
7 changed files
with
293 additions
and
10 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
describe('Test Sphinx Needs Collapse', () => { | ||
it('Visit Sphinx Needs Homepage', () => { | ||
// 1. Given a user visits http://localhost:65323/ | ||
cy.visit('/') | ||
|
||
cy.get('table.need span.needs.needs_collapse').each(($el, index, $list) => { | ||
// 2. When page loads, select all elements that matches the selector `table.need span.needs.needs_collapse` | ||
|
||
var id = $el.attr("id"); | ||
var parts = id.split("__"); | ||
var rows = parts.slice(2); | ||
|
||
var table = $el.closest('table'); | ||
var need_table_id = table.closest("div[id^=SNCB-]").attr("id"); | ||
|
||
// 3. Check if the id of the element contains show or hide | ||
if (parts[1] == "show") { | ||
cy.get($el).within(() => { | ||
// 4. Then check if `span.needs.visible` has the class `collapse_is_hidden` | ||
cy.get('span.needs.visible').should('have.class', 'collapse_is_hidden') | ||
}) | ||
} else { | ||
cy.get($el).within(() => { | ||
// 4. Then check if `span.needs.collapse` has the class `collapse_is_hidden` | ||
cy.get('span.needs.collapsed').should('have.class', 'collapse_is_hidden') | ||
}) | ||
|
||
for (var row in rows) { | ||
// 5. And check if `#${need_table_id} table tr.${rows[row]}` has the class `collapse_is_hidden` | ||
cy.get(`#${need_table_id} table tr.${rows[row]}`).should('have.class', 'collapse_is_hidden') | ||
} | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
describe('Test Sphinx Needs Collapse Click', () => { | ||
it('Visit Sphinx Needs Directive page', () => { | ||
// 1. Given a user visits http://localhost:65323/ | ||
cy.visit('/') | ||
|
||
cy.get('table.need span.needs.needs_collapse').each(($el, index, $list) => { | ||
// 2. When page loads, select all elements that matches the selector `table.need span.needs.needs_collapse` | ||
|
||
var id = $el.attr("id"); | ||
var parts = id.split("__"); | ||
var rows = parts.slice(2); | ||
|
||
var table = $el.closest('table'); | ||
var need_table_id = table.closest("div[id^=SNCB-]").attr("id"); | ||
|
||
if (parts[1] == "show") { | ||
// 3. Click collapse/expand button | ||
cy.get($el).click() | ||
|
||
for (var row in rows) { | ||
// 4. And check if `#${need_table_id} table tr.${rows[row]}` has the class `collapse_is_hidden` | ||
cy.get(`#${need_table_id} table tr.${rows[row]}`).should('have.class', 'collapse_is_hidden') | ||
} | ||
|
||
cy.get($el).within(() => { | ||
// 5. Then check if `span.needs.collapse` has the class `collapse_is_hidden` | ||
cy.get('span.needs.collapsed').should('have.class', 'collapse_is_hidden') | ||
// 6. And check if `span.needs.visible` has the class `collapse_is_hidden` | ||
cy.get('span.needs.visible').should('not.have.class', 'collapse_is_hidden') | ||
}) | ||
} else{ | ||
// 3. Click collapse/expand button | ||
cy.get($el).click() | ||
|
||
for (var row in rows) { | ||
// 4. And check if `#${need_table_id} table tr.${rows[row]}` has the class `collapse_is_hidden` | ||
cy.get(`#${need_table_id} table tr.${rows[row]}`).should('not.have.class', 'collapse_is_hidden') | ||
} | ||
|
||
cy.get($el).within(() => { | ||
// 5. Then check if `span.needs.collapse` has the class `collapse_is_hidden` | ||
cy.get('span.needs.collapsed').should('not.have.class', 'collapse_is_hidden') | ||
// 6. Check if `span.needs.visible` has the class `collapse_is_hidden` | ||
cy.get('span.needs.visible').should('have.class', 'collapse_is_hidden') | ||
}) | ||
} | ||
|
||
}) | ||
}) | ||
}) |
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,27 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.jstest | ||
@pytest.mark.parametrize( | ||
"test_app", | ||
[ | ||
{ | ||
"buildername": "html", | ||
"srcdir": "doc_test/variant_doc", | ||
"tags": ["tag_a"], | ||
"spec_pattern": "js_test/js-test-sn-collapse-button.cy.js", | ||
} | ||
], | ||
indirect=True, | ||
) | ||
def test_collapse_button_in_docs(test_app): | ||
"""Check if the Sphinx-Needs collapse button works in the provided documentation source.""" | ||
app = test_app | ||
app.build() | ||
|
||
# Call `app.test_js()` to run the JS test for a particular specPattern | ||
js_test_result = app.test_js() | ||
|
||
# Check the return code and stdout | ||
assert js_test_result["returncode"] == 0 | ||
assert "All specs passed!" in js_test_result["stdout"].decode("utf-8") |