@truedat/df 6.6.5 → 6.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/package.json +5 -5
  2. package/src/components/DynamicFieldValue.js +7 -1
  3. package/src/components/DynamicForm.js +4 -1
  4. package/src/components/DynamicFormViewer.js +0 -1
  5. package/src/components/FieldGroupDetail.js +3 -3
  6. package/src/components/FieldGroupSegment.js +6 -2
  7. package/src/components/OriginLabel.js +34 -0
  8. package/src/components/__tests__/DynamicFieldValue.spec.js +2 -2
  9. package/src/components/__tests__/DynamicForm.spec.js +4 -1
  10. package/src/components/__tests__/FieldGroupDetail.spec.js +12 -12
  11. package/src/components/__tests__/SelectableDynamicForm.spec.js +1 -1
  12. package/src/components/__tests__/__snapshots__/EditableDynamicFieldValue.spec.js.snap +2 -2
  13. package/src/components/widgets/DynamicField.js +71 -62
  14. package/src/components/widgets/__tests__/DynamicField.spec.js +34 -14
  15. package/src/components/widgets/__tests__/HierarchyDropdown.spec.js +48 -0
  16. package/src/components/widgets/__tests__/HierarchyPreview.spec.js +1 -2
  17. package/src/components/widgets/__tests__/__snapshots__/HierarchyDropdown.spec.js.snap +6 -0
  18. package/src/templates/components/templateForm/ActiveGroupForm.js +4 -1
  19. package/src/templates/components/templateForm/DefaultValue.js +13 -10
  20. package/src/templates/components/templateForm/FieldForm.js +8 -2
  21. package/src/templates/components/templateForm/__tests__/DefaultValue.spec.js +2 -2
  22. package/src/templates/components/templateForm/__tests__/FieldForm.spec.js +2 -2
  23. package/src/templates/utils/__tests__/applyDefaults.spec.js +101 -51
  24. package/src/templates/utils/__tests__/applyTemplate.spec.js +81 -37
  25. package/src/templates/utils/__tests__/filterDepends.spec.js +9 -6
  26. package/src/templates/utils/__tests__/filterDomains.spec.js +76 -31
  27. package/src/templates/utils/__tests__/filterSwitches.spec.js +35 -6
  28. package/src/templates/utils/__tests__/filterValues.spec.js +19 -7
  29. package/src/templates/utils/__tests__/parseFieldOptions.spec.js +18 -12
  30. package/src/templates/utils/__tests__/parseGroups.spec.js +57 -18
  31. package/src/templates/utils/applyDefaults.js +62 -21
  32. package/src/templates/utils/filterDepends.js +4 -2
  33. package/src/templates/utils/filterDomains.js +1 -1
  34. package/src/templates/utils/filterSwitches.js +6 -6
  35. package/src/templates/utils/filterValues.js +7 -4
  36. package/src/templates/utils/parseFieldOptions.js +1 -1
  37. package/src/templates/utils/parseGroups.js +2 -2
@@ -1,3 +1,9 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
+ exports[`<HierarchyDropdown /> matches the latest snapshot (min-depth 0) 1`] = `<div />`;
4
+
5
+ exports[`<HierarchyDropdown /> matches the latest snapshot (min-depth 2) 1`] = `<div />`;
6
+
7
+ exports[`<HierarchyDropdown /> matches the latest snapshot (missing min-depth) 1`] = `<div />`;
8
+
3
9
  exports[`<HierarchyDropdown /> matches the latest snapshot 1`] = `<div />`;
