Files
threshold-ui/addons/api/tests/unit/transforms/string-array-test.js
T
hashicorp-copywrite[bot]andCameron Perera 3d610427d0 [COMPLIANCE] Add Copyright and License Headers (#1617)
* [COMPLIANCE] Add Copyright and License Headers

* chore: 🤖 update Copyright headers to satisfy our lint rules

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
2023-03-01 09:39:41 -06:00

48 lines
1.5 KiB
JavaScript

/**
* 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' },
]);
});
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']);
});
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, []);
});
});