2018-10-19 15:17:02 +00:00
|
|
|
import updateArrayObject from 'consul-ui/utils/update-array-object';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
|
|
|
module('Unit | Utility | update array object');
|
|
|
|
|
|
|
|
// Replace this with your real tests.
|
2019-05-01 18:09:29 +00:00
|
|
|
test('it updates the correct item in the array', function(assert) {
|
2018-10-19 15:17:02 +00:00
|
|
|
const expected = {
|
|
|
|
data: {
|
|
|
|
id: '2',
|
|
|
|
name: 'expected',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const arr = [
|
|
|
|
{
|
|
|
|
data: {
|
|
|
|
id: '1',
|
|
|
|
name: 'name',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: {
|
|
|
|
id: '2',
|
|
|
|
name: '-',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const actual = updateArrayObject(arr, expected, 'id');
|
|
|
|
assert.ok(actual, expected);
|
2019-05-01 18:09:29 +00:00
|
|
|
assert.equal(arr[1].name, expected.name);
|
2018-10-19 15:17:02 +00:00
|
|
|
});
|