-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad8ed8e
commit a1d135f
Showing
11 changed files
with
277 additions
and
650 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
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,178 @@ | ||
import { module, test } from 'qunit'; | ||
import { click, render, settled, waitFor } from '@ember/test-helpers'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import cases from 'qunit-parameterize'; | ||
|
||
module('Acceptance | modal-component', (hooks) => { | ||
setupRenderingTest(hooks); | ||
|
||
hooks.beforeEach(async function(assert) { | ||
assert.timeout(5000); | ||
|
||
const modal = this.owner.lookup('service:modal'); | ||
|
||
this.open = () => modal.open('custom-modal'); | ||
this.waitForRender = () => waitFor('[data-id="modalCustomModal"]'); | ||
this.waitForVisible = async() => { | ||
await settled(); | ||
await waitFor( | ||
'[data-id="modalCustomModal"][data-modal-show="true"]' | ||
); | ||
}; | ||
|
||
await render(hbs`<ModalContainer />`); | ||
}); | ||
|
||
test('it defines the appropriate `data-id` on the component wrapper', async function(assert) { | ||
this.open(); | ||
|
||
await this.waitForRender(); | ||
|
||
assert.dom('[data-id="modalCustomModal"]').exists(); | ||
|
||
await settled(); | ||
}); | ||
|
||
test('it is accessible', async function(assert) { | ||
this.open(); | ||
|
||
await this.waitForRender(); | ||
|
||
assert | ||
.dom('[data-id="modalCustomModal"]') | ||
.hasAttribute('role', 'dialog'); | ||
|
||
// Resolve modal to remove pending waiters | ||
await click('[data-id="resolve"]'); | ||
}); | ||
|
||
test('it renders hidden and then toggles visibility', async function(assert) { | ||
this.open(); | ||
|
||
await this.waitForRender(); | ||
|
||
assert | ||
.dom('[data-id="modalCustomModal"]') | ||
.hasAttribute('data-modal-show', 'false'); | ||
|
||
await this.waitForVisible(); | ||
|
||
assert | ||
.dom('[data-id="modalCustomModal"]') | ||
.hasAttribute('data-modal-show', 'true'); | ||
}); | ||
|
||
cases([{ title: 'resolve' }, { title: 'reject' }]).test( | ||
'it changes visibility when modal is closing ', | ||
async function({ title: method }, assert) { | ||
this.open(); | ||
|
||
await this.waitForVisible(); | ||
click(`[data-id="${method}"]`); | ||
await waitFor( | ||
'[data-id="modalCustomModal"][data-modal-show="false"]' | ||
); | ||
|
||
assert | ||
.dom('[data-id="modalCustomModal"]') | ||
.hasAttribute('data-modal-show', 'false'); | ||
|
||
await settled(); | ||
} | ||
); | ||
|
||
cases([{ title: 'resolve' }, { title: 'reject' }]).test( | ||
'it removes modal from DOM when promise is fulfilled ', | ||
async function({ title: method }, assert) { | ||
const promise = this.open(); | ||
|
||
await this.waitForVisible(); | ||
click(`[data-id="${method}"]`); | ||
|
||
try { | ||
await promise; | ||
} catch { | ||
// Nope... | ||
} | ||
|
||
assert.dom('[data-id="modalCustomModal"]').doesNotExist(); | ||
} | ||
); | ||
|
||
cases([{ title: 'resolve' }, { title: 'reject' }]).test( | ||
'it fulfills with a value ', | ||
async function({ title: method }, assert) { | ||
const promise = this.open(); | ||
|
||
await this.waitForVisible(); | ||
click(`[data-id="${method}"]`); | ||
|
||
try { | ||
const value = await promise; | ||
|
||
assert.equal(typeof value, 'function'); | ||
} catch (e) { | ||
assert.equal(e, 'reject'); | ||
} | ||
} | ||
); | ||
|
||
test('it calls "didOpen" when modal is visible', async function(assert) { | ||
const promise = this.open(); | ||
|
||
await this.waitForVisible(); | ||
await new Promise((res) => setTimeout(res, 500)); // wait transition callback | ||
click('[data-id="resolve"]'); | ||
|
||
const didOpenSpy = await promise; | ||
|
||
assert.ok(didOpenSpy.calledOnce); | ||
}); | ||
|
||
module('animations disabled', (moduleHooks) => { | ||
moduleHooks.beforeEach(function() { | ||
this.styles = document.createElement('style'); | ||
this.styles.innerHTML = ` | ||
[data-id="modalCustomModal"] { | ||
transition: none !important; | ||
} | ||
`; | ||
document.body.appendChild(this.styles); | ||
}); | ||
|
||
moduleHooks.afterEach(function() { | ||
document.body.removeChild(this.styles); | ||
}); | ||
|
||
test('it calls "didOpen" when modal is visible', async function(assert) { | ||
const promise = this.open(); | ||
|
||
await this.waitForVisible(); | ||
await new Promise((res) => setTimeout(res, 500)); // wait transition callback | ||
click('[data-id="resolve"]'); | ||
|
||
const didOpenSpy = await promise; | ||
|
||
assert.ok(didOpenSpy.calledOnce); | ||
}); | ||
|
||
cases([{ title: 'resolve' }, { title: 'reject' }]).test( | ||
'it removes modal from DOM when promise is fulfilled ', | ||
async function({ title: method }, assert) { | ||
const promise = this.open(); | ||
|
||
await this.waitForVisible(); | ||
click(`[data-id="${method}"]`); | ||
|
||
try { | ||
await promise; | ||
} catch { | ||
// Nope... | ||
} | ||
|
||
assert.dom('[data-id="modalCustomModal"]').doesNotExist(); | ||
} | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<button type="button" data-id="resolve" {{on 'click' (action this.resolve this 'foo')}}>Resolve</button> | ||
<button type="button" data-id="reject" {{on 'click' (action this.reject 'reject')}}>Reject</button> | ||
<button type="button" data-id="resolve" {{on 'click' (fn this.resolve this.didOpen)}}>Resolve</button> | ||
<button type="button" data-id="reject" {{on 'click' (fn this.reject 'reject')}}>Reject</button> |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import ModalComponent from 'ember-modal-service/components/modal'; | ||
import sinon from 'sinon'; | ||
|
||
export default class CustomModalComponent extends ModalComponent {} | ||
export default class CustomModalComponent extends ModalComponent { | ||
didOpen = sinon.spy(); | ||
} |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
.animated { | ||
transition: opacity .2s | ||
} | ||
|
||
.animated[data-modal-show="false"] { | ||
[data-id='modalCustomModal'] { | ||
transition: opacity 0.2s; | ||
} | ||
[data-id='modalCustomModal'][data-modal-show='false'] { | ||
opacity: 0; | ||
} | ||
|
||
.animated[data-modal-show="true"] { | ||
} | ||
[data-id='modalCustomModal'][data-modal-show='true'] { | ||
opacity: 1; | ||
} | ||
} |
Oops, something went wrong.