Skip to content

Commit

Permalink
fix tests for embroider-optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
poulet42 committed May 25, 2023
1 parent 3368343 commit 50b64fa
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
1 change: 1 addition & 0 deletions test-app/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module.exports = {
// test files
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
rules: { 'ember/no-empty-glimmer-component-classes': 'off' },
},
],
};
1 change: 0 additions & 1 deletion test-app/app/components/group-list-item.hbs

This file was deleted.

1 change: 0 additions & 1 deletion test-app/app/components/hyperlink.hbs

This file was deleted.

1 change: 0 additions & 1 deletion test-app/app/components/list-item.hbs

This file was deleted.

52 changes: 49 additions & 3 deletions test-app/tests/integration/components/prismic/dom-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { render } from '@ember/test-helpers';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';
import { setComponentTemplate } from '@ember/component';
import Component from '@glimmer/component';

import { hbs } from 'ember-cli-htmlbars';

Expand All @@ -18,6 +20,14 @@ module('Integration | Component | prismic/dom', function (hooks) {

module('custom elements', function () {
test('hyperlink', async function (assert) {
class Hyperlink extends Component {}
setComponentTemplate(
hbs`<a href={{@node.element.data.url}}>{{yield}}</a>`,
Hyperlink
);

this.hyperlink = Hyperlink;

this.nodes = [
{
type: 'paragraph',
Expand All @@ -34,32 +44,68 @@ module('Integration | Component | prismic/dom', function (hooks) {
];

await render(
hbs`<Prismic::Dom @nodes={{this.nodes}} @hyperlink='hyperlink'/>`
hbs`<Prismic::Dom @nodes={{this.nodes}} @hyperlink={{this.hyperlink}} />`
);
assert.strictEqual(
cleanHtml(this),
'<div><p>A <a href="https://example.org">link</a> to somewhere</p></div>'
);
});

test('handle passing a custom component as a string', async function (assert) {
class SuperCustom extends Component {}
setComponentTemplate(hbs`<mark>{{yield}}</mark>`, SuperCustom);

this.nodes = [
{
type: 'paragraph',
text: 'A fancy component',
spans: [
{
start: 2,
end: 7,
type: 'super-custom',
},
],
},
];
this.owner.register('component:super-custom', SuperCustom);

await render(
hbs`<Prismic::Dom @nodes={{this.nodes}} @super-custom="super-custom" />`
);

assert.strictEqual(
cleanHtml(this),
'<div><p>A <mark>fancy</mark> component</p></div>'
);
});

test('list', async function (assert) {
class GroupListItem extends Component {}
class ListItem extends Component {}

setComponentTemplate(hbs`<ul>{{~yield~}}elephant</ul>`, GroupListItem);
setComponentTemplate(hbs`<li>{{~yield}} bananna</li>`, ListItem);

this.nodes = [
{ type: 'list-item', text: 'one', spans: [] },
{ type: 'list-item', text: 'two', spans: [] },
];

this.groupListItem = GroupListItem;
this.listItem = '';

await render(
hbs`<Prismic::Dom @nodes={{this.nodes}} @group-list-item='group-list-item' @list-item={{this.listItem}}/>`
hbs`<Prismic::Dom @nodes={{this.nodes}} @group-list-item={{this.groupListItem}} @list-item={{this.listItem}}/>`
);

assert.strictEqual(
cleanHtml(this),
'<div><ul><li>one</li><li>two</li>elephant</ul></div>'
);

this.set('listItem', 'list-item');
this.set('listItem', ListItem);

assert.strictEqual(
cleanHtml(this),
Expand Down

0 comments on commit 50b64fa

Please sign in to comment.