Skip to content

Commit

Permalink
Failing tests for #15635
Browse files Browse the repository at this point in the history
  • Loading branch information
chancancode committed Feb 11, 2020
1 parent 80325ec commit 0d49231
Showing 1 changed file with 121 additions and 59 deletions.
180 changes: 121 additions & 59 deletions packages/@ember/-internals/glimmer/tests/integration/content-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<p>hello</p>');
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 = `
<div class="header">
<h1>Welcome to Ember.js</h1>
</div>
<div class="body">
<h2>Why you should use Ember.js?</h2>
<ol>
<li>It's great</li>
<li>It's awesome</li>
<li>It's Ember.js</li>
</ol>
</div>
<div class="footer">
Ember.js is free, open source and always will be.
</div>
`;
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('<p>hello</p>');
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 = `
<div class="header">
<h1>Welcome to Ember.js</h1>
</div>
<div class="body">
<h2>Why you should use Ember.js?</h2>
<ol>
<li>It's great</li>
<li>It's awesome</li>
<li>It's Ember.js</li>
</ol>
</div>
<div class="footer">
Ember.js is free, open source and always will be.
</div>
`;

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 */
Expand Down Expand Up @@ -588,9 +662,7 @@ class DynamicContentTest extends RenderingTestCase {
}
}

const EMPTY = {};

class ContentTestGenerator {
class DynamicContentTestGenerator {
constructor(cases, tag = '@test') {
this.cases = cases;
this.tag = tag;
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -679,7 +741,7 @@ const SharedContentTestCases = new ContentTestGenerator([
['<b>Max</b><b>James</b>', '<b>Max</b><b>James</b>'],
]);

let GlimmerContentTestCases = new ContentTestGenerator([
let GlimmerContentTestCases = new DynamicContentTestGenerator([
[Object.create(null), EMPTY, 'an object with no toString'],
]);

Expand Down

0 comments on commit 0d49231

Please sign in to comment.