Merge branch '15781-multi-value-property-edit'
[arvados-workbench2.git] / src / lib / resource-properties.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as _ from "./resource-properties";
6 import { omit } from "lodash";
7
8 describe("Resource properties lib", () => {
9
10     let properties: any;
11
12     beforeEach(() => {
13         properties = {
14             animal: 'dog',
15             color: ['brown', 'black'],
16             name: ['Toby']
17         }
18     })
19
20     it("should convert a single string value into a list when adding values", () => {
21         expect(
22             _.addProperty(properties, 'animal', 'cat')
23         ).toEqual({
24             ...properties, animal: ['dog', 'cat']
25         });
26     });
27
28     it("should convert a 2 value list into a string when removing values", () => {
29         expect(
30             _.deleteProperty(properties, 'color', 'brown')
31         ).toEqual({
32             ...properties, color: 'black'
33         });
34     });
35
36     it("shouldn't add duplicated key:value items", () => {
37         expect(
38             _.addProperty(properties, 'animal', 'dog')
39         ).toEqual(properties);
40     });
41
42     it("should remove the key when deleting from a one value list", () => {
43         expect(
44             _.deleteProperty(properties, 'name', 'Toby')
45         ).toEqual(omit(properties, 'name'));
46     });
47
48     it("should return the same when deleting non-existant value", () => {
49         expect(
50             _.deleteProperty(properties, 'animal', 'dolphin')
51         ).toEqual(properties);
52     });
53
54     it("should return the same when deleting non-existant key", () => {
55         expect(
56             _.deleteProperty(properties, 'doesntexist', 'something')
57         ).toEqual(properties);
58     });
59 });