-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add initial test without any values * Test show delay * Test dismissal * Test remove delay value * Check hidden class before removal * Delete remove delay references
- Loading branch information
Showing
10 changed files
with
78 additions
and
9 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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,49 @@ | ||
import { aTimeout, fixture, expect, nextFrame } from '@open-wc/testing' | ||
import { fetchFixture } from './test_helpers' | ||
|
||
import { Application } from '@hotwired/stimulus' | ||
import Alert from '../src/alert' | ||
|
||
describe('AlertController', () => { | ||
const loadFixture = async (fixturePath) => { | ||
const html = await fetchFixture(fixturePath) | ||
await fixture(html) | ||
const application = Application.start() | ||
application.register('alert', Alert) | ||
} | ||
|
||
const fetchElement = () => document.querySelector("[data-controller='alert'") | ||
|
||
describe('with default values', () => { | ||
it('shows the element immediately and closes it without delay ', async () => { | ||
await loadFixture('alerts/alert_default.html') | ||
expect(fetchElement().className.includes("hidden")).to.equal(false) | ||
|
||
const closeButton = document.querySelector("[data-action='alert#close']") | ||
closeButton.click() | ||
|
||
await aTimeout(1000) | ||
expect(fetchElement()).to.equal(null) | ||
}) | ||
}) | ||
|
||
describe('with show delay value', () => { | ||
it('shows after 1000ms', async () => { | ||
await loadFixture('alerts/alert_show_delay.html') | ||
expect(fetchElement().className.includes("hidden")).to.equal(true) | ||
|
||
await aTimeout(1000) | ||
expect(fetchElement().className.includes("hidden")).to.equal(false) | ||
}) | ||
}) | ||
|
||
describe('with dismiss after value', () => { | ||
it('dismisses after 500ms', async () => { | ||
await loadFixture('alerts/alert_dismiss_after.html') | ||
expect(fetchElement().className.includes("hidden")).to.equal(false) | ||
|
||
await aTimeout(600) | ||
expect(fetchElement()).to.equal(null) | ||
}) | ||
}) | ||
}) |
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,6 @@ | ||
<div data-controller="alert"> | ||
<div> | ||
<div>Stimulus is the JS of the future!</div> | ||
<button data-action="alert#close">Close</button> | ||
</div> | ||
</div> |
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,6 @@ | ||
<div data-controller="alert" data-alert-dismiss-after-value="500"> | ||
<div> | ||
<div>Stimulus is the JS of the future!</div> | ||
<button data-action="alert#close">Close</button> | ||
</div> | ||
</div> |
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,10 @@ | ||
<div | ||
data-controller="alert" | ||
data-alert-show-delay-value="1000" | ||
class="hidden" | ||
> | ||
<div> | ||
<div>Stimulus is the JS of the future!</div> | ||
<button data-action="alert#close">Close</button> | ||
</div> | ||
</div> |