@@ -14,6 +14,7 @@ import { BoxelInput } from '@cardstack/boxel-ui/components';
14
14
import { Loader , CardContextName , type Query } from ' @cardstack/runtime-common' ;
15
15
16
16
import { getSearch } from ' @cardstack/host/resources/search' ;
17
+ import { getCard } from ' @cardstack/host/resources/card-resource' ;
17
18
import LoaderService from ' @cardstack/host/services/loader-service' ;
18
19
19
20
import {
@@ -161,7 +162,6 @@ module('Integration | card api (Usage of publicAPI actions)', function (hooks) {
161
162
},
162
163
});
163
164
});
164
-
165
165
test (` changing query updates search resource ` , async function (assert ) {
166
166
class Isolated extends Component <typeof AuthorSearch > {
167
167
@tracked name = ' Jane' ;
@@ -254,6 +254,109 @@ module('Integration | card api (Usage of publicAPI actions)', function (hooks) {
254
254
.exists ({ count: 2 });
255
255
});
256
256
});
257
+
258
+ module (' getCard' , function (_ ) {
259
+ hooks .beforeEach (async function (this : RenderingTestContext ) {
260
+ class StringFieldWithValue extends StringField {
261
+ static displayName = ' StringFieldWithValue' ;
262
+
263
+ static edit = class Edit extends Component <
264
+ typeof StringFieldWithValue
265
+ > {
266
+ <template >
267
+ {{@ model }}
268
+ <BoxelInput @ value ={{@ model }} @ onInput ={{@ set }} />
269
+ </template >
270
+ };
271
+ }
272
+
273
+ class SimpleCard extends CardDef {
274
+ static displayName = ' SimpleCard' ;
275
+ @field name = contains (StringFieldWithValue );
276
+
277
+ static edit = class Edit extends Component <typeof this > {
278
+ <template >
279
+ <@ fields.name />
280
+ </template >
281
+ };
282
+ }
283
+ await setupIntegrationTestRealm ({
284
+ loader ,
285
+ mockMatrixUtils ,
286
+ contents: {
287
+ ' simple-card.gts' : { SimpleCard },
288
+ ' simple-card.json' : {
289
+ data: {
290
+ type: ' card' ,
291
+ attributes: {
292
+ name: ' Jane Doe' ,
293
+ },
294
+ meta: {
295
+ adoptsFrom: {
296
+ module: ` ${testRealmURL }simple-card ` ,
297
+ name: ' SimpleCard' ,
298
+ },
299
+ },
300
+ },
301
+ },
302
+ },
303
+ });
304
+ });
305
+
306
+ test (' accessing property of card in getter should not cause re-render of the component' , async function (assert ) {
307
+ class SampleUsageWithGetCard extends CardDef {
308
+ static displayName = ' SampleUsageWithGetCard' ;
309
+ @field name = contains (StringField );
310
+ @field title = contains (StringField , {
311
+ computeVia : function (this : SampleUsageWithGetCard ) {
312
+ return this .name ;
313
+ },
314
+ });
315
+
316
+ static edit = class Edit extends Component <
317
+ typeof SampleUsageWithGetCard
318
+ > {
319
+ get id() {
320
+ return ` ${testRealmURL }simple-card ` ;
321
+ }
322
+
323
+ private resource = getCard (this , () => this .id );
324
+
325
+ get card() {
326
+ // console.log(this.resource.card.name); //<- this will cause a re-render
327
+ return this .resource .card ;
328
+ }
329
+
330
+ <template >
331
+ {{#if this . card }}
332
+ {{#let ( getComponent this . card) as | CardComponent | }}
333
+ <CardComponent />
334
+ {{/let }}
335
+ {{else }}
336
+ <div >
337
+ Loading...
338
+ </div >
339
+ {{/if }}
340
+ </template >
341
+ };
342
+ }
343
+ let card = new SampleUsageWithGetCard ();
344
+ await renderComponent (
345
+ class TestDriver extends GlimmerComponent {
346
+ <template >
347
+ <CardContextProvider >
348
+ <CardContextConsumer >
349
+ {{#let ( getComponent card ) as | Card | }}
350
+ <Card @ format =' edit' />
351
+ {{/let }}
352
+ </CardContextConsumer >
353
+ </CardContextProvider >
354
+ </template >
355
+ },
356
+ );
357
+ assert .ok (true );
358
+ });
359
+ });
257
360
});
258
361
259
362
function getComponent(cardOrField : any ) {
0 commit comments