From e29b9066d1691ea0e2c7e413c3acb3ad07ddecd4 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Wed, 9 Feb 2022 21:29:32 -0500 Subject: [PATCH 1/2] improving ember-data test coverage This exercises ember-data within the fully-static app scenario. And adds a default packageRule that covers something needed by ember-data 3.24. --- .../src/addon-dependency-rules/ember-data.ts | 3 ++ tests/scenarios/static-app-test.ts | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/packages/compat/src/addon-dependency-rules/ember-data.ts b/packages/compat/src/addon-dependency-rules/ember-data.ts index b0de7993b..8fa811a22 100644 --- a/packages/compat/src/addon-dependency-rules/ember-data.ts +++ b/packages/compat/src/addon-dependency-rules/ember-data.ts @@ -10,6 +10,9 @@ let rules: PackageRules[] = [ '-private/system/core-store.js': { dependsOnModules: ['@ember-data/record-data/-private'], }, + '-private/system/model/internal-model.js': { + dependsOnModules: ['@ember-data/model/-private'], + }, }, }, ]; diff --git a/tests/scenarios/static-app-test.ts b/tests/scenarios/static-app-test.ts index 7d4f60a88..7588952fb 100644 --- a/tests/scenarios/static-app-test.ts +++ b/tests/scenarios/static-app-test.ts @@ -58,6 +58,27 @@ appScenarios export default helper(loadedHelpers); `, }, + models: { + 'post.js': ` + import Model, { attr } from '@ember-data/model'; + export default class PostModel extends Model { + @attr() title; + } + `, + }, + routes: { + 'ember-data-example.js': ` + import Route from '@ember/routing/route'; + import { inject as service } from '@ember/service'; + + export default class EmberDataExampleRoute extends Route { + @service() store; + model() { + return this.store.findRecord('post', 0); + } + } + `, + }, templates: { components: { 'default-title.hbs': ` @@ -98,6 +119,7 @@ appScenarios `, + 'ember-data-example.hbs': `

{{@model.title}}

`, }, 'router.js': ` import EmberRouter from '@ember/routing/router'; @@ -113,9 +135,23 @@ appScenarios this.route('components-example'); this.route('static-component-rules-example'); this.route('macros-example'); + this.route('ember-data-example'); }); `, }, + public: { + posts: { + '0': JSON.stringify({ + data: { + type: 'posts', + id: '0 ', + attributes: { + title: 'Hello world', + }, + }, + }), + }, + }, tests: { acceptance: { 'components-example-test.js': ` @@ -212,6 +248,21 @@ appScenarios }); }); `, + 'ember-data-example-test.js': ` + import { module, test } from 'qunit'; + import { visit, currentURL } from '@ember/test-helpers'; + import { setupApplicationTest } from 'ember-qunit'; + + module('Acceptance | ember data example', function (hooks) { + setupApplicationTest(hooks); + + test('visiting /ember-data-example', async function (assert) { + await visit('/ember-data-example'); + assert.equal(currentURL(), '/ember-data-example'); + assert.dom('h1').containsText('Hello world'); + }); + }); + `, }, unit: { 'missing-import-sync-renamed-test.js': ` From ad08f5f0090a938608b35c393ffcda50a42c9171 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Wed, 9 Feb 2022 22:20:39 -0500 Subject: [PATCH 2/2] fix ember-data test data stubbing Using /public doesn't work without more config using testem. --- tests/scenarios/static-app-test.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tests/scenarios/static-app-test.ts b/tests/scenarios/static-app-test.ts index 7588952fb..1ead5d8fc 100644 --- a/tests/scenarios/static-app-test.ts +++ b/tests/scenarios/static-app-test.ts @@ -13,6 +13,16 @@ appScenarios merge(project.files, { app: { + adapters: { + 'post.js': ` + import JSONAPIAdapter from '@ember-data/adapter/json-api'; + export default class PostAdapter extends JSONAPIAdapter { + findRecord(store, type, id, snapshot) { + return { data: { type: 'posts', id: '0 ', attributes: { title: 'Hello world' } } }; + } + } + `, + }, components: { 'fancy-box.js': ` import Component from '@glimmer/component'; @@ -139,19 +149,6 @@ appScenarios }); `, }, - public: { - posts: { - '0': JSON.stringify({ - data: { - type: 'posts', - id: '0 ', - attributes: { - title: 'Hello world', - }, - }, - }), - }, - }, tests: { acceptance: { 'components-example-test.js': `