Skip to content

Commit

Permalink
(DomActions) WTR tests for elementVisible() (#497)
Browse files Browse the repository at this point in the history
* Add dom-actions.element-visible.html

* Reuse DomActions across dom-actions.element-visible.ts and combine When + Then phases

* Add a button with hidden parent into dom-actions.element-visible.html

---------

Co-authored-by: ondrej.frei <frei.ondrej@pm.me>
  • Loading branch information
freiondrej and ondrej.frei authored Oct 24, 2024
1 parent 1bd1901 commit c22c1c3
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests-wtr/dom-actions/dom-actions.element-visible.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<html>
<body>
<script type="module">
import {runTests} from '@web/test-runner-mocha';

runTests(async () => {
await import('./dom-actions.element-visible')
});
</script>
<div id="none-visible">
<button style="display:none">This one is invisible</button>
<button style="display:none">This one too</button>
<div style="display:none">
<button>I am hidden too</button>
</div>
</div>
<div id="some-visible">
<button style="display:none">This one is invisible</button>
<button style="display:none">This one too</button>
<button>This one is visible</button>
</div>
<div id="all-visible">
<button>This one is visible</button>
<button>This one too</button>
</div>
</body>
</html>
68 changes: 68 additions & 0 deletions tests-wtr/dom-actions/dom-actions.element-visible.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {expect} from '@esm-bundle/chai';
import {instantiateDomActions} from "./utils";
import {DomActions} from "../../lib/dom-actions";

// must be run from dom-actions.element-visible.html
describe('elementVisible', () => {
let domActions: DomActions

beforeEach(() => {
// Given
domActions = instantiateDomActions();
})

describe('mode: "none"', () => {
it('should return true if no elements found by selector', () => {
// When + Then
expect(domActions.elementVisible('#not-found', 'none')).to.be.true
})
it('should return false if all elements are visible', () => {
// When + Then
expect(domActions.elementVisible(['#all-visible', 'button'], 'none')).to.be.false
})
it('should return false if some elements are visible', () => {
// When + Then
expect(domActions.elementVisible(['#some-visible', 'button'], 'none')).to.be.false
})
it('should return true if no elements are visible', () => {
// When + Then
expect(domActions.elementVisible(['#none-visible', 'button'], 'none')).to.be.true
})
})
describe('mode: "any"', () => {
it('should return false if no elements found by selector', () => {
// When + Then
expect(domActions.elementVisible('#not-found', 'any')).to.be.false
})
it('should return false if no elements are visible', () => {
// When + Then
expect(domActions.elementVisible(['#none-visible', 'button'], 'any')).to.be.false
})
it('should return true if some elements are visible', () => {
// When + Then
expect(domActions.elementVisible(['#some-visible', 'button'], 'any')).to.be.true
})
it('should return true if all elements are visible', () => {
// When + Then
expect(domActions.elementVisible(['#all-visible', 'button'], 'any')).to.be.true
})
})
describe('mode: "all"', () => {
it('should return false if no elements found by selector', () => {
// When + Then
expect(domActions.elementVisible('#not-found', 'all')).to.be.false
})
it('should return false if no elements are visible', () => {
// When + Then
expect(domActions.elementVisible(['#none-visible', 'button'], 'all')).to.be.false
})
it('should return false if some elements are visible', () => {
// When + Then
expect(domActions.elementVisible(['#some-visible', 'button'], 'all')).to.be.false
})
it('should return true if all elements are visible', () => {
// When + Then
expect(domActions.elementVisible(['#all-visible', 'button'], 'all')).to.be.true
})
})
})

0 comments on commit c22c1c3

Please sign in to comment.