Files
threshold-ui/addons/api/tests/unit/transforms/string-array-test.js
T

47 lines
1.5 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Transform | string array', function (hooks) {
setupTest(hooks);
test('it deserializes an array of strings to an array of `{value}`', function (assert) {
assert.expect(1);
const transform = this.owner.lookup('transform:string-array');
const deserialized = transform.deserialize(['a', 'bee', 'Hello World']);
assert.deepEqual(deserialized, [
{ value: 'a' },
{ value: 'bee' },
{ value: 'Hello World' },
]);
});
2022-11-21 19:07:46 -05:00
test('it deserializes null to an empty array', function (assert) {
assert.expect(1);
const transform = this.owner.lookup('transform:string-array');
const deserialized = transform.deserialize(null);
assert.deepEqual(deserialized, []);
});
test('it serializes an array of `{value}` to an array of strings', function (assert) {
assert.expect(1);
const transform = this.owner.lookup('transform:string-array');
const serialized = transform.serialize([
{ value: 'a' },
{ value: 'bee' },
{ value: 'Hello World' },
]);
assert.deepEqual(serialized, ['a', 'bee', 'Hello World']);
});
2022-11-21 19:07:46 -05:00
test('it serializes null to an empty array', function (assert) {
assert.expect(1);
const transform = this.owner.lookup('transform:string-array');
const serialized = transform.serialize(null);
assert.deepEqual(serialized, []);
});
});