Skip to content

Commit 9c36cae

Browse files
committed
[Bug] Render multiple cards successfully
- Add integration test covering two card sections in one mobiledoc - Ensure all afterRender mutations use schedule instead of scheduleOnce
1 parent 3b44547 commit 9c36cae

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

addon/components/render-mobiledoc.gts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Component from '@glimmer/component';
22
import { tracked } from '@glimmer/tracking';
3-
import { scheduleOnce } from '@ember/runloop';
3+
import { schedule, scheduleOnce } from '@ember/runloop';
44
import Renderer from 'ember-mobiledoc-dom-renderer';
55
import { getDocument } from 'ember-mobiledoc-dom-renderer/utils/document';
66
import { guidFor } from '@ember/object/internals';
@@ -324,7 +324,7 @@ export default class RenderMobiledocComponent extends Component<Signature> {
324324

325325
private addCard(card: CardRegistration): void {
326326
// Defer mutation to after the current render to avoid updating a value during computation
327-
scheduleOnce('afterRender', this, this._addCard, card);
327+
schedule('afterRender', this, this._addCard, card);
328328
}
329329

330330
private _addCard(card: CardRegistration): void {
@@ -333,7 +333,7 @@ export default class RenderMobiledocComponent extends Component<Signature> {
333333

334334
private removeCard(card: CardRegistration): void {
335335
// Defer mutation to after the current render to avoid updating a value during computation
336-
scheduleOnce('afterRender', this, this._removeCard, card);
336+
schedule('afterRender', this, this._removeCard, card);
337337
}
338338

339339
private _removeCard(card: CardRegistration): void {
@@ -344,7 +344,7 @@ export default class RenderMobiledocComponent extends Component<Signature> {
344344

345345
private addAtom(atom: AtomRegistration): void {
346346
// Defer mutation to after the current render to avoid updating a value during computation
347-
scheduleOnce('afterRender', this, this._addAtom, atom);
347+
schedule('afterRender', this, this._addAtom, atom);
348348
}
349349

350350
private _addAtom(atom: AtomRegistration): void {
@@ -353,7 +353,7 @@ export default class RenderMobiledocComponent extends Component<Signature> {
353353

354354
private removeAtom(atom: AtomRegistration): void {
355355
// Defer mutation to after the current render to avoid updating a value during computation
356-
scheduleOnce('afterRender', this, this._removeAtom, atom);
356+
schedule('afterRender', this, this._removeAtom, atom);
357357
}
358358

359359
private _removeAtom(atom: AtomRegistration): void {

tests/integration/components/render-mobiledoc-test.gts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,44 @@ module('Integration | Component | render-mobiledoc', function (hooks) {
7474
.exists(`renders card with class ${CARD_ELEMENT_CLASS}-${cardName}`);
7575
});
7676

77+
test('it renders multiple cards in a single mobiledoc', async function (this: MobiledocTestContext, assert) {
78+
const secondCardName = 'test-card';
79+
this.set('mobiledoc', {
80+
version: '0.3.1',
81+
markups: [],
82+
atoms: [],
83+
cards: [
84+
[cardName, { foo: 'bar' }],
85+
[secondCardName, { foo: 'baz' }],
86+
],
87+
sections: [
88+
[10, 0],
89+
[10, 1],
90+
],
91+
});
92+
this.set('cardNames', [cardName, secondCardName]);
93+
const context = this;
94+
95+
await render(
96+
<template>
97+
<RenderMobiledoc
98+
@mobiledoc={{context.mobiledoc}}
99+
@cardNames={{context.cardNames}}
100+
/>
101+
</template>,
102+
);
103+
104+
assert
105+
.dom(`.${CARD_ELEMENT_CLASS}`)
106+
.exists({ count: 2 }, 'renders a card element for each card section');
107+
assert
108+
.dom('#sample-test-card')
109+
.hasText('foo: bar', 'renders the first card payload');
110+
assert
111+
.dom('.test-card-component-payload')
112+
.hasText('baz', 'renders the second card payload');
113+
});
114+
77115
test('it uses `cardNameToComponentName` to allow selecting components (inheritance)', async function (this: MobiledocTestContext, assert) {
78116
this.set('mobiledoc', createMobiledocWithCard(cardName));
79117
this.set('cardNames', [cardName]);

0 commit comments

Comments
 (0)