@@ -58,7 +58,10 @@ export const ActiveGroupForm = ({
58
58
  widget: "string",
59
59
  cardinality: "?",
60
60
  type: "string",
61
- default: "",
61
+ default: {
62
+ value: "",
63
+ origin: "default",
64
+ },
62
65
  values: null,
63
66
  };
64
67
  const name = `${groupNamePrefix}.fields`;
@@ -40,14 +40,14 @@ export const DefaultValue = ({
40
40
  const onDefaultValueChange = (e, { value }) => {
41
41
  onChange(null, {
42
42
  name: defaultField,
43
- value: formatDefaultValue(type, value),
43
+ value: { value: formatDefaultValue(type, value), origin: "default" },
44
44
  });
45
45
  };
46
46
 
47
47
  const onMultipleDefaultValueChange = (e, { value }) => {
48
48
  onChange(null, {
49
49
  name: defaultField,
50
- value: value,
50
+ value: { value, origin: "default" },
51
51
  });
52
52
  };
53
53
 
@@ -66,7 +66,7 @@ export const DefaultValue = ({
66
66
  <>
67
67
  {!type && fieldType === "date" && (
68
68
  <DateField
69
- field={{ ...field, value: _.get("default")(field) }}
69
+ field={{ ...field, value: _.get("default.value")(field) }}
70
70
  onChange={(e, { value }) =>
71
71
  onDefaultValueChange(e, { name: name, value: value })
72
72
  }
@@ -74,7 +74,7 @@ export const DefaultValue = ({
74
74
  )}
75
75
  {!type && fieldType === "datetime" && (
76
76
  <DateTimeField
77
- field={{ ...field, value: _.get("default")(field) }}
77
+ field={{ ...field, value: _.get("default.value")(field) }}
78
78
  onChange={(e, { value }) =>
79
79
  onDefaultValueChange(e, { name: name, value: value })
80
80
  }
@@ -82,7 +82,7 @@ export const DefaultValue = ({
82
82
  )}
83
83
  {!type && (fieldType === "integer" || fieldType === "float") && (
84
84
  <NumberField
85
- field={{ ...field, value: _.get("default")(field) }}
85
+ field={{ ...field, value: _.get("default.value")(field) }}
86
86
  onChange={onDefaultValueChange}
87
87
  />
88
88
  )}
@@ -101,7 +101,7 @@ export const DefaultValue = ({
101
101
  label={formatMessage({
102
102
  id: "template.field.values.default_value",
103
103
  })}
104
- value={_.get("default")(field)}
104
+ value={_.get("default.value")(field)}
105
105
  onChange={onDefaultValueChange}
106
106
  />
107
107
  )}
@@ -111,7 +111,7 @@ export const DefaultValue = ({
111
111
  selection
112
112
  label={formatMessage({ id: "template.field.values.default_value" })}
113
113
  onChange={onDefaultValueChange}
114
- value={defaultValueFormat(_.get("default")(field))}
114
+ value={defaultValueFormat(_.get("default.value")(field))}
115
115
  options={_.map((v) => ({
116
116
  key: v,
117
117
  value: v,
@@ -127,7 +127,7 @@ export const DefaultValue = ({
127
127
  multiple
128
128
  label={formatMessage({ id: "template.field.values.default_value" })}
129
129
  onChange={onMultipleDefaultValueChange}
130
- value={multipleDefaultValueFormat(_.get("default")(field))}
130
+ value={multipleDefaultValueFormat(_.get("default.value")(field))}
131
131
  options={_.map((v) => ({
132
132
  key: v,
133
133
  value: v,
@@ -144,12 +144,15 @@ export const DefaultValue = ({
144
144
  allowAdditions
145
145
  label={formatMessage({ id: "template.field.values.default_value" })}
146
146
  onChange={onMultipleDefaultValueChange}
147
- value={multipleDefaultValueFormat(_.get("default")(field))}
147
+ value={multipleDefaultValueFormat(_.get("default.value")(field))}
148
148
  options={_.map((v) => ({
149
149
  key: v,
150
150
  value: v,
151
151
  text: v,
152
- }))(["", ...multipleDefaultValueFormat(_.get("default")(field))])}
152
+ }))([
153
+ "",
154
+ ...multipleDefaultValueFormat(_.get("default.value")(field)),
155
+ ])}
153
156
  />
154
157
  )}
155
158
  </>
@@ -101,7 +101,10 @@ export const FieldForm = ({
101
101
  valueName,
102
102
  defaultType(getValues(value, updatedType)) || "null"
103
103
  );
104
- onChange(e, { name: defaultField, value: "" });
104
+ onChange(e, {
105
+ name: defaultField,
106
+ value: { value: "", origin: "default" },
107
+ });
105
108
  onChange(e, { name: subscribableField, value: false });
106
109
  onChange(e, data);
107
110
  };
@@ -109,7 +112,10 @@ export const FieldForm = ({
109
112
  const handleTypeChange = (e, data) => {
110
113
  const { value } = data;
111
114
  changeValue(valueName, defaultType(getValues(widget, value)) || "null");
112
- onChange(e, { name: defaultField, value: "" });
115
+ onChange(e, {
116
+ name: defaultField,
117
+ value: { value: "", origin: "default" },
118
+ });
113
119
  onChange(e, { name: subscribableField, value: false });
114
120
  onChange(e, data);
115
121
  };
@@ -252,7 +252,7 @@ describe("<DefaultValue />", () => {
252
252
  input.simulate("change", null, { value: 3 });
253
253
  expect(onChange).toBeCalledWith(null, {
254
254
  name: defaultField,
255
- value: [3],
255
+ value: { value: [3], origin: "default" },
256
256
  });
257
257
  });
258
258
 
@@ -264,7 +264,7 @@ describe("<DefaultValue />", () => {
264
264
  input.simulate("change", null, { value: 3 });
265
265
  expect(onChange).toBeCalledWith(null, {
266
266
  name: defaultField,
267
- value: 3,
267
+ value: { value: 3, origin: "default" },
268
268
  });
269
269
  });
270
270
  });
@@ -136,7 +136,7 @@ describe("<FieldForm />", () => {
136
136
  });
137
137
  expect(onChange).toBeCalledWith(null, {
138
138
  name: "Group.fields[0].default",
139
- value: "",
139
+ value: { value: "", origin: "default" },
140
140
  });
141
141
  expect(onChange).toBeCalledWith(null, {
142
142
  name: "Group.fields[0].subscribable",
@@ -179,7 +179,7 @@ describe("<FieldForm />", () => {
179
179
  });
180
180
  expect(onChange).toBeCalledWith(null, {
181
181
  name: "Group.fields[0].default",
182
- value: "",
182
+ value: { value: "", origin: "default" },
183
183
  });
184
184
  expect(onChange).toBeCalledWith(null, {
185
185
  name: "Group.fields[0].subscribable",
@@ -1,122 +1,172 @@
1
1
  import { applyDefaults } from "..";
2
2
 
3
3
  describe("utils: applyDefaults", () => {
4
- const xyzzy = ["xyzzy", {}, null];
4
+ const xyzzy = { value: ["xyzzy", {}, null], origin: "default" };
5
5
 
6
6
  const templateContent = [
7
- { name: "foo", default: "bar" },
8
- { name: "bar", default: "1" },
7
+ { name: "foo", default: { value: "bar", origin: "default" } },
8
+ { name: "bar", default: { value: "1", origin: "default" } },
9
9
  {
10
10
  name: "qux",
11
- default: "quux",
11
+ default: { value: "quux", origin: "default" },
12
12
  depends: {
13
13
  on: "foo",
14
14
  to_be: ["bar"],
15
15
  },
16
16
  },
17
- { name: "xyz", default: { 1: ["a"] }, values: { switch: { on: "bar" } } },
17
+ {
18
+ name: "xyz",
19
+ values: { switch: { on: "bar", values: { 1: ["a"] } } },
20
+ default: {
21
+ value: { 1: ["a"] },
22
+ origin: "default",
23
+ },
24
+ },
18
25
  {
19
26
  name: "xxyy",
20
- default: { 1: ["a"], 2: ["c"] },
27
+ default: { value: { 1: ["a"], 2: ["c"] }, origin: "default" },
21
28
  values: { domain: { 1: ["a", "b"], 2: ["c", "d"] } },
22
29
  },
23
30
  ];
24
31
 
25
32
  it("should apply simple defaults if key is not present in content", () => {
26
- const content = { xyzzy, bar: "2" };
33
+ const content = { xyzzy, bar: { value: "2", origin: "user" } };
27
34
  const result = applyDefaults(templateContent)(content);
28
- expect(result).toEqual({ foo: "bar", qux: "quux", xyzzy, bar: "2" });
35
+ expect(result).toEqual({
36
+ foo: { value: "bar", origin: "default" },
37
+ qux: { value: "quux", origin: "default" },
38
+ xyzzy,
39
+ bar: { value: "2", origin: "user" },
40
+ });
29
41
  });
30
42
 
31
43
  it("should not apply simple defaults if key is present in content", () => {
32
- const content = { foo: "baz", xyzzy, bar: "2" };
44
+ const content = {
45
+ foo: { value: "baz", origin: "user" },
46
+ xyzzy,
47
+ bar: { value: "2", origin: "user" },
48
+ };
33
49
  const result = applyDefaults(templateContent)(content);
34
- expect(result).toEqual({ foo: "baz", bar: "2", xyzzy });
50
+ expect(result).toEqual({
51
+ foo: { value: "baz", origin: "user" },
52
+ bar: { value: "2", origin: "user" },
53
+ xyzzy,
54
+ });
35
55
  });
36
56
 
37
57
  it("should apply conditional defaults key is not present in content", () => {
38
- const content = { foo: "bar", xyzzy, bar: "2" };
58
+ const content = {
59
+ foo: { value: "bar", origin: "user" },
60
+ xyzzy,
61
+ bar: { value: "2", origin: "user" },
62
+ };
39
63
  const result = applyDefaults(templateContent)(content);
40
- expect(result).toEqual({ foo: "bar", bar: "2", qux: "quux", xyzzy });
64
+ expect(result).toEqual({
65
+ foo: { value: "bar", origin: "user" },
66
+ bar: { value: "2", origin: "user" },
67
+ qux: { value: "quux", origin: "default" },
68
+ xyzzy,
69
+ });
41
70
  });
42
71
 
43
72
  it("should not apply conditional defaults if key is present in content", () => {
44
- const content = { foo: "bar", qux: "spqr", xyzzy, bar: "2" };
73
+ const content = {
74
+ foo: { value: "bar", origin: "user" },
75
+ qux: { value: "spqr", origin: "user" },
76
+ xyzzy,
77
+ bar: { value: "2", origin: "user" },
78
+ };
45
79
  const result = applyDefaults(templateContent)(content);
46
- expect(result).toEqual({ foo: "bar", qux: "spqr", xyzzy, bar: "2" });
80
+ expect(result).toEqual({
81
+ foo: { value: "bar", origin: "user" },
82
+ qux: { value: "spqr", origin: "user" },
83
+ xyzzy,
84
+ bar: { value: "2", origin: "user" },
85
+ });
47
86
  });
48
87
 
49
88
  it("should apply conditional switch defaults if key is not present in content", () => {
50
89
  expect(
51
- applyDefaults(templateContent)({ foo: "bar", qux: "spqr", xyzzy })
90
+ applyDefaults(templateContent)({
91
+ foo: { value: "bar", origin: "user" },
92
+ qux: { value: "spqr", origin: "user" },
93
+ xyzzy,
94
+ })
52
95
  ).toEqual({
53
- foo: "bar",
54
- qux: "spqr",
96
+ foo: { value: "bar", origin: "user" },
97
+ qux: { value: "spqr", origin: "user" },
55
98
  xyzzy,
56
- bar: "1",
57
- xyz: ["a"],
99
+ bar: { value: "1", origin: "default" },
100
+ xyz: { value: ["a"], origin: "default" },
58
101
  });
59
102
  expect(
60
103
  applyDefaults(templateContent)({
61
- foo: "bar",
62
- qux: "spqr",
104
+ foo: { value: "bar", origin: "user" },
105
+ qux: { value: "spqr", origin: "user" },
63
106
  xyzzy,
64
- bar: "1",
107
+ bar: { value: "1", origin: "user" },
65
108
  })
66
109
  ).toEqual({
67
- foo: "bar",
68
- qux: "spqr",
110
+ foo: { value: "bar", origin: "user" },
111
+ qux: { value: "spqr", origin: "user" },
69
112
  xyzzy,
70
- bar: "1",
71
- xyz: ["a"],
113
+ bar: { value: "1", origin: "user" },
114
+ xyz: { value: ["a"], origin: "default" },
72
115
  });
73
116
  });
74
117
 
75
118
  it("should apply domain defaults", () => {
76
- const defaultContent = { foo: "bar", qux: "spqr", xyzzy };
119
+ const defaultContent = {
120
+ foo: { value: "bar", origin: "user" },
121
+ qux: { value: "spqr", origin: "user" },
122
+ xyzzy,
123
+ };
77
124
  expect(applyDefaults(templateContent)(defaultContent, 1)).toEqual({
78
- foo: "bar",
79
- qux: "spqr",
125
+ foo: { value: "bar", origin: "user" },
126
+ qux: { value: "spqr", origin: "user" },
80
127
  xyzzy,
81
- bar: "1",
82
- xyz: ["a"],
83
- xxyy: ["a"],
128
+ bar: { value: "1", origin: "default" },
129
+ xyz: { value: ["a"], origin: "default" },
130
+ xxyy: { value: ["a"], origin: "default" },
84
131
  });
85
132
 
86
133
  expect(applyDefaults(templateContent)(defaultContent, 2)).toEqual({
87
- foo: "bar",
88
- qux: "spqr",
134
+ foo: { value: "bar", origin: "user" },
135
+ qux: { value: "spqr", origin: "user" },
89
136
  xyzzy,
90
- bar: "1",
91
- xyz: ["a"],
92
- xxyy: ["c"],
137
+ bar: { value: "1", origin: "default" },
138
+ xyz: { value: ["a"], origin: "default" },
139
+ xxyy: { value: ["c"], origin: "default" },
93
140
  });
94
141
 
95
142
  expect(applyDefaults(templateContent)(defaultContent, 3)).toEqual({
96
- foo: "bar",
97
- qux: "spqr",
143
+ foo: { value: "bar", origin: "user" },
144
+ qux: { value: "spqr", origin: "user" },
98
145
  xyzzy,
99
- bar: "1",
100
- xyz: ["a"],
146
+ bar: { value: "1", origin: "default" },
147
+ xyz: { value: ["a"], origin: "default" },
101
148
  });
102
149
 
103
150
  expect(
104
- applyDefaults(templateContent)({ ...defaultContent, xxyy: ["b"] }, 2)
151
+ applyDefaults(templateContent)(
152
+ { ...defaultContent, xxyy: { value: ["b"], origin: "user" } },
153
+ 2
154
+ )
105
155
  ).toEqual({
106
- foo: "bar",
107
- qux: "spqr",
156
+ foo: { value: "bar", origin: "user" },
157
+ qux: { value: "spqr", origin: "user" },
108
158
  xyzzy,
109
- bar: "1",
110
- xyz: ["a"],
111
- xxyy: ["b"],
159
+ bar: { value: "1", origin: "default" },
160
+ xyz: { value: ["a"], origin: "default" },
161
+ xxyy: { value: ["b"], origin: "user" },
112
162
  });
113
163
 
114
164
  expect(applyDefaults(templateContent)(defaultContent, null)).toEqual({
115
- foo: "bar",
116
- qux: "spqr",
165
+ foo: { value: "bar", origin: "user" },
166
+ qux: { value: "spqr", origin: "user" },
117
167
  xyzzy,
118
- bar: "1",
119
- xyz: ["a"],
168
+ bar: { value: "1", origin: "default" },
169
+ xyz: { value: ["a"], origin: "default" },
120
170
  });
121
171
  });
122
172
  });
@@ -18,7 +18,7 @@ const template = {
18
18
  {
19
19
  name: "wibble",
20
20
  depends: { on: "role", to_be: ["u1"] },
21
- default: "wobble",
21
+ default: { value: "wobble", origin: "default" },
22
22
  },
23
23
  {
24
24
  name: "switch",
@@ -34,7 +34,7 @@ const template = {
34
34
  },
35
35
  {
36
36
  name: "domain",
37
- default: { 2: ["d"] },
37
+ default: { value: { 2: ["d"] }, origin: "default" },
38
38
  values: {
39
39
  domain: {
40
40
  1: ["a", "b"],
@@ -50,20 +50,28 @@ const template = {
50
50
  describe("utils: applyTemplate", () => {
51
51
  describe("switches", () => {
52
52
  it("should filter properties with invalid switch values", () => {
53
- const o = { fixed: "foo", switch: "bar2", xyzzy };
53
+ const o = {
54
+ fixed: { value: "foo", origin: "user" },
55
+ switch: { value: "bar2", origin: "user" },
56
+ xyzzy,
57
+ };
54
58
  const result = applyTemplate(template)(o);
55
59
  expect(result).toEqual({
56
- fixed: "foo",
60
+ fixed: { value: "foo", origin: "user" },
57
61
  xyzzy,
58
62
  });
59
63
  });
60
64
 
61
65
  it("should not filter properties with valid switch values", () => {
62
- const o = { fixed: "bar", switch: "bar2", xyzzy };
66
+ const o = {
67
+ fixed: { value: "bar", origin: "user" },
68
+ switch: { value: "bar2", origin: "user" },
69
+ xyzzy,
70
+ };
63
71
  const result = applyTemplate(template)(o);
64
72
  expect(result).toEqual({
65
- fixed: "bar",
66
- switch: "bar2",
73
+ fixed: { value: "bar", origin: "user" },
74
+ switch: { value: "bar2", origin: "user" },
67
75
  xyzzy,
68
76
  });
69
77
  });
@@ -71,100 +79,136 @@ describe("utils: applyTemplate", () => {
71
79
 
72
80
  describe("domains", () => {
73
81
  it("should filter properties with invalid domain values", () => {
74
- const o = { fixed: "foo", switch: "foo1", xyzzy, domain: "foo" };
82
+ const o = {
83
+ fixed: { value: "foo", origin: "user" },
84
+ switch: { value: "foo1", origin: "user" },
85
+ xyzzy,
86
+ domain: { value: "foo", origin: "user" },
87
+ };
75
88
  const result = applyTemplate(template)(o, 1);
76
89
  expect(result).toEqual({
77
- fixed: "foo",
78
- switch: "foo1",
90
+ fixed: { value: "foo", origin: "user" },
91
+ switch: { value: "foo1", origin: "user" },
79
92
  xyzzy,
80
93
  });
81
94
  });
82
95
 
83
96
  it("should include domain when single value is valid", () => {
84
- const o = { fixed: "foo", switch: "foo1", xyzzy, domain: "a" };
97
+ const o = {
98
+ fixed: { value: "foo", origin: "user" },
99
+ switch: { value: "foo1", origin: "user" },
100
+ xyzzy,
101
+ domain: { value: "a", origin: "user" },
102
+ };
85
103
  const result = applyTemplate(template)(o, 1);
86
104
  expect(result).toEqual({
87
- fixed: "foo",
88
- switch: "foo1",
105
+ fixed: { value: "foo", origin: "user" },
106
+ switch: { value: "foo1", origin: "user" },
89
107
  xyzzy,
90
- domain: "a",
108
+ domain: { value: "a", origin: "user" },
91
109
  });
92
110
  });
93
111
 
94
112
  it("should include domain when multiple value is valid", () => {
95
- const o = { fixed: "foo", switch: "foo1", xyzzy, domain: ["c", "d"] };
113
+ const o = {
114
+ fixed: { value: "foo", origin: "user" },
115
+ switch: { value: "foo1", origin: "user" },
116
+ xyzzy,
117
+ domain: { value: ["c", "d"], origin: "user" },
118
+ };
96
119
  const result = applyTemplate(template)(o, 2);
97
120
  expect(result).toEqual({
98
- fixed: "foo",
99
- switch: "foo1",
121
+ fixed: { value: "foo", origin: "user" },
122
+ switch: { value: "foo1", origin: "user" },
100
123
  xyzzy,
101
- domain: ["c", "d"],
124
+ domain: { value: ["c", "d"], origin: "user" },
102
125
  });
103
126
  });
104
127
 
105
128
  it("should apply domain default", () => {
106
- const o = { fixed: "foo", switch: "foo1", xyzzy };
129
+ const o = {
130
+ fixed: { value: "foo", origin: "user" },
131
+ switch: { value: "foo1", origin: "user" },
132
+ xyzzy,
133
+ };
107
134
  const result = applyTemplate(template)(o, 2);
108
135
  expect(result).toEqual({
109
- fixed: "foo",
110
- switch: "foo1",
136
+ fixed: { value: "foo", origin: "user" },
137
+ switch: { value: "foo1", origin: "user" },
111
138
  xyzzy,
112
- domain: ["d"],
139
+ domain: { value: ["d"], origin: "default" },
113
140
  });
114
141
  });
115
142
  });
116
143
 
117
144
  describe("field filters", () => {
118
145
  it("should filter unlisted properties", () => {
119
- const o = { fixed: "foo", bar: "baz", xyzzy };
146
+ const o = {
147
+ fixed: { value: "foo", origin: "user" },
148
+ bar: { value: "baz", origin: "user" },
149
+ xyzzy,
150
+ };
120
151
  const result = applyTemplate(template)(o);
121
- expect(result).toEqual({ fixed: "foo", xyzzy });
152
+ expect(result).toEqual({
153
+ fixed: { value: "foo", origin: "user" },
154
+ xyzzy,
155
+ });
122
156
  });
123
157
  });
124
158
 
125
159
  describe("value filters", () => {
126
160
  it("should nullify unlisted values", () => {
127
- const o = { fixed: "foo2", xyzzy };
161
+ const o = { fixed: { value: "foo2", origin: "user" }, xyzzy };
128
162
  const result = applyTemplate(template)(o);
129
- expect(result).toEqual({ fixed: null, xyzzy });
163
+ expect(result).toEqual({ fixed: { value: null, origin: "user" }, xyzzy });
130
164
  });
131
165
  });
132
166
 
133
167
  describe("conditional defaults", () => {
134
168
  it("should be ignored if a value exists", () => {
135
- const o = { role: "u1", wibble: "woo", xyzzy };
169
+ const o = {
170
+ role: { value: "u1", origin: "user" },
171
+ wibble: { value: "woo", origin: "user" },
172
+ xyzzy,
173
+ };
136
174
  const result = applyTemplate(template)(o);
137
175
  expect(result).toEqual({
138
- role: "u1",
139
- wibble: "woo",
176
+ role: { value: "u1", origin: "user" },
177
+ wibble: { value: "woo", origin: "user" },
140
178
  xyzzy,
141
179
  });
142
180
  });
143
181
 
144
182
  it("should be applied if conditions are met and no value exists", () => {
145
- const o = { fixed: "boo", role: "u1", xyzzy };
183
+ const o = {
184
+ fixed: { value: "boo", origin: "user" },
185
+ role: { value: "u1", origin: "user" },
186
+ xyzzy,
187
+ };
146
188
  const result = applyTemplate(template)(o);
147
189
  expect(result).toEqual({
148
- fixed: null,
149
- role: "u1",
150
- wibble: "wobble",
190
+ fixed: { value: null, origin: "user" },
191
+ role: { value: "u1", origin: "user" },
192
+ wibble: { value: "wobble", origin: "default" },
151
193
  xyzzy,
152
194
  });
153
195
  });
154
196
 
155
197
  it("should be applied if values of fixed field has multiple cardinality", () => {
156
- const o = { fixed: ["boo", "foo", "bar", "far"] };
198
+ const o = {
199
+ fixed: { value: ["boo", "foo", "bar", "far"], origin: "user" },
200
+ };
157
201
  const result = applyTemplate(template)(o);
158
202
  expect(result).toEqual({
159
- fixed: ["foo", "bar"],
203
+ fixed: { value: ["foo", "bar"], origin: "user" },
160
204
  });
161
205
  });
162
206
 
163
207
  it("applyTemplateWithoutDefaults should not apply default values", () => {
164
- const o = { role: "u1" };
208
+ const o = { role: { value: "u1", origin: "user" } };
165
209
  const result = applyTemplateWithoutDefaults(template)(o);
166
210
  expect(result).toEqual({
167
- role: "u1",
211
+ role: { value: "u1", origin: "user" },
168
212
  });
169
213
  });
170
214
  });
@@ -1,19 +1,18 @@
1
- import _ from "lodash/fp";
2
1
  import { filterDepends, isDepends } from "..";
3
2
 
4
3
  const depends1 = {
5
4
  name: "target",
6
5
  depends: {
7
6
  on: "src",
8
- to_be: ["foo"]
9
- }
7
+ to_be: ["foo"],
8
+ },
10
9
  };
11
10
  const depends2 = {
12
11
  name: "target2",
13
12
  depends: {
14
13
  on: "src",
15
- to_be: ["bar"]
16
- }
14
+ to_be: ["bar"],
15
+ },
17
16
  };
18
17
  const templateContent = [depends1, depends2];
19
18
 
@@ -25,7 +24,11 @@ describe("utils: isDepends", () => {
25
24
 
26
25
  describe("utils: filterDepends", () => {
27
26
  it("should remove keys with unmatched depends", () => {
28
- const o = { src: "foo", target: "asd", xyzzy: "xyzzy" };
27
+ const o = {
28
+ src: { value: "foo", origin: "default" },
29
+ target: { value: "asd", origin: "default" },
30
+ xyzzy: { value: "xyzzy", origin: "default" },
31
+ };
29
32
  const filter = filterDepends(templateContent);
30
33
  expect(filter({ ...o, target2: "boo" })).toMatchObject(o);
31
34
  });