-
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.
feat(upgrade): upgrade ember version and fix tests
- Loading branch information
Showing
11 changed files
with
17,510 additions
and
13,156 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
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,37 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render } from '@ember/test-helpers'; | ||
import EmberObject from '@ember/object'; | ||
import ModalService from 'ember-modal-service/services/modal'; | ||
import ModalContainerComponent from 'ember-modal-service/components/modal-container'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import Component from '@ember/component'; | ||
|
||
module('Integration | Component | modal-container', (hooks) => { | ||
setupRenderingTest(hooks); | ||
|
||
hooks.beforeEach(function() { | ||
this.owner.register('service:modal', ModalService); | ||
}); | ||
|
||
test('it creates instances of components from model', async function(assert) { | ||
const object = EmberObject.create({ | ||
fullname: 'modal-foo' | ||
}); | ||
const MyComponent = ModalContainerComponent.extend({ | ||
modal: { | ||
content: [object] | ||
} | ||
}); | ||
const TestComponent = Component.extend({ | ||
classNames: ['modal-foo'] | ||
}); | ||
|
||
this.owner.register('component:modal-container', MyComponent); | ||
this.owner.register('component:modal-foo', TestComponent); | ||
|
||
await render(hbs `{{modal-container}}`); | ||
|
||
assert.equal(document.querySelectorAll('.modal-foo').length, 1); | ||
}); | ||
}); |
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,228 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import EmberObject from '@ember/object'; | ||
import RSVP from 'rsvp'; | ||
import sinon from 'sinon'; | ||
import waitFor from 'ember-task-scheduler/utils/wait-for'; | ||
import { A } from '@ember/array'; | ||
import onTransitionEnd from 'ember-transition-end/utils/on-transition-end'; | ||
import { run } from '@ember/runloop'; | ||
import { render } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import ModalModel from 'ember-modal-service/models/modal'; | ||
import ModalService from 'ember-modal-service/services/modal'; | ||
import SchedulerService from 'ember-task-scheduler/services/scheduler'; | ||
import ModalComponent from 'ember-modal-service/components/modal'; | ||
|
||
const { spy } = sinon; | ||
const ANIMATION_DELAY = 300; | ||
|
||
let component, deferred, service, content, didOpenSpy; | ||
|
||
function waitForTransitionEnd(element) { | ||
return new RSVP.Promise((resolve) => { | ||
onTransitionEnd(element, resolve); | ||
}); | ||
} | ||
|
||
function waitForTimeout(timeout) { | ||
return new RSVP.Promise((resolve) => { | ||
setTimeout(resolve, timeout); | ||
}); | ||
} | ||
|
||
function waitForScheduler() { | ||
return waitFor(() => !service.hasPendingTasks() && !run.hasScheduledTimers(), 0); | ||
} | ||
|
||
function isVisible(element) { | ||
return element.getAttribute('data-modal-show') === 'true'; | ||
} | ||
|
||
function getComponent(owner, element) { | ||
const instances = owner.__container__.lookup('-view-registry:main'); | ||
|
||
return instances[element.id]; | ||
} | ||
|
||
module('Integration | Component | modal', (hooks) => { | ||
setupRenderingTest(hooks); | ||
|
||
hooks.beforeEach(async function() { | ||
this.owner.register('service:modal', ModalService); | ||
this.owner.register('service:scheduler', SchedulerService); | ||
this.owner.register('model:modal', ModalModel); | ||
|
||
deferred = RSVP.defer(); | ||
content = A(); | ||
didOpenSpy = spy(); | ||
|
||
const MyComponent = ModalComponent.extend({ | ||
target: null, | ||
model: EmberObject.create({ | ||
fullname: 'modal-foo', | ||
deferred, | ||
promise: deferred.promise | ||
}), | ||
didOpen: didOpenSpy, | ||
modal: { | ||
content | ||
} | ||
}); | ||
|
||
this.owner.register('component:modal', MyComponent); | ||
|
||
service = this.owner.lookup('service:scheduler'); | ||
}); | ||
|
||
test('it defines the appropriate `data-id` on the component wrapper', async(assert) => { | ||
await render(hbs `{{modal data-id='foo' visible=visible}}`); | ||
|
||
component = document.querySelector('[data-id="foo"]'); | ||
|
||
await waitForScheduler(); | ||
|
||
assert.ok(component); | ||
}); | ||
|
||
test('it binds visible class from component', async function(assert) { | ||
await render(hbs `{{modal data-id='foo' visible=visible}}`); | ||
|
||
component = document.querySelector('[data-id="foo"]'); | ||
|
||
await waitForScheduler(); | ||
|
||
this.set('visible', false); | ||
|
||
assert.notOk(isVisible(component)); | ||
|
||
this.set('visible', true); | ||
|
||
assert.ok(isVisible(component)); | ||
}); | ||
|
||
test('it hides and removes modal when promise is resolved', async(assert) => { | ||
await render(hbs `{{modal data-id='foo'}}`); | ||
|
||
component = document.querySelector('[data-id="foo"]'); | ||
|
||
await waitForScheduler(); | ||
|
||
assert.ok(isVisible(component)); | ||
|
||
run(() => { | ||
deferred.resolve(); | ||
}); | ||
|
||
assert.notOk(isVisible(component)); | ||
assert.equal(content.length, 0); | ||
}); | ||
|
||
test('it hides and removes modal when promise is rejected', async(assert) => { | ||
await render(hbs `{{modal data-id='foo'}}`); | ||
|
||
component = document.querySelector('[data-id="foo"]'); | ||
|
||
await waitForScheduler(); | ||
|
||
assert.ok(isVisible(component)); | ||
|
||
run(() => { | ||
deferred.reject(); | ||
}); | ||
|
||
assert.notOk(isVisible(component)); | ||
assert.equal(content.length, 0); | ||
}); | ||
|
||
test('it sends didOpen when it is rendered', async(assert) => { | ||
await render(hbs `{{modal data-id='foo'}}`); | ||
|
||
component = document.querySelector('[data-id="foo"]'); | ||
await waitForScheduler(); | ||
|
||
assert.ok(didOpenSpy.calledOnce); | ||
}); | ||
|
||
test('it sends didOpen when it is rendered and has transitions', async(assert) => { | ||
await render(hbs `{{modal data-id='foo' class='animated'}}`); | ||
|
||
component = document.querySelector('[data-id="foo"]'); | ||
|
||
await waitForScheduler(); | ||
|
||
assert.ok(didOpenSpy.notCalled); | ||
|
||
await waitForTimeout(ANIMATION_DELAY); | ||
|
||
assert.ok(didOpenSpy.calledOnce); | ||
}); | ||
|
||
test('it does not sends didOpen when it is destroyed', async function(assert) { | ||
await render(hbs ` | ||
{{#unless destroy}} | ||
{{modal data-id='foo' class='animated'}} | ||
{{/unless}} | ||
`); | ||
|
||
component = document.querySelector('[data-id="foo"]'); | ||
|
||
await waitForTransitionEnd(component); | ||
|
||
this.set('destroy', true); | ||
|
||
await waitForScheduler(); | ||
|
||
assert.ok(didOpenSpy.notCalled); | ||
}); | ||
|
||
test('it waits for transitions before being removed', async(assert) => { | ||
await render(hbs `{{modal data-id='foo' class='animated'}}`); | ||
|
||
component = document.querySelector('[data-id="foo"]'); | ||
|
||
await waitForScheduler(); | ||
|
||
run(() => { | ||
deferred.resolve(); | ||
}); | ||
|
||
assert.notOk(isVisible(component)); | ||
|
||
await waitForTimeout(ANIMATION_DELAY); | ||
|
||
assert.equal(content.length, 0); | ||
}); | ||
|
||
test('it resolves promise with arguments', async function(assert) { | ||
await render(hbs `{{modal data-id='foo'}}`); | ||
|
||
component = document.querySelector('[data-id="foo"]'); | ||
|
||
const instance = getComponent(this.owner, component); | ||
|
||
await waitForScheduler(); | ||
|
||
instance.resolve('foo'); | ||
|
||
assert.equal(await deferred.promise, 'foo'); | ||
}); | ||
|
||
test('it rejects promise with arguments', async function(assert) { | ||
assert.expect(1); | ||
|
||
await render(hbs `{{modal data-id='foo'}}`); | ||
|
||
component = document.querySelector('[data-id="foo"]'); | ||
|
||
const instance = getComponent(this.owner, component); | ||
|
||
await waitForScheduler(); | ||
|
||
deferred.promise.catch((foo) => { | ||
assert.equal(foo, 'foo'); | ||
}); | ||
|
||
instance.reject('foo'); | ||
}); | ||
}); |
Oops, something went wrong.