Skip to content

Commit

Permalink
feat(upgrade): upgrade ember version and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josex2r committed Dec 5, 2019
1 parent 227c65c commit 141439d
Show file tree
Hide file tree
Showing 11 changed files with 17,510 additions and 13,156 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
ecmaVersion: 2017
},
env: {
browser: false,
Expand All @@ -45,6 +45,7 @@ module.exports = {
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
'no-process-env': 0
})
}
]
Expand Down
29,734 changes: 17,009 additions & 12,725 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"@ember/optional-features": "^1.0.0",
"@semantic-release/changelog": "^3.0.2",
"@semantic-release/git": "^7.0.8",
"babel-eslint": "^10.0.3",
"babel-plugin-istanbul": "^5.1.1",
"broccoli-asset-rev": "^3.0.0",
"commitizen": "^4.0.3",
Expand All @@ -79,7 +78,6 @@
"ember-cli": "^3.14.0",
"ember-cli-code-coverage": "1.0.0-beta.8",
"ember-cli-dependency-checker": "^3.1.0",
"ember-cli-eslint": "^5.1.0",
"ember-cli-inject-live-reload": "^2.0.1",
"ember-cli-shims": "^1.2.0",
"ember-cli-sri": "2.1.1",
Expand All @@ -95,8 +93,9 @@
"ember-source": "~3.14.1",
"ember-source-channel-url": "^2.0.1",
"ember-try": "^1.2.1",
"eslint-config-bbva": "^2.0.3",
"eslint-plugin-ember": "^7.1.0",
"eslint": "^6.6.0",
"eslint-config-bbva": "^2.0.4",
"eslint-plugin-ember": "^7.2.0",
"eslint-plugin-node": "^10.0.0",
"husky": "^3.0.0",
"istanbul": "^0.4.5",
Expand Down
4 changes: 1 addition & 3 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable prefer-arrow-callback */
import EmberRouter from '@ember/routing/router';
import config from './config/environment';

Expand All @@ -7,6 +6,5 @@ const Router = EmberRouter.extend({
rootURL: config.rootURL
});

Router.map(function() {
//
Router.map(() => {
});
37 changes: 37 additions & 0 deletions tests/integration/components/modal-container-test.js
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);
});
});
228 changes: 228 additions & 0 deletions tests/integration/components/modal-test.js
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');
});
});

0 comments on commit 141439d

Please sign in to comment.