Skip to content

Commit

Permalink
Merge pull request #305 from cibernox/support-root-less-apps
Browse files Browse the repository at this point in the history
Support testing without an application template wrapper.
  • Loading branch information
rwjblue authored Feb 10, 2018
2 parents 37c4139 + a16b9d3 commit 39e8194
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 53 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery
- env: EMBER_TRY_SCENARIO=ember-without-application-wrapper

# runs deploy if running on a specific tag
- stage: deploy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* globals EmberENV */
import { get } from '@ember/object';
import { nextTickPromise } from './-utils';
import { getContext } from './setup-context';
Expand All @@ -19,7 +20,11 @@ export function visit() {
return owner.visit(...arguments);
})
.then(() => {
context.element = document.querySelector('#ember-testing > .ember-view');
if (EmberENV._APPLICATION_TEMPLATE_WRAPPER !== false) {
context.element = document.querySelector('#ember-testing > .ember-view');
} else {
context.element = document.querySelector('#ember-testing');
}
})
.then(settled);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* globals EmberENV */
import { guidFor } from '@ember/object/internals';
import { run } from '@ember/runloop';
import Ember from 'ember';
Expand Down Expand Up @@ -196,7 +197,11 @@ export default function setupRenderingContext(context) {
// In older Ember versions (2.4) the element itself is not stable,
// and therefore we cannot update the `this.element` until after the
// rendering is completed
context.element = getRootElement().querySelector('.ember-view');
if (EmberENV._APPLICATION_TEMPLATE_WRAPPER !== false) {
context.element = getRootElement().querySelector('.ember-view');
} else {
context.element = getRootElement();
}

return context;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* globals EmberENV */
import { set, setProperties, get, getProperties } from '@ember/object';
import $ from 'jquery';
import { isArray } from '@ember/array';
Expand Down Expand Up @@ -278,10 +279,14 @@ export function setupComponentIntegrationTest() {
hasRendered = true;
}

// ensure the element is based on the wrapping toplevel view
// Ember still wraps the main application template with a
// normal tagged view
context._element = element = document.querySelector('#ember-testing > .ember-view');
if (EmberENV._APPLICATION_TEMPLATE_WRAPPER !== false) {
// ensure the element is based on the wrapping toplevel view
// Ember still wraps the main application template with a
// normal tagged view
context._element = element = document.querySelector('#ember-testing > .ember-view');
} else {
context._element = element = document.querySelector('#ember-testing');
}
};

