-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dom-actions.element-visible.html
- Loading branch information
ondrej.frei
committed
Oct 22, 2024
1 parent
0a0054b
commit 9b1d328
Showing
2 changed files
with
156 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,24 @@ | ||
<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> | ||
<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,132 @@ | ||
import {expect} from '@esm-bundle/chai'; | ||
import {instantiateDomActions} from "./utils"; | ||
|
||
// must be run from dom-actions.element-visible.html | ||
describe('elementVisible', () => { | ||
describe('mode: "none"', () => { | ||
it('should return true if no elements found by selector', () => { | ||
// Given | ||
const domActions = instantiateDomActions(); | ||
|
||
// When | ||
const visible = domActions.elementVisible('#not-found', 'none'); | ||
|
||
// Then | ||
expect(visible).to.be.true | ||
}) | ||
it('should return false if all elements are visible', () => { | ||
// Given | ||
const domActions = instantiateDomActions(); | ||
|
||
// When | ||
const visible = domActions.elementVisible(['#all-visible', 'button'], 'none'); | ||
|
||
// Then | ||
expect(visible).to.be.false | ||
}) | ||
it('should return false if some elements are visible', () => { | ||
// Given | ||
const domActions = instantiateDomActions(); | ||
|
||
// When | ||
const visible = domActions.elementVisible(['#some-visible', 'button'], 'none'); | ||
|
||
// Then | ||
expect(visible).to.be.false | ||
}) | ||
it('should return true if no elements are visible', () => { | ||
// Given | ||
const domActions = instantiateDomActions(); | ||
|
||
// When | ||
const visible = domActions.elementVisible(['#none-visible', 'button'], 'none'); | ||
|
||
// Then | ||
expect(visible).to.be.true | ||
}) | ||
}) | ||
describe('mode: "any"', () => { | ||
it('should return false if no elements found by selector', () => { | ||
// Given | ||
const domActions = instantiateDomActions(); | ||
|
||
// When | ||
const visible = domActions.elementVisible('#not-found', 'any'); | ||
|
||
// Then | ||
expect(visible).to.be.false | ||
}) | ||
it('should return false if no elements are visible', () => { | ||
// Given | ||
const domActions = instantiateDomActions(); | ||
|
||
// When | ||
const visible = domActions.elementVisible(['#none-visible', 'button'], 'any'); | ||
|
||
// Then | ||
expect(visible).to.be.false | ||
}) | ||
it('should return true if some elements are visible', () => { | ||
// Given | ||
const domActions = instantiateDomActions(); | ||
|
||
// When | ||
const visible = domActions.elementVisible(['#some-visible', 'button'], 'any'); | ||
|
||
// Then | ||
expect(visible).to.be.true | ||
}) | ||
it('should return true if all elements are visible', () => { | ||
// Given | ||
const domActions = instantiateDomActions(); | ||
|
||
// When | ||
const visible = domActions.elementVisible(['#all-visible', 'button'], 'any'); | ||
|
||
// Then | ||
expect(visible).to.be.true | ||
}) | ||
}) | ||
describe('mode: "all"', () => { | ||
it('should return false if no elements found by selector', () => { | ||
// Given | ||
const domActions = instantiateDomActions(); | ||
|
||
// When | ||
const visible = domActions.elementVisible('#not-found', 'all'); | ||
|
||
// Then | ||
expect(visible).to.be.false | ||
}) | ||
it('should return false if no elements are visible', () => { | ||
// Given | ||
const domActions = instantiateDomActions(); | ||
|
||
// When | ||
const visible = domActions.elementVisible(['#none-visible', 'button'], 'all'); | ||
|
||
// Then | ||
expect(visible).to.be.false | ||
}) | ||
it('should return false if some elements are visible', () => { | ||
// Given | ||
const domActions = instantiateDomActions(); | ||
|
||
// When | ||
const visible = domActions.elementVisible(['#some-visible', 'button'], 'all'); | ||
|
||
// Then | ||
expect(visible).to.be.false | ||
}) | ||
it('should return true if all elements are visible', () => { | ||
// Given | ||
const domActions = instantiateDomActions(); | ||
|
||
// When | ||
const visible = domActions.elementVisible(['#all-visible', 'button'], 'all'); | ||
|
||
// Then | ||
expect(visible).to.be.true | ||
}) | ||
}) | ||
}) |