From 5e8d2bdaa383f3af399909ebd4ca2894adc540fd Mon Sep 17 00:00:00 2001 From: snewcomer Date: Fri, 10 Jan 2020 13:36:20 -0800 Subject: [PATCH 1/8] add ChangesetForm for testing purposes --- tests/dummy/app/components/changeset-form.ts | 22 +++++++++++++++++++ tests/dummy/app/templates/application.hbs | 4 +++- .../templates/components/changeset-form.hbs | 15 +++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/dummy/app/components/changeset-form.ts create mode 100644 tests/dummy/app/templates/components/changeset-form.hbs diff --git a/tests/dummy/app/components/changeset-form.ts b/tests/dummy/app/components/changeset-form.ts new file mode 100644 index 00000000..4d1c0471 --- /dev/null +++ b/tests/dummy/app/components/changeset-form.ts @@ -0,0 +1,22 @@ +import Component from '@ember/component'; +// @ts-ignore: Ignore import of compiled template +/* import layout from '../templates/components/changeset-form'; */ +/* import { tracked } from '@glimmer/tracking'; */ +import { action } from '@ember/object'; +import Changeset from 'ember-changeset' + +export default class ChangesetForm extends Component.extend({ + // anything which *must* be merged to prototype here +}) { + model = { + email: 'something' + } + + changeset = new Changeset(this.model) + // normal class body definition here + + @action submitForm(changeset: any, event: any) { + event.preventDefault() + changeset.save() + } +} diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs index a4b691ce..5df38c17 100644 --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -1,3 +1,5 @@ -

Hello world

+

Basic Form

