diff --git a/packages/@ember/-internals/glimmer/tests/integration/content-test.js b/packages/@ember/-internals/glimmer/tests/integration/content-test.js index 1d04465daab..b6c0bc28245 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/content-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/content-test.js @@ -10,61 +10,135 @@ import { HAS_NATIVE_SYMBOL } from '@ember/-internals/utils'; import { constructStyleDeprecationMessage } from '@ember/-internals/views'; import { Component, SafeString, htmlSafe } from '../utils/helpers'; -moduleFor( - 'Static content tests', - class extends RenderingTestCase { - ['@test it can render a static text node']() { - this.render('hello'); - let text1 = this.assertTextNode(this.firstChild, 'hello'); +const EMPTY = Object.freeze({}); - runTask(() => this.rerender()); +const LITERALS = [ + ['foo', 'foo', '"foo"'], + [undefined, EMPTY], + [null, EMPTY], + [true, 'true'], + [false, 'false'], + [0, '0', '0'], + [-0, '0', '-0'], + [1, '1', '1'], + [-1, '-1', '-1'], + [0.0, '0', '0.0'], + [0.5, '0.5', '0.5'], +]; - let text2 = this.assertTextNode(this.firstChild, 'hello'); +let i = Number.MAX_SAFE_INTEGER; - this.assertSameNode(text1, text2); - } +while (i > 1) { + LITERALS.push([i, `${i}`, `${i}`]); + i = Math.round(i / 2); +} - ['@test it can render a static element']() { - this.render('

hello

'); - let p1 = this.assertElement(this.firstChild, { tagName: 'p' }); - let text1 = this.assertTextNode(this.firstChild.firstChild, 'hello'); +i = Number.MIN_SAFE_INTEGER; - runTask(() => this.rerender()); +while (i < -1) { + LITERALS.push([i, `${i}`, `${i}`]); + i = Math.round(i / 2); +} - let p2 = this.assertElement(this.firstChild, { tagName: 'p' }); - let text2 = this.assertTextNode(this.firstChild.firstChild, 'hello'); +class StaticContentTest extends RenderingTestCase { + ['@test it can render a static text node']() { + this.render('hello'); + let text1 = this.assertTextNode(this.firstChild, 'hello'); - this.assertSameNode(p1, p2); - this.assertSameNode(text1, text2); - } + runTask(() => this.rerender()); - ['@test it can render a static template']() { - let template = ` -
-

Welcome to Ember.js

-
-
-

Why you should use Ember.js?

-
    -
  1. It's great
  2. -
  3. It's awesome
  4. -
  5. It's Ember.js
  6. -
-
- - `; + let text2 = this.assertTextNode(this.firstChild, 'hello'); - this.render(template); - this.assertHTML(template); + this.assertSameNode(text1, text2); + } - runTask(() => this.rerender()); + ['@test it can render a static element']() { + this.render('

hello

'); + let p1 = this.assertElement(this.firstChild, { tagName: 'p' }); + let text1 = this.assertTextNode(this.firstChild.firstChild, 'hello'); - this.assertHTML(template); - } + runTask(() => this.rerender()); + + let p2 = this.assertElement(this.firstChild, { tagName: 'p' }); + let text2 = this.assertTextNode(this.firstChild.firstChild, 'hello'); + + this.assertSameNode(p1, p2); + this.assertSameNode(text1, text2); } -); + + ['@test it can render a static template']() { + let template = ` +
+

Welcome to Ember.js

+
+
+

Why you should use Ember.js?

+
    +
  1. It's great
  2. +
  3. It's awesome
  4. +
  5. It's Ember.js
  6. +
+
+ + `; + + this.render(template); + this.assertHTML(template); + + runTask(() => this.rerender()); + + this.assertHTML(template); + } +} + +class StaticContentTestGenerator { + constructor(cases, tag = '@test') { + this.cases = cases; + this.tag = tag; + } + + generate([value, expected, label]) { + let tag = this.tag; + label = label || value; + + return { + [`${tag} rendering {{${label}}}`]() { + this.render(`{{${label}}}`); + + if (expected === EMPTY) { + this.assertHTML(''); + } else { + this.assertHTML(expected); + } + + this.assertStableRerender(); + }, + + [`${tag} rendering {{to-js ${label}}}`](assert) { + this.registerHelper('to-js', ([actual]) => { + assert.strictEqual(actual, value); + return actual; + }); + + this.render(`{{to-js ${label}}}`); + + if (expected === EMPTY) { + this.assertHTML(''); + } else { + this.assertHTML(expected); + } + + this.assertStableRerender(); + }, + }; + } +} + +applyMixins(StaticContentTest, new StaticContentTestGenerator(LITERALS)); + +moduleFor('Static content tests', StaticContentTest); class DynamicContentTest extends RenderingTestCase { /* abstract */ @@ -588,9 +662,7 @@ class DynamicContentTest extends RenderingTestCase { } } -const EMPTY = {}; - -class ContentTestGenerator { +class DynamicContentTestGenerator { constructor(cases, tag = '@test') { this.cases = cases; this.tag = tag; @@ -639,18 +711,8 @@ class ContentTestGenerator { } } -const SharedContentTestCases = new ContentTestGenerator([ - ['foo', 'foo'], - [0, '0'], - [-0, '0', '-0'], - [1, '1'], - [-1, '-1'], - [0.0, '0', '0.0'], - [0.5, '0.5'], - [undefined, EMPTY], - [null, EMPTY], - [true, 'true'], - [false, 'false'], +const SharedContentTestCases = new DynamicContentTestGenerator([ + ...LITERALS, [NaN, 'NaN'], [new Date(2000, 0, 1), String(new Date(2000, 0, 1)), 'a Date object'], [Infinity, 'Infinity'], @@ -679,7 +741,7 @@ const SharedContentTestCases = new ContentTestGenerator([ ['MaxJames', 'MaxJames'], ]); -let GlimmerContentTestCases = new ContentTestGenerator([ +let GlimmerContentTestCases = new DynamicContentTestGenerator([ [Object.create(null), EMPTY, 'an object with no toString'], ]);