Skip to content

Commit

Permalink
fix tests. remove toJquery
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcobain committed Mar 28, 2016
1 parent 5e72f33 commit 1dd2295
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 87 deletions.
22 changes: 11 additions & 11 deletions addon/components/paper-dialog.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Ember from 'ember';
import { toJQuery } from '../mixins/translate3d-mixin';

const {
Component,
Expand Down Expand Up @@ -28,26 +27,27 @@ export default Component.extend({
// id is that of the 'parent', if provided, or 'paper-wormhole' if not.
destinationId: computed('defaultedParent', function() {
let parent = this.get('defaultedParent');
let $parent = toJQuery(parent);
let $parent = $(parent);
// If the parent isn't found, assume that it is an id, but that the DOM doesn't
// exist yet. This only happens during integration tests or if entire application
// route is a dialog.
if (isEmpty($parent) && parent.charAt(0) === '#') {
if ($parent.length === 0 && parent.charAt(0) === '#') {
return parent.substring(1);
} else {
let id = $parent.attr('id');
if (!id) {
id = `${this.elementId}-parent`;
$parent.get(0).id = id;
}
return id;
}
let id = $parent.attr('id');
if (!id) {
id = `${this.elementId}-parent`;
$parent.get(0).id = id;
}
return id;
}),

constants: service(),

didInsertElement() {
if (this.get('escapeToClose')) {
toJQuery(this.get('defaultedParent')).on(`keydown.${this.elementId}`, (e) => {
$(this.get('defaultedParent')).on(`keydown.${this.elementId}`, (e) => {
if (e.keyCode === this.get('constants.KEYCODE.ESCAPE') && this.get('onClose')) {
this.get('onClose')();
}
Expand All @@ -57,7 +57,7 @@ export default Component.extend({

willDestroyElement() {
if (this.get('escapeToClose')) {
toJQuery(this.get('defaultedParent')).off(`keydown.${this.elementId}`);
$(this.get('defaultedParent')).off(`keydown.${this.elementId}`);
}
},

Expand Down
14 changes: 5 additions & 9 deletions addon/mixins/translate3d-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ const {
typeOf
} = Ember;

export function toJQuery(element) {
return typeOf(element) === 'string' ? $(element) : element;
}

export default Mixin.create({
constants: service(),

Expand Down Expand Up @@ -82,15 +78,15 @@ export default Mixin.create({
let toStyle = this.toTransformCss(this.calculateZoomToOrigin(this.element, this.get('defaultedCloseTo')));

run.schedule('afterRender', () => {
toJQuery(this.get('defaultedParent')).parent().append(containerClone);
$(this.get('defaultedParent')).parent().append(containerClone);
run.next(() => {
dialogClone.removeClass('md-transition-in');
dialogClone.addClass('md-transition-out');
dialogClone.attr('style', toStyle);
run.next(() => {
this.waitTransitionEnd(dialogClone).then(() => {
containerClone.remove();
this.onTranslateToEnd(toJQuery(this.get('origin')));
this.onTranslateToEnd($(this.get('origin')));
});
});
});
Expand All @@ -111,9 +107,9 @@ export default Mixin.create({

// Upon timeout or transitionEnd, reject or resolve (respectively) this promise.
// NOTE: Make sure this transitionEnd didn't bubble up from a child
$element.on(this.TRANSITIONEND, function(ev) {
$element.one(this.TRANSITIONEND, function(ev) {
if (ev) {
resolve();
run(resolve);
}
});

Expand All @@ -135,7 +131,7 @@ export default Mixin.create({
let zoomStyle;

if (originator) {
originator = toJQuery(originator).get(0);
originator = $(originator).get(0);
let originBnds = this.copyRect(originator.getBoundingClientRect());
let dialogRect = this.copyRect(element.getBoundingClientRect());
let dialogCenterPt = this.centerPointFor(dialogRect);
Expand Down
8 changes: 4 additions & 4 deletions tests/dummy/app/templates/dialog.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,25 @@
</tr>
<tr>
<td><strong>parent</strong></td>
<td>jQuery object or selector</td>
<td>jQuery object, Element or selector</td>
<td>existing element where the modal and backdrop will be rendered</td>
</tr>
<tr>
<td><strong>origin</strong></td>
<td>jQuery object or selector</td>
<td>jQuery object, Element or selector</td>
<td>
if present, the dialog will use it as openFrom and closeTo. Also,
focus will be returned to this element once the dialog closes.
</td>
</tr>
<tr>
<td><strong>openFrom</strong></td>
<td>jQuery object or selector</td>
<td>jQuery object, Element or selector</td>
<td>source for opening the dialog with a transition</td>
</tr>
<tr>
<td><strong>closeTo</strong></td>
<td>jQuery object or selector</td>
<td>jQuery object, Element or selector</td>
<td>target for closing the dialog with a transition</td>
</tr>
<tr>
Expand Down
24 changes: 0 additions & 24 deletions tests/integration/components/paper-dialog-actions-test.js

This file was deleted.

26 changes: 0 additions & 26 deletions tests/integration/components/paper-dialog-content-test.js

This file was deleted.

32 changes: 19 additions & 13 deletions tests/integration/components/paper-dialog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ test('applies transitions when opening and closing', function(assert) {
return wait().then(() => {
let dialogTransform = getDialogTransform();
assert.ok(!dialogTransform, 'open translate was removed');

this.set('dialogOpen', false);

return wait();
Expand Down Expand Up @@ -197,7 +196,9 @@ test('opening gives focus', function(assert) {
<div id="paper-wormhole"></div>
{{#if showDialog}}
{{#paper-dialog onClose=closeDialog origin="#theorigin"}}
<button id="thedialogbutton" autofocus>çup?</button>
{{#paper-dialog-actions}}
<button id="thedialogbutton">çup?</button>
{{/paper-dialog-actions}}
{{/paper-dialog}}
{{/if}}
<button id="theorigin" onclick={{action openDialog}}>
Expand All @@ -209,17 +210,22 @@ test('opening gives focus', function(assert) {
assert.equal(document.activeElement, this.$('#theorigin').get(0));
this.$('#theorigin').click();

return wait().then(() => {
assert.equal(document.activeElement, this.$('#thedialogbutton').get(0));
this.set('showDialog', false);
return wait();
}).then(() => {
let done = assert.async();
// wait() doesn't seem to wait after transitionend
this.$('md-dialog').one('transitionend webkitTransitionEnd', () => {
run.next(() => {
assert.equal(document.activeElement, this.$('#theorigin').get(0));
done();
let done = assert.async();

this.$('md-dialog').one('transitionend webkitTransitionEnd', (ev) => {
// transitionend fires for each property transitioned
if (ev.originalEvent.propertyName !== 'opacity') {
return;
}
run.next(() => {
assert.equal(document.activeElement, this.$('#thedialogbutton').get(0));
this.set('showDialog', false);

this.$('md-dialog').one('transitionend webkitTransitionEnd', () => {
run.next(() => {
assert.equal(document.activeElement, this.$('#theorigin').get(0));
done();
});
});
});
});
Expand Down

0 comments on commit 1dd2295

Please sign in to comment.