Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.17 tests #438

Merged
merged 4 commits into from
Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ branches:
jobs:
fast_finish: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-release
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default class Foo extends Component<Args> {

constructor(owner, args) {
super(owner, args);
this.changeset = new Changeset(args.user);
this.changeset = Changeset(args.user);
}
}
```
Expand Down
10 changes: 5 additions & 5 deletions addon/helpers/changeset.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { helper } from '@ember/component/helper';
import Changeset from 'ember-changeset';
import { Changeset } from 'ember-changeset';
import { lookupValidator, isChangeset, isPromise, isObject } from 'validated-changeset';

export function changeset(
Expand All @@ -13,18 +13,18 @@ export function changeset(
if (isObject(validations)) {
if (isPromise(obj)) {
return obj.then((resolved) =>
new Changeset(resolved, lookupValidator(validations), validations, options)
Changeset(resolved, lookupValidator(validations), validations, options)
);
}

return new Changeset(obj, lookupValidator(validations), validations, options);
return Changeset(obj, lookupValidator(validations), validations, options);
}

if (isPromise(obj)) {
return Promise.resolve(obj).then((resolved) => new Changeset(resolved, validations, {}, options));
return Promise.resolve(obj).then((resolved) => Changeset(resolved, validations, {}, options));
}

return new Changeset(obj, validations, {}, options);
return Changeset(obj, validations, {}, options);
}

export default helper(changeset);
2 changes: 1 addition & 1 deletion addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class EmberChangeset extends BufferedChangeset {


// return getters/setters/methods on BufferedProxy instance
if (this[key]) {
if (typeof this[key] !== 'undefined') {
return this[key];
} else if (this[baseKey]) {
const v = this[baseKey];
Expand Down
1 change: 0 additions & 1 deletion config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module.exports = async function() {
},
{
name: 'ember-release',
allowedToFail: true,
npm: {
devDependencies: {
'ember-source': await getChannelURL('release')
Expand Down
6 changes: 5 additions & 1 deletion tests/dummy/app/components/changeset-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export default class ChangesetForm extends Component {
}
}

changeset = Changeset(this.model)
init() {
super.init(...arguments);

this.changeset = Changeset(this.model)
}

@action
submitForm(changeset, event) {
Expand Down
82 changes: 41 additions & 41 deletions tests/integration/components/changeset-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { typeOf, isPresent } from '@ember/utils';
import Changeset from 'ember-changeset';
import { Changeset } from 'ember-changeset';
import hbs from 'htmlbars-inline-precompile';
import {
render,
Expand Down Expand Up @@ -228,7 +228,7 @@ module('Integration | Helper | changeset', function(hooks) {
this.set('dummyModel', { firstName: 'Jim', lastName: 'Bob' });
this.set('validate', () => true);
await render(hbs`
{{#with (changeset dummyModel (action validate)) as |changesetObj|}}
{{#with (changeset this.dummyModel (action this.validate)) as |changesetObj|}}
<h1>{{changesetObj.firstName}} {{changesetObj.lastName}}</h1>
<input
id="first-name"
Expand All @@ -247,18 +247,18 @@ module('Integration | Helper | changeset', function(hooks) {

test('a passed down nested object updates when set without a validator', async function(assert) {
let data = { person: { firstName: 'Jim', lastName: 'Bob' } };
let changeset = new Changeset(data);
let changeset = Changeset(data);
this.set('changeset', changeset);
await render(hbs`
<h1>{{changeset.person.firstName}} {{changeset.person.lastName}}</h1>
<h1>{{this.changeset.person.firstName}} {{this.changeset.person.lastName}}</h1>
<input
id="first-name"
value={{changeset.person.firstName}}
onchange={{action (changeset-set changeset "person.firstName") value="target.value"}}>
value={{this.changeset.person.firstName}}
onchange={{action (changeset-set this.changeset "person.firstName") value="target.value"}}>
>
<input id="last-name"
value={{changeset.person.lastName}}
onchange={{action (changeset-set changeset "person.lastName") value="target.value"}}>
value={{this.changeset.person.lastName}}
onchange={{action (changeset-set this.changeset "person.lastName") value="target.value"}}>
`);

assert.equal(find('h1').textContent.trim(), 'Jim Bob', 'precondition');
Expand All @@ -277,18 +277,18 @@ module('Integration | Helper | changeset', function(hooks) {

test('nested object updates when set without a validator', async function(assert) {
let data = { person: { firstName: 'Jim', lastName: 'Bob' } };
let changeset = new Changeset(data);
let changeset = Changeset(data);
this.set('changeset', changeset);
await render(hbs`
<h1>{{changeset.person.firstName}} {{changeset.person.lastName}}</h1>
<h1>{{this.changeset.person.firstName}} {{this.changeset.person.lastName}}</h1>
<input
id="first-name"
value={{changeset.person.firstName}}
onchange={{action (changeset-set changeset "person.firstName") value="target.value"}}>
value={{this.changeset.person.firstName}}
onchange={{action (changeset-set this.changeset "person.firstName") value="target.value"}}>
<input
id="last-name"
value={{changeset.person.lastName}}
onchange={{action (changeset-set changeset "person.lastName") value="target.value"}}>
value={{this.changeset.person.lastName}}
onchange={{action (changeset-set this.changeset "person.lastName") value="target.value"}}>
`);

assert.equal(find('h1').textContent.trim(), 'Jim Bob', 'precondition');
Expand All @@ -300,7 +300,7 @@ module('Integration | Helper | changeset', function(hooks) {
test('nested key error clears after entering valid input', async function(assert) {
let data = { person: { firstName: 'Jim' } };
let validator = ({ newValue }) => isPresent(newValue) || 'need a first name';
let c = new Changeset(data, validator);
let c = Changeset(data, validator);
this.set('c', c);

await render(hbs`
Expand Down Expand Up @@ -331,7 +331,7 @@ module('Integration | Helper | changeset', function(hooks) {
test('nested object updates when set with async validator', async function(assert) {
let data = { person: { firstName: 'Jim' } };
let validator = () => Promise.resolve(true);
let c = new Changeset(data, validator);
let c = Changeset(data, validator);
this.set('c', c);
await render(hbs`
<h1>{{c.person.firstName}}</h1>
Expand All @@ -350,7 +350,7 @@ module('Integration | Helper | changeset', function(hooks) {
test('deeply nested key error clears after entering valid input', async function(assert) {
let data = { person: { name: { parts: { first: 'Jim' } } } };
let validator = ({ newValue }) => isPresent(newValue) || 'need a first name';
let c = new Changeset(data, validator);
let c = Changeset(data, validator);
this.set('c', c);

await render(hbs`
Expand Down Expand Up @@ -383,20 +383,20 @@ module('Integration | Helper | changeset', function(hooks) {

test('a rollback propagates binding to deeply nested changesets', async function(assert) {
let data = { person: { firstName: 'Jim', lastName: 'Bob' } };
let changeset = new Changeset(data);
let changeset = Changeset(data);
this.set('changeset', changeset);
this.set('reset', () => changeset.rollback());
await render(hbs`
<h1>{{changeset.person.firstName}} {{changeset.person.lastName}}</h1>
<h1>{{this.changeset.person.firstName}} {{this.changeset.person.lastName}}</h1>
<input
id="first-name"
value={{changeset.person.firstName}}
onchange={{action (changeset-set changeset "person.firstName") value="target.value"}}>
value={{this.changeset.person.firstName}}
onchange={{action (changeset-set this.changeset "person.firstName") value="target.value"}}>
<input
id="last-name"
value={{changeset.person.lastName}}
onchange={{action (changeset-set changeset "person.lastName") value="target.value"}}>
<button id="reset-btn" {{action reset}}>Reset</button>
value={{this.changeset.person.lastName}}
onchange={{action (changeset-set this.changeset "person.lastName") value="target.value"}}>
<button id="reset-btn" {{action this.reset}}>Reset</button>
`);

assert.equal(find('h1').textContent.trim(), 'Jim Bob', 'precondition');
Expand All @@ -415,7 +415,7 @@ module('Integration | Helper | changeset', function(hooks) {
let lookupValidator = (validationMap) => {
return ({ key, newValue }) => [validationMap[key](newValue)];
};
let changeset = new Changeset({ even: 4, odd: 4 }, lookupValidator(dummyValidations), dummyValidations);
let changeset = Changeset({ even: 4, odd: 4 }, lookupValidator(dummyValidations), dummyValidations);
this.set('changeset', changeset);
this.set('validateProperty', (changeset, property) => changeset.validate(property));
await render(hbs`
Expand All @@ -424,27 +424,27 @@ module('Integration | Helper | changeset', function(hooks) {
<input
id="even"
type="text"
value={{changeset.even}}
oninput={{action (mut changeset.even) value="target.value"}}
onblur={{action validateProperty changeset "even"}}>
{{#if changeset.error.even}}
<small class="even">{{changeset.error.even.validation}}</small>
value={{this.changeset.even}}
oninput={{action (mut this.changeset.even) value="target.value"}}
onblur={{action this.validateProperty this.changeset "even"}}>
{{#if this.changeset.error.even}}
<small class="even">{{this.changeset.error.even.validation}}</small>
{{/if}}
<code class="even">{{changeset.even}}</code>
<code class="even">{{this.changeset.even}}</code>
</fieldset>

<fieldset class="odd">
<label for="odd">Odd Number</label>
<input
id="odd"
type="text"
value={{changeset.odd}}
oninput={{action (mut changeset.odd) value="target.value"}}
onblur={{action validateProperty changeset "odd"}}>
{{#if changeset.error.odd}}
<small class="odd">{{changeset.error.odd.validation}}</small>
value={{this.changeset.odd}}
oninput={{action (mut this.changeset.odd) value="target.value"}}
onblur={{action this.validateProperty this.changeset "odd"}}>
{{#if this.changeset.error.odd}}
<small class="odd">{{this.changeset.error.odd.validation}}</small>
{{/if}}
<code class="odd">{{changeset.odd}}</code>
<code class="odd">{{this.changeset.odd}}</code>
</fieldset>
`);

Expand Down Expand Up @@ -476,7 +476,7 @@ module('Integration | Helper | changeset', function(hooks) {
let momentInstance = new Moment(d);
this.set('dummyModel', { startDate: momentInstance });
await render(hbs`
{{#with (changeset dummyModel) as |changesetObj|}}
{{#with (changeset this.dummyModel) as |changesetObj|}}
<h1>{{changesetObj.startDate.date}}</h1>
{{/with}}
`);
Expand All @@ -488,7 +488,7 @@ module('Integration | Helper | changeset', function(hooks) {
let d = new Date('2015');
this.set('d', d);
await render(hbs`
{{#with (changeset (hash date=d)) as |changesetObj|}}
{{#with (changeset (hash date=this.d)) as |changesetObj|}}
<h1>{{changesetObj.date}}</h1>
{{/with}}
`);
Expand All @@ -499,7 +499,7 @@ module('Integration | Helper | changeset', function(hooks) {
test('it handles models that are promises', async function(assert) {
this.set('dummyModel', Promise.resolve({ firstName: 'Jim', lastName: 'Bob' }));
await render(hbs`
{{#with (changeset dummyModel) as |changesetObj|}}
{{#with (changeset this.dummyModel) as |changesetObj|}}
<h1>{{changesetObj.firstName}} {{changesetObj.lastName}}</h1>
<input
id="first-name"
Expand All @@ -521,7 +521,7 @@ module('Integration | Helper | changeset', function(hooks) {
this.set('dummyModel', { firstName: 'Jim', lastName: 'Bob' });
this.set('validate', () => false);
await render(hbs`
{{#with (changeset dummyModel (action validate) skipValidate=true) as |changesetObj|}}
{{#with (changeset this.dummyModel (action this.validate) skipValidate=true) as |changesetObj|}}
<h1>{{changesetObj.firstName}} {{changesetObj.lastName}}</h1>
{{input id="first-name" value=changesetObj.firstName}}
{{input id="last-name" value=changesetObj.lastName}}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/helpers/changeset-get-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setupRenderingTest } from 'ember-qunit';
import { TestContext } from 'ember-test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { module, test } from 'qunit';
import Changeset from 'ember-changeset';
import { Changeset } from 'ember-changeset';

interface ModelType {
name: { first: string; last: string };
Expand All @@ -26,7 +26,7 @@ module('Integration | Helper | changeset-get', function(hooks) {
url: 'http://bobloblawslawblog.com'
};

this.set('changeset', new Changeset(model));
this.set('changeset', Changeset(model));
this.set('fieldName', 'name.first');
});

Expand Down