|
| 1 | +import { module, test } from 'qunit'; |
| 2 | +import { setupApplicationTest } from 'ember-qunit'; |
| 3 | +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; |
| 4 | +import runGist from '../helpers/run-gist'; |
| 5 | +import outputPane from '../helpers/output-pane'; |
| 6 | + |
| 7 | +let files = [ |
| 8 | + { |
| 9 | + filename: "templates.application.hbs", |
| 10 | + content: `<h1>Welcome to {{this.appName}}</h1> |
| 11 | + <div class="test-parent"> |
| 12 | + <MyComponent @appName={{this.appName}} /> |
| 13 | + </div>` |
| 14 | + }, |
| 15 | + { |
| 16 | + filename: "controllers.application.js", |
| 17 | + content: `import Controller from '@ember/controller'; |
| 18 | +
|
| 19 | + export default class ApplicationController extends Controller { |
| 20 | + appName = 'Ember Twiddle'; |
| 21 | + }` |
| 22 | + }, |
| 23 | + { |
| 24 | + filename: "templates.components.my-component.hbs", |
| 25 | + content: `{{@appName}}` |
| 26 | + }, |
| 27 | + { |
| 28 | + filename: "twiddle.json", |
| 29 | + content: `{ |
| 30 | + "version": "0.17.0", |
| 31 | + "EmberENV": { |
| 32 | + "FEATURES": {}, |
| 33 | + "_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, |
| 34 | + "_APPLICATION_TEMPLATE_WRAPPER": true, |
| 35 | + "_JQUERY_INTEGRATION": true |
| 36 | + }, |
| 37 | + "options": { |
| 38 | + "use_pods": false, |
| 39 | + "enable-testing": false |
| 40 | + }, |
| 41 | + "dependencies": { |
| 42 | + "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", |
| 43 | + "ember": "3.14.3", |
| 44 | + "ember-template-compiler": "3.14.3", |
| 45 | + "ember-testing": "3.14.3" |
| 46 | + }, |
| 47 | + "addons": { |
| 48 | + "ember-data": "3.14.1" |
| 49 | + } |
| 50 | + }` |
| 51 | + } |
| 52 | +]; |
| 53 | + |
| 54 | +function setFlag(state) { |
| 55 | + let file = files.find(file => file.filename === 'twiddle.json'); |
| 56 | + let twiddleJSON = JSON.parse(file.content); |
| 57 | + twiddleJSON.EmberENV["_TEMPLATE_ONLY_GLIMMER_COMPONENTS"] = state; |
| 58 | + file.content = JSON.stringify(twiddleJSON); |
| 59 | +} |
| 60 | + |
| 61 | +module('Acceptance | template-only-glimmer-components', function(hooks) { |
| 62 | + setupApplicationTest(hooks); |
| 63 | + setupMirage(hooks); |
| 64 | + |
| 65 | + test('template only glimmer components off', async function(assert) { |
| 66 | + |
| 67 | + setFlag(false); |
| 68 | + |
| 69 | + await runGist(files); |
| 70 | + |
| 71 | + assert.equal(outputPane().document.querySelector('.test-parent').textContent.trim(), 'Ember Twiddle', 'content loaded'); |
| 72 | + assert.equal(outputPane().document.querySelectorAll('.test-parent>.ember-view').length, 1, 'content is inside wrapper div'); |
| 73 | + }); |
| 74 | + |
| 75 | + test('template only glimmer components on', async function(assert) { |
| 76 | + |
| 77 | + setFlag(true); |
| 78 | + |
| 79 | + await runGist(files); |
| 80 | + |
| 81 | + assert.equal(outputPane().document.querySelector('.test-parent').textContent.trim(), 'Ember Twiddle', 'content loaded'); |
| 82 | + assert.equal(outputPane().document.querySelectorAll('.test-parent>.ember-view').length, 0, 'content is not inside wrapper div'); |
| 83 | + }); |
| 84 | +}); |
0 commit comments