Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember optional features #701

Merged
merged 4 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/dummy-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default Component.extend(ResizeMixin, {
let offset = this.$().offset(), width = this.$().width(),
height = this.$().height();

$('#root').css({
$('#main').css({
top: offset.top,
left: offset.left,
width: width,
Expand Down
6 changes: 2 additions & 4 deletions app/services/ember-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ export default Service.extend({

let contentForBody = `${depScriptTags}\n${appScriptTag}\n${testStuff}\n`;

if (!testingEnabled(twiddleJSON) || legacyTesting(twiddleJSON)) {
contentForBody += '<div id="root"></div>';
}
contentForBody += '<div id="root"></div>';

index = index.replace('{{content-for \'body\'}}', contentForBody);

Expand Down Expand Up @@ -579,7 +577,7 @@ function contentForAppBoot(content, config) {
*/
function calculateAppConfig(config) {
let appConfig = config.APP || {};
appConfig.rootElement="#root";
appConfig.rootElement="#main";
return JSON.stringify(appConfig);
}

Expand Down
2 changes: 1 addition & 1 deletion app/styles/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ body {
width: 100%;
}

#root {
#main {
position: absolute;
}

Expand Down
5 changes: 4 additions & 1 deletion blueprints/twiddle.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"version": "0.17.0",
"EmberENV": {
"FEATURES": {}
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
Expand Down
77 changes: 77 additions & 0 deletions tests/acceptance/application-template-wrapper-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import runGist from '../helpers/run-gist';
import outputPane from '../helpers/output-pane';

let files = [
{
filename: "templates.application.hbs",
content: `<h1>Welcome to {{this.appName}}</h1>`
},
{
filename: "controllers.application.js",
content: `import Controller from '@ember/controller';

export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}`
},
{
filename: "twiddle.json",
content: `{
"version": "0.17.0",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.14.3",
"ember-template-compiler": "3.14.3",
"ember-testing": "3.14.3"
},
"addons": {
"ember-data": "3.14.1"
}
}`
}
];

function setFlag(state) {
let file = files.find(file => file.filename === 'twiddle.json');
let twiddleJSON = JSON.parse(file.content);
twiddleJSON.EmberENV["_APPLICATION_TEMPLATE_WRAPPER"] = state;
file.content = JSON.stringify(twiddleJSON);
}

module('Acceptance | application-template-wrapper', function(hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

test('application template wrapper off', async function(assert) {

setFlag(false);

await runGist(files);

assert.equal(outputPane().document.querySelector('h1').textContent.trim(), 'Welcome to Ember Twiddle', 'content loaded');
assert.equal(outputPane().document.querySelectorAll('.ember-application>.ember-view>h1').length, 0, 'content is not inside wrapper');
});

test('application template wrapper on', async function(assert) {

setFlag(true);

await runGist(files);

assert.equal(outputPane().document.querySelector('h1').textContent.trim(), 'Welcome to Ember Twiddle', 'content loaded');
assert.equal(outputPane().document.querySelectorAll('.ember-application>.ember-view>h1').length, 1, 'content is inside wrapper');
});
});
56 changes: 56 additions & 0 deletions tests/acceptance/jquery-integration-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import runGist from '../helpers/run-gist';
import outputContents from '../helpers/output-contents';

module('Acceptance | jquery-integration', function(hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

test('can turn jquery integration off', async function(assert) {

let files = [
{
filename: "templates.application.hbs",
content: `<h1>Welcome to {{this.appName}}</h1>`
},
{
filename: "controllers.application.js",
content: `import Controller from '@ember/controller';

export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}`
},
{
filename: "twiddle.json",
content: `{
"version": "0.17.0",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": false,
"_JQUERY_INTEGRATION": false
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"ember": "3.14.3",
"ember-template-compiler": "3.14.3",
"ember-testing": "3.14.3"
},
"addons": {
"ember-data": "3.14.1"
}
}`
}
];

await runGist(files);

assert.equal(outputContents(), 'Welcome to Ember Twiddle');
});
});
84 changes: 84 additions & 0 deletions tests/acceptance/template-only-glimmer-components-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import runGist from '../helpers/run-gist';
import outputPane from '../helpers/output-pane';

let files = [
{
filename: "templates.application.hbs",
content: `<h1>Welcome to {{this.appName}}</h1>
<div class="test-parent">
<MyComponent @appName={{this.appName}} />
</div>`
},
{
filename: "controllers.application.js",
content: `import Controller from '@ember/controller';

export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}`
},
{
filename: "templates.components.my-component.hbs",
content: `{{@appName}}`
},
{
filename: "twiddle.json",
content: `{
"version": "0.17.0",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.14.3",
"ember-template-compiler": "3.14.3",
"ember-testing": "3.14.3"
},
"addons": {
"ember-data": "3.14.1"
}
}`
}
];

function setFlag(state) {
let file = files.find(file => file.filename === 'twiddle.json');
let twiddleJSON = JSON.parse(file.content);
twiddleJSON.EmberENV["_TEMPLATE_ONLY_GLIMMER_COMPONENTS"] = state;
file.content = JSON.stringify(twiddleJSON);
}

module('Acceptance | template-only-glimmer-components', function(hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

test('template only glimmer components off', async function(assert) {

setFlag(false);

await runGist(files);

assert.equal(outputPane().document.querySelector('.test-parent').textContent.trim(), 'Ember Twiddle', 'content loaded');
assert.equal(outputPane().document.querySelectorAll('.test-parent>.ember-view').length, 1, 'content is inside wrapper div');
});

test('template only glimmer components on', async function(assert) {

setFlag(true);

await runGist(files);

assert.equal(outputPane().document.querySelector('.test-parent').textContent.trim(), 'Ember Twiddle', 'content loaded');
assert.equal(outputPane().document.querySelectorAll('.test-parent>.ember-view').length, 0, 'content is not inside wrapper div');
});
});
2 changes: 1 addition & 1 deletion tests/helpers/output-contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import outputPane from './output-pane';

export default function(selector) {
let output = outputPane();
let outputDiv = output.document.querySelector('#root');
let outputDiv = output.document.querySelector('#main');
if (selector) {
return outputDiv.querySelector(selector).textContent.trim();
}
Expand Down