-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(DomActions) WTR tests for elementVisible() (#497)
* 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
1 parent
1bd1901
commit c22c1c3
Showing
2 changed files
with
95 additions
and
0 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
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> |
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,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 | ||
}) | ||
}) | ||
}) |