/model-test.js Secret
Last active
August 19, 2016 04:35
Revisions
-
Jakub Niechciał revised this gist
Aug 19, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,8 +20,10 @@ export default DS.Model.extend({ }); }), }); // ================= END MODEL FILE // ================= TEST FILE test('it properly computes #properties', function(assert) { const types = ['type1', 'type2']; const values = ['value1', 'value2']; @@ -50,4 +52,5 @@ test('it properly computes #properties', function(assert) { 'property have proper options' ); }); // ================= END TEST FILE -
Jakub Niechciał created this gist
Aug 19, 2016 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ // ================= MODEL FILE export default DS.Model.extend({ // attributes fields: attr(''), values: attr(''), types: attr(''), options: attr(''), // computed properties: computed('fields.[]', 'values.[]', function() { if(!this.get('fields')) { return []; } return this.get('fields').map((item, index) => { return ServiceDetailProperty.create({ name: item, value: this.get('values')[index], type: this.get('types')[index], options: this.get('options')[index] }); }); }), }); // ================= END MODEL FILE // ================= TEST FILE test('it properly computes #properties', function(assert) { const types = ['type1', 'type2']; const values = ['value1', 'value2']; const fields = ['name1', 'name2']; const options = [['1', '2'], ['3', '4']]; const model = this.subject({ types, values, fields, options }); assert.equal(model.get('properties').length, 2, 'there are two properties computed'); assert.equal( model.get('properties.firstObject.name'), 'name1', 'property have proper name' ); assert.equal( model.get('properties.firstObject.value'), 'value1', 'property have proper value' ); assert.equal( model.get('properties.firstObject.type'), 'type1', 'property have proper type' ); assert.deepEqual( model.get('properties.firstObject.options'), ['1', '2'], 'property have proper options' ); }); // ================= END TEST FILE