context.$ = function(selector) {
Expand Down
11 changes: 11 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ module.exports = function() {
},
},
},
{
name: 'ember-without-application-wrapper',
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({ 'application-template-wrapper': false }),
},
npm: {
devDependencies: {
'ember-source': urls[2],
},
},
},
{
name: 'ember-default-with-jquery',
npm: {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"ember-cli-htmlbars-inline-precompile": "^1.0.0"
},
"devDependencies": {
"@ember/optional-features": "^0.5.1",
"documentation": "^5.3.5",
"ember-cli": "~2.18.0",
"ember-cli-dependency-checker": "^2.0.0",
Expand All @@ -54,9 +55,9 @@
"ember-maybe-import-regenerator-for-testing": "^1.0.0",
"ember-native-dom-event-dispatcher": "^0.6.3",
"ember-resolver": "^4.0.0",
"ember-source": "~2.18.0",
"ember-source": "~3.0.0-beta.5",
"ember-source-channel-url": "^1.0.1",
"ember-try": "^0.2.23",
"ember-try": "^1.0.0-beta.1",
"eslint-config-prettier": "^2.6.0",
"eslint-plugin-disable-features": "^0.1.3",
"eslint-plugin-node": "^5.2.1",
Expand Down
83 changes: 54 additions & 29 deletions tests/integration/setup-rendering-context-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* globals EmberENV */
import Ember from 'ember';
import { module, test } from 'qunit';
import Component from '@ember/component';
Expand Down Expand Up @@ -116,34 +117,58 @@ module('setupRenderingContext "real world"', function(hooks) {

// uses `{{-in-element` which was only added in Ember 2.10
if (hasEmberVersion(2, 10)) {
test('can click on a sibling element of this.element (within the rootElement)', async function(assert) {
let rootElement = document.getElementById('ember-testing');

assert.notEqual(
rootElement,
this.element,
'precond - confirm that the rootElement is different from this.element'
);

this.set('rootElement', rootElement);

await render(hbs`{{#-in-element rootElement}}{{click-me-button}}{{/-in-element}}`);

// this will need to be modified / removed once RFC280 lands
assert.equal(this.element.textContent, '', 'no content is contained _within_ this.element');
assert.equal(
rootElement.textContent,
'Click Me!',
'the rootElement has the correct content after initial render'
);

await click('.click-me-button');

assert.equal(
rootElement.textContent,
'Clicked!',
'the rootElement has the correct content after clicking'
);
});
if (EmberENV._APPLICATION_TEMPLATE_WRAPPER !== false) {
test('can click on a sibling element of the application template wrapper', async function(assert) {
let rootElement = document.getElementById('ember-testing');

assert.notEqual(
rootElement,
this.element,
'precond - confirm that the rootElement is different from this.element'
);

this.set('rootElement', rootElement);

await render(hbs`{{#-in-element rootElement}}{{click-me-button}}{{/-in-element}}`);

assert.equal(this.element.textContent, '', 'no content is contained _within_ this.element');
assert.equal(
rootElement.textContent,
'Click Me!',
'the rootElement has the correct content after initial render'
);

await click('.click-me-button');

assert.equal(
rootElement.textContent,
'Clicked!',
'the rootElement has the correct content after clicking'
);
});
} else {
test('can click on a sibling of the rendered content', async function(assert) {
let rootElement = document.getElementById('ember-testing');
this.set('rootElement', rootElement);

assert.equal(rootElement.textContent, '', 'the rootElement is empty before rendering');

await render(hbs`{{#-in-element rootElement}}{{click-me-button}}{{/-in-element}}`);

assert.equal(
rootElement.textContent,
'Click Me!',
'the rootElement has the correct content after initial render'
);

await click('.click-me-button');

assert.equal(
rootElement.textContent,
'Clicked!',
'the rootElement has the correct content after clicking'
);
});
}
}
});
23 changes: 19 additions & 4 deletions tests/unit/setup-rendering-context-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* globals EmberENV */
import { module, test, skip } from 'qunit';
import Service from '@ember/service';
import Component from '@ember/component';
Expand Down Expand Up @@ -51,11 +52,25 @@ module('setupRenderingContext', function(hooks) {
await teardownContext(this);
});

test('render exposes an `.element` property', async function(assert) {
await this.render(hbs`<p>Hello!</p>`);
if (EmberENV._APPLICATION_TEMPLATE_WRAPPER !== false) {
test('render exposes an `.element` property with application template wrapper', async function(assert) {
let rootElement = document.getElementById('ember-testing');
assert.notEqual(this.element, rootElement, 'this.element should not be rootElement');
assert.ok(rootElement.contains(this.element), 'this.element is _within_ the rootElement');
await this.render(hbs`<p>Hello!</p>`);

assert.equal(this.element.textContent, 'Hello!');
});
assert.equal(this.element.textContent, 'Hello!');
});
} else {
test('render exposes an `.element` property without an application template wrapper', async function(assert) {
let rootElement = document.getElementById('ember-testing');
assert.equal(this.element, rootElement, 'this.element should _be_ rootElement');

await this.render(hbs`<p>Hello!</p>`);

assert.equal(this.element.textContent, 'Hello!');
});
}

test('render can be used multiple times', async function(assert) {
await this.render(hbs`<p>Hello!</p>`);
Expand Down
Loading

0 comments on commit 39e8194

Please sign in to comment.