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

Feature 191507 add computed detail batch update test #144

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import DS from 'ember-data';
import { Projection } from 'ember-flexberry-data';
import Ember from 'ember';

var Model = Projection.Model.extend({
// Inversed relationship for ember-flexberry-dummy-suggestion-type.localizedTypes.
Expand All @@ -10,6 +11,39 @@ var Model = Projection.Model.extend({
}),
name: DS.attr('string'),

/**
Non-stored property.

@property detailComputedField
*/
detailComputedField: DS.attr('string'),

/**
Method to set non-stored property.
Please, use code below in model class (outside of this mixin) otherwise it will be replaced during regeneration of models.
Please, implement 'detailComputedFieldCompute' method in model class (outside of this mixin) if you want to compute value of 'detailComputedField' property.

@method _detailComputedFieldCompute
@private
@example
```javascript
_detailComputedFieldChanged: on('init', observer('detailComputedField', function() {
once(this, '_detailComputedFieldCompute');
}))
```
*/

_detailComputedFieldCompute: function() {
let name = this.get('name');
let localizationName = this.get('localization.name');
let result = (localizationName) ? name + ':' + localizationName : name;
this.set('detailComputedField', result);
},

detailComputedFieldChanged: Ember.on('init', Ember.observer('name', function() {
Ember.run.once(this, '_detailComputedFieldCompute');
})),

// This property is for flexberry-lookup component. No inverse relationship here.
localization: DS.belongsTo('ember-flexberry-dummy-localization', {
inverse: null,
Expand Down Expand Up @@ -38,4 +72,14 @@ Model.defineProjection('LocalizedSuggestionTypeE', 'ember-flexberry-dummy-locali
})
});

Model.defineProjection('LocalizedSuggestionTypeEWithComputedField', 'ember-flexberry-dummy-localized-suggestion-type', {
name: Projection.attr('Name'),
detailComputedField: Projection.attr(''),
localization: Projection.belongsTo('ember-flexberry-dummy-localization', '', {
name: Projection.attr('Name')
}),
suggestionType: Projection.belongsTo('ember-flexberry-dummy-suggestion-type', '', {
})
});

export default Model;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Ember from 'ember';
import generateUniqueId from 'ember-flexberry-data/utils/generate-unique-id';

export default function batchUpdatingWithCompDetailMasterTest(store, assert) {
assert.expect(4);
let done = assert.async();

Ember.run(() => {
let records = initTestData(store);
store.adapterFor('application').batchUpdate(store, Ember.A(records)).then((result) => {
assert.equal(result.length, 3);
assert.ok(result[0] === records[0]);
assert.ok(result[1] === records[1]);
assert.ok(result[2] === records[2]);
})
.catch((e) => {
console.log(e, e.message);
throw e;
})
.finally(done);
});
}

function initTestData(store) {
// Parent type
let result = [];

let createdSuggestionType = store.createRecord('ember-flexberry-dummy-suggestion-type', {
id: generateUniqueId(),
name: 'Parent type',
});

let createdLocalization = store.createRecord('ember-flexberry-dummy-localization', {
id: generateUniqueId(),
name: 'en',
});

let createdLocalizationSuggestionType = store.createRecord('ember-flexberry-dummy-localized-suggestion-type', {
id: generateUniqueId(),
name: 'LocName',
localization: createdLocalization,
suggestionType: createdSuggestionType,
});

result.push(createdSuggestionType, createdLocalization, createdLocalizationSuggestionType);

return result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import executeTest from './execute-odata-test';
import batchUpdating from '../base/base-batch-updating-with-computed-detail-with-master-test';

executeTest('batchUpdatingWhithComputedDetailWithMasterTest', (store, assert) => {
batchUpdating(store, assert);
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
"flexberryType": "string",
"notNull": false,
"defaultValue": ""
},
{
"name": "detailComputedField",
"type": "string",
"flexberryType": "string",
"notNull": false,
"defaultValue": ""
}
],
"belongsTo": [
Expand Down Expand Up @@ -103,6 +110,12 @@
"caption": "Name",
"hidden": false,
"index": 0
},
{
"name": "detailComputedField",
"caption": "",
"hidden": false,
"index": 1
}
],
"belongsTo": [
Expand Down Expand Up @@ -141,6 +154,62 @@
}
],
"hasMany": []
},
{
"name": "LocalizedSuggestionTypeEWithComputedField",
"modelName": "ember-flexberry-dummy-localized-suggestion-type",
"attrs": [
{
"name": "name",
"caption": "",
"hidden": false,
"index": 0
},
{
"name": "detailComputedField",
"caption": "",
"hidden": false,
"index": 1
}
],
"belongsTo": [
{
"lookupValue": null,
"lookupValueField": null,
"relationName": "Localization",
"belongsTo": [],
"hidden": false,
"attrs": [
{
"name": "name",
"caption": "",
"hidden": false,
"index": 3
}
],
"index": 2,
"type": "default",
"caption": "",
"name": "localization",
"relatedTo": "ember-flexberry-dummy-localization",
"inverse": null
},
{
"lookupValue": null,
"lookupValueField": null,
"relationName": "SuggestionType",
"belongsTo": [],
"hidden": false,
"attrs": [],
"index": 4,
"type": "default",
"caption": "",
"name": "suggestionType",
"relatedTo": "ember-flexberry-dummy-suggestion-type",
"inverse": null
}
],
"hasMany": []
}
]
}