Skip to content

Commit

Permalink
71 test failures to go, implemente PromiseManyArray deprecation from …
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Aug 5, 2022
1 parent e99428a commit 04edfe9
Show file tree
Hide file tree
Showing 19 changed files with 514 additions and 224 deletions.
12 changes: 5 additions & 7 deletions ember-data-types/q/record-data-record-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { JsonApiValidationError } from './record-data-json-api';
@module @ember-data/store
*/

export interface RecordDataRecordWrapper {
export interface RecordDataWrapper {
rollbackAttributes(): string[];
changedAttributes(): ChangedAttributesHash;
hasChangedAttributes(): boolean;
Expand All @@ -16,17 +16,15 @@ export interface RecordDataRecordWrapper {
getAttr(key: string): any;
getHasMany(key: string): CollectionResourceRelationship;

addToHasMany(key: string, recordDatas: RecordDataRecordWrapper[], idx?: number): void;
removeFromHasMany(key: string, recordDatas: RecordDataRecordWrapper[]): void;
setDirtyHasMany(key: string, recordDatas: RecordDataRecordWrapper[]): void;
addToHasMany(key: string, recordDatas: RecordDataWrapper[], idx?: number): void;
removeFromHasMany(key: string, recordDatas: RecordDataWrapper[]): void;
setDirtyHasMany(key: string, recordDatas: RecordDataWrapper[]): void;

getBelongsTo(key: string): SingleResourceRelationship;

setDirtyBelongsTo(name: string, recordData: RecordDataRecordWrapper | null): void;
setDirtyBelongsTo(name: string, recordData: RecordDataWrapper | null): void;

// ----- unspecced
isAttrDirty(key: string): boolean;
removeFromInverseRelationships(): void;
hasAttr(key: string): boolean;

// new
Expand Down
2 changes: 0 additions & 2 deletions ember-data-types/q/record-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export interface RecordData {
didCommit(data: JsonApiResource | null): void;

// ----- unspecced
isAttrDirty(key: string): boolean;
removeFromInverseRelationships(): void;
hasAttr(key: string): boolean;

isRecordInUse(): boolean;
Expand Down
276 changes: 264 additions & 12 deletions packages/-ember-data/tests/acceptance/relationships/has-many-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import { LEGACY_SUPPORT } from '@ember-data/model/-private';
import JSONAPISerializer from '@ember-data/serializer/json-api';
import Store from '@ember-data/store';
import { deprecatedTest } from '@ember-data/unpublished-test-infra/test-support/deprecated-test';

class Person extends Model {
@attr()
Expand Down Expand Up @@ -751,14 +752,212 @@ module('autotracking has-many', function (hooks) {
assert.deepEqual(names, ['RGB', 'RGB'], 'rendered 2 children');
});

deprecatedTest(
'We can re-render hasMany w/PromiseManyArray.sortBy',
{ id: 'ember-data:deprecate-promise-many-array-behaviors', until: '5.0', count: 6 },
async function (assert) {
class ChildrenList extends Component {
@service store;

get sortedChildren() {
return this.args.person.children.sortBy('name');
}

@action
createChild() {
const parent = this.args.person;
const name = 'RGB';
this.store.createRecord('person', { name, parent });
}
}

let layout = hbs`
<button id="createChild" {{on "click" this.createChild}}>Add child</button>
<h2>{{this.sortedChildren.length}}</h2>
<ul>
{{#each this.sortedChildren as |child|}}
<li>{{child.name}}</li>
{{/each}}
</ul>
`;
this.owner.register('component:children-list', ChildrenList);
this.owner.register('template:components/children-list', layout);

store.createRecord('person', { id: '1', name: 'Doodad' });
this.person = store.peekRecord('person', '1');

await render(hbs`<ChildrenList @person={{this.person}} />`);

let names = findAll('li').map((e) => e.textContent);

assert.deepEqual(names, [], 'rendered no children');

await click('#createChild');

names = findAll('li').map((e) => e.textContent);
assert.deepEqual(names, ['RGB'], 'rendered 1 child');

await click('#createChild');

names = findAll('li').map((e) => e.textContent);
assert.deepEqual(names, ['RGB', 'RGB'], 'rendered 2 children');
}
);

deprecatedTest(
'We can re-render hasMany with sort computed macro on PromiseManyArray',
{ id: 'ember-data:deprecate-promise-many-array-behaviors', until: '5.0', count: 6 },
async function (assert) {
class ChildrenList extends Component {
@service store;

sortProperties = ['name'];
@sort('args.person.children', 'sortProperties') sortedChildren;

@action
createChild() {
const parent = this.args.person;
const name = 'RGB';
this.store.createRecord('person', { name, parent });
}
}

let layout = hbs`
<button id="createChild" {{on "click" this.createChild}}>Add child</button>
<h2>{{this.sortedChildren.length}}</h2>
<ul>
{{#each this.sortedChildren as |child|}}
<li>{{child.name}}</li>
{{/each}}
</ul>
`;
this.owner.register('component:children-list', ChildrenList);
this.owner.register('template:components/children-list', layout);

store.createRecord('person', { id: '1', name: 'Doodad' });
this.person = store.peekRecord('person', '1');

await render(hbs`<ChildrenList @person={{this.person}} />`);

let names = findAll('li').map((e) => e.textContent);

assert.deepEqual(names, [], 'rendered no children');

await click('#createChild');

names = findAll('li').map((e) => e.textContent);
assert.deepEqual(names, ['RGB'], 'rendered 1 child');

await click('#createChild');

names = findAll('li').map((e) => e.textContent);
assert.deepEqual(names, ['RGB', 'RGB'], 'rendered 2 children');
}
);

deprecatedTest(
'We can re-render hasMany with PromiseManyArray.objectAt',
{ id: 'ember-data:deprecate-promise-many-array-behaviors', until: '5.0', count: 6 },
async function (assert) {
class ChildrenList extends Component {
@service store;
get firstChild() {
return this.args.person.children.objectAt(0);
}
@action
createChild() {
const parent = this.args.person;
const name = 'RGB';
this.store.createRecord('person', { name, parent });
}
}
let layout = hbs`
<button id="createChild" {{on "click" this.createChild}}>Add child</button>
<h2>{{this.firstChild.name}}</h2>
`;
this.owner.register('component:children-list', ChildrenList);
this.owner.register('template:components/children-list', layout);
store.createRecord('person', { id: '1', name: 'Doodad' });
this.person = store.peekRecord('person', '1');
await render(hbs`<ChildrenList @person={{this.person}} />`);
assert.dom('h2').hasText('', 'rendered no children');

await click('#createChild');

assert.dom('h2').hasText('RGB', 'renders first child');

await click('#createChild');

assert.dom('h2').hasText('RGB', 'renders first child');
}
);

deprecatedTest(
'We can re-render hasMany with PromiseManyArray.map',
{ id: 'ember-data:deprecate-promise-many-array-behaviors', until: '5.0', count: 6 },
async function (assert) {
class ChildrenList extends Component {
@service store;
get children() {
return this.args.person.children.map((child) => child);
}
@action
createChild() {
const parent = this.args.person;
const name = 'RGB';
this.store.createRecord('person', { name, parent });
}
}
let layout = hbs`
<button id="createChild" {{on "click" this.createChild}}>Add child</button>
<h2>{{this.children.length}}</h2>
<ul>
{{#each this.children as |child|}}
<li>{{child.name}}</li>
{{/each}}
</ul>
`;
this.owner.register('component:children-list', ChildrenList);
this.owner.register('template:components/children-list', layout);
store.createRecord('person', { id: '1', name: 'Doodad' });
this.person = store.peekRecord('person', '1');
await render(hbs`<ChildrenList @person={{this.person}} />`);
let names = findAll('li').map((e) => e.textContent);
assert.deepEqual(names, [], 'rendered no children');
await click('#createChild');
names = findAll('li').map((e) => e.textContent);
assert.deepEqual(names, ['RGB'], 'rendered 1 child');
await click('#createChild');
names = findAll('li').map((e) => e.textContent);
assert.deepEqual(names, ['RGB', 'RGB'], 'rendered 2 children');
}
);
test('We can re-render hasMany', async function (assert) {
class ChildrenList extends Component {
@service store;
get sortedChildren() {
return this.args.person.children.sortBy('name');
}

@action
createChild() {
const parent = this.args.person;
Expand All @@ -770,9 +969,9 @@ module('autotracking has-many', function (hooks) {
let layout = hbs`
<button id="createChild" {{on "click" this.createChild}}>Add child</button>
<h2>{{this.sortedChildren.length}}</h2>
<h2>{{@person.children.length}}</h2>
<ul>
{{#each this.sortedChildren as |child|}}
{{#each @person.children as |child|}}
<li>{{child.name}}</li>
{{/each}}
</ul>
Expand Down Expand Up @@ -805,7 +1004,7 @@ module('autotracking has-many', function (hooks) {
@service store;
sortProperties = ['name'];
@sort('args.person.children', 'sortProperties') sortedChildren;
@sort('args.children', 'sortProperties') sortedChildren;

@action
createChild() {
Expand All @@ -830,8 +1029,9 @@ module('autotracking has-many', function (hooks) {

store.createRecord('person', { id: '1', name: 'Doodad' });
this.person = store.peekRecord('person', '1');
this.children = await this.person.children;

await render(hbs`<ChildrenList @person={{this.person}} />`);
await render(hbs`<ChildrenList @children={{this.children}} @person={{this.person}} />`);

let names = findAll('li').map((e) => e.textContent);

Expand All @@ -853,7 +1053,7 @@ module('autotracking has-many', function (hooks) {
@service store;

get firstChild() {
return this.args.person.children.objectAt(0);
return this.args.children.objectAt(0);
}

@action
Expand All @@ -874,8 +1074,9 @@ module('autotracking has-many', function (hooks) {

store.createRecord('person', { id: '1', name: 'Doodad' });
this.person = store.peekRecord('person', '1');
this.children = await this.person.children;

await render(hbs`<ChildrenList @person={{this.person}} />`);
await render(hbs`<ChildrenList @children={{this.children}} @person={{this.person}} />`);

assert.dom('h2').hasText('', 'rendered no children');

Expand All @@ -893,7 +1094,7 @@ module('autotracking has-many', function (hooks) {
@service store;

get children() {
return this.args.person.children.map((child) => child);
return this.args.children.map((child) => child);
}

@action
Expand All @@ -919,8 +1120,59 @@ module('autotracking has-many', function (hooks) {

store.createRecord('person', { id: '1', name: 'Doodad' });
this.person = store.peekRecord('person', '1');
this.children = await this.person.children;

await render(hbs`<ChildrenList @person={{this.person}} />`);
await render(hbs`<ChildrenList @children={{this.children}} @person={{this.person}} />`);

let names = findAll('li').map((e) => e.textContent);

assert.deepEqual(names, [], 'rendered no children');

await click('#createChild');

names = findAll('li').map((e) => e.textContent);
assert.deepEqual(names, ['RGB'], 'rendered 1 child');

await click('#createChild');

names = findAll('li').map((e) => e.textContent);
assert.deepEqual(names, ['RGB', 'RGB'], 'rendered 2 children');
});

test('We can re-render hasMany with toArray', async function (assert) {
class ChildrenList extends Component {
@service store;

get children() {
return this.args.children.toArray();
}

@action
createChild() {
const parent = this.args.person;
const name = 'RGB';
this.store.createRecord('person', { name, parent });
}
}

let layout = hbs`
<button id="createChild" {{on "click" this.createChild}}>Add child</button>
<h2>{{this.children.length}}</h2>
<ul>
{{#each this.children as |child|}}
<li>{{child.name}}</li>
{{/each}}
</ul>
`;
this.owner.register('component:children-list', ChildrenList);
this.owner.register('template:components/children-list', layout);

store.createRecord('person', { id: '1', name: 'Doodad' });
this.person = store.peekRecord('person', '1');
this.children = await this.person.children;

await render(hbs`<ChildrenList @children={{this.children}} @person={{this.person}} />`);

let names = findAll('li').map((e) => e.textContent);

Expand Down
Loading

0 comments on commit 04edfe9

Please sign in to comment.