Skip to content

Commit

Permalink
Add dom-actions.element-visible.html
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrej.frei committed Oct 22, 2024
1 parent 0a0054b commit 9b1d328
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
24 changes: 24 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,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>
132 changes: 132 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,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
})
})
})

0 comments on commit 9b1d328

Please sign in to comment.