Skip to content

Instantly share code, notes, and snippets.

@jniechcial
Last active August 19, 2016 04:35

Revisions

  1. Jakub Niechciał revised this gist Aug 19, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions model-test.js
    Original 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
  2. Jakub Niechciał created this gist Aug 19, 2016.
    53 changes: 53 additions & 0 deletions model-test.js
    Original 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