+ + {{outlet}} diff --git a/tests/dummy/app/templates/components/changeset-form.hbs b/tests/dummy/app/templates/components/changeset-form.hbs new file mode 100644 index 00000000..d15af4f8 --- /dev/null +++ b/tests/dummy/app/templates/components/changeset-form.hbs @@ -0,0 +1,15 @@ +Changeset value: "{{this.changeset.email}}" +
+Model value: "{{this.model.email}}" + +
+ + + +
From d79dbd2552205d76303310db90d852dfaa079485 Mon Sep 17 00:00:00 2001 From: snewcomer Date: Fri, 10 Jan 2020 13:39:30 -0800 Subject: [PATCH 2/8] Add safeSet for Ember tracking context --- addon/utils/merge-deep.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/utils/merge-deep.ts b/addon/utils/merge-deep.ts index 9bcba764..5130eb2b 100644 --- a/addon/utils/merge-deep.ts +++ b/addon/utils/merge-deep.ts @@ -101,11 +101,11 @@ function mergeTargetAndSource(target: any, source: any, options: Options): any { } else { let next = source[key]; if (next && next instanceof Change) { - return target[key] = next.value; + return options.safeSet(target, key, next.value); } // if just some normal leaf value, then set - return target[key] = next; + return options.safeSet(target, key, next); } }); From 5feb08953f68f114f5eb48b3169680e900009f12 Mon Sep 17 00:00:00 2001 From: snewcomer Date: Fri, 10 Jan 2020 13:42:32 -0800 Subject: [PATCH 3/8] fix test --- addon/utils/merge-deep.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/utils/merge-deep.ts b/addon/utils/merge-deep.ts index 5130eb2b..f82e0b74 100644 --- a/addon/utils/merge-deep.ts +++ b/addon/utils/merge-deep.ts @@ -123,7 +123,7 @@ function mergeTargetAndSource(target: any, source: any, options: Options): any { */ export default function mergeDeep(target: any, source: any, options: Options = { safeGet: undefined, safeSet: undefined }): object | [any] { options.safeGet = options.safeGet || function (obj: any, key: string): any { return obj[key] }; - options.safeSet = options.safeSet; + options.safeSet = options.safeSet || function(obj: any, key: string, value: unknown): any { return obj[key] = value }; let sourceIsArray = Array.isArray(source); let targetIsArray = Array.isArray(target); let sourceAndTargetTypesMatch = sourceIsArray === targetIsArray; From 58635514a694a7c738880f40ed5b605df218cecb Mon Sep 17 00:00:00 2001 From: snewcomer Date: Fri, 10 Jan 2020 13:43:42 -0800 Subject: [PATCH 4/8] cleanup templates --- tests/dummy/app/components/changeset-form.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/dummy/app/components/changeset-form.ts b/tests/dummy/app/components/changeset-form.ts index 4d1c0471..e9297142 100644 --- a/tests/dummy/app/components/changeset-form.ts +++ b/tests/dummy/app/components/changeset-form.ts @@ -1,20 +1,13 @@ import Component from '@ember/component'; -// @ts-ignore: Ignore import of compiled template -/* import layout from '../templates/components/changeset-form'; */ -/* import { tracked } from '@glimmer/tracking'; */ import { action } from '@ember/object'; import Changeset from 'ember-changeset' -export default class ChangesetForm extends Component.extend({ - // anything which *must* be merged to prototype here -}) { +export default class ChangesetForm extends Component.extend() { model = { email: 'something' } changeset = new Changeset(this.model) - // normal class body definition here - @action submitForm(changeset: any, event: any) { event.preventDefault() changeset.save() From ed9bd66467bcc46437b9fd3893c16982d946725a Mon Sep 17 00:00:00 2001 From: snewcomer Date: Fri, 10 Jan 2020 14:19:52 -0800 Subject: [PATCH 5/8] cleanup coponent --- tests/dummy/app/components/changeset-form.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/dummy/app/components/changeset-form.ts b/tests/dummy/app/components/changeset-form.ts index e9297142..c4a1a51a 100644 --- a/tests/dummy/app/components/changeset-form.ts +++ b/tests/dummy/app/components/changeset-form.ts @@ -2,12 +2,13 @@ import Component from '@ember/component'; import { action } from '@ember/object'; import Changeset from 'ember-changeset' -export default class ChangesetForm extends Component.extend() { +export default class ChangesetForm extends Component { model = { email: 'something' } changeset = new Changeset(this.model) + @action submitForm(changeset: any, event: any) { event.preventDefault() changeset.save() From 3f4b56a434565ede70b59d944aded97b63f40f85 Mon Sep 17 00:00:00 2001 From: snewcomer Date: Fri, 10 Jan 2020 15:25:41 -0800 Subject: [PATCH 6/8] does the failure have to be the last one? --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3eee6f84..13f4bdb5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,8 +51,8 @@ jobs: env: EMBER_TRY_SCENARIO=ember-3.13 - env: EMBER_TRY_SCENARIO=ember-release - env: EMBER_TRY_SCENARIO=ember-beta - - env: EMBER_TRY_SCENARIO=ember-canary - env: EMBER_TRY_SCENARIO=ember-default-with-jquery + - env: EMBER_TRY_SCENARIO=ember-canary before_install: - curl -o- -L https://yarnpkg.com/install.sh | bash From 20df364bcf216b5944b177cc4a424d62ae9deffb Mon Sep 17 00:00:00 2001 From: snewcomer Date: Fri, 10 Jan 2020 16:27:19 -0800 Subject: [PATCH 7/8] add allowedToFail --- config/ember-try.js | 1 + 1 file changed, 1 insertion(+) diff --git a/config/ember-try.js b/config/ember-try.js index 814fc47b..c7663502 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -32,6 +32,7 @@ module.exports = async function() { }, { name: 'ember-canary', + allowedToFail: true, npm: { devDependencies: { 'ember-source': await getChannelURL('canary') From f35fcad35f5620097f34bb7e8a0b8ceb7e170085 Mon Sep 17 00:00:00 2001 From: snewcomer Date: Fri, 10 Jan 2020 16:50:05 -0800 Subject: [PATCH 8/8] add test for copmonent form --- .../app/templates/components/changeset-form.hbs | 7 ++++--- .../components/changeset-form-test.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tests/integration/components/changeset-form-test.js diff --git a/tests/dummy/app/templates/components/changeset-form.hbs b/tests/dummy/app/templates/components/changeset-form.hbs index d15af4f8..eee2fd44 100644 --- a/tests/dummy/app/templates/components/changeset-form.hbs +++ b/tests/dummy/app/templates/components/changeset-form.hbs @@ -1,15 +1,16 @@ -Changeset value: "{{this.changeset.email}}" +

Changeset value: {{this.changeset.email}}


-Model value: "{{this.model.email}}" +

Model value: {{this.model.email}}

- +
diff --git a/tests/integration/components/changeset-form-test.js b/tests/integration/components/changeset-form-test.js new file mode 100644 index 00000000..de44e690 --- /dev/null +++ b/tests/integration/components/changeset-form-test.js @@ -0,0 +1,17 @@ +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { click, find, fillIn, render } from '@ember/test-helpers'; +import hbs from 'htmlbars-inline-precompile'; + +module('Integration | Component | changeset-form', function(hooks) { + setupRenderingTest(hooks); + + test('it renders', async function(assert) { + await render(hbs``); + await fillIn('[data-test-email]', 'foo'); + await click('[data-test-submit]'); + + assert.equal(find('[data-test-model-email]').textContent.trim(), 'foo', 'has email after submit'); + assert.equal(find('[data-test-changeset-email]').textContent.trim(), 'foo', 'changeset has email after submit'); + }); +});