@beinformed/ui 1.27.4 → 1.27.5
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.
- package/CHANGELOG.md +6 -0
- package/esm/models/actions/ActionCollection.js +10 -16
- package/esm/models/actions/ActionCollection.js.map +1 -1
- package/lib/models/actions/ActionCollection.js +10 -16
- package/lib/models/actions/ActionCollection.js.flow +12 -20
- package/lib/models/actions/ActionCollection.js.map +1 -1
- package/lib/models/actions/__tests__/ActionCollection.spec.js.flow +16 -4
- package/package.json +1 -1
- package/src/models/actions/ActionCollection.js +12 -20
- package/src/models/actions/__tests__/ActionCollection.spec.js +16 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.27.5](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.27.4...v1.27.5) (2023-02-07)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- **actions:** allow for action collections where part of contributions is not available ([ee1f482](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/ee1f482edf21f3c783b4f5f5b927f6838d36f626))
|
|
10
|
+
|
|
5
11
|
### [1.27.4](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.27.3...v1.27.4) (2023-02-07)
|
|
6
12
|
|
|
7
13
|
### Bug Fixes
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
2
1
|
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
3
2
|
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
4
3
|
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
4
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
5
5
|
import BaseCollection from "../base/BaseCollection";
|
|
6
6
|
import ActionModel from "./ActionModel";
|
|
7
|
-
import { IllegalArgumentException } from "../../exceptions";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Collection of actions
|
|
@@ -14,22 +13,17 @@ export default class ActionCollection extends BaseCollection {
|
|
|
14
13
|
super();
|
|
15
14
|
|
|
16
15
|
// no actions gives an empty collection
|
|
17
|
-
if (!actions) {
|
|
16
|
+
if (!Array.isArray(actions)) {
|
|
18
17
|
this.collection = [];
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (actionsContributions) {
|
|
26
|
-
const contributions = _findInstanceProperty(actionsContributions).call(actionsContributions, actionContribution => actionContribution.name === action.name);
|
|
27
|
-
if (contributions) {
|
|
28
|
-
return new ActionModel(action, contributions);
|
|
29
|
-
}
|
|
18
|
+
} else if (Array.isArray(actionsContributions)) {
|
|
19
|
+
const actionModels = [];
|
|
20
|
+
for (const actionData of actions) {
|
|
21
|
+
const actionContribution = _findInstanceProperty(actionsContributions).call(actionsContributions, actionContribution => actionContribution.name === actionData.name);
|
|
22
|
+
if (actionContribution) {
|
|
23
|
+
actionModels.push(new ActionModel(actionData, actionContribution));
|
|
30
24
|
}
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
}
|
|
26
|
+
this.collection = actionModels;
|
|
33
27
|
}
|
|
34
28
|
}
|
|
35
29
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionCollection.js","names":["BaseCollection","ActionModel","
|
|
1
|
+
{"version":3,"file":"ActionCollection.js","names":["BaseCollection","ActionModel","ActionCollection","constructor","actions","actionsContributions","Array","isArray","collection","actionModels","actionData","actionContribution","name","push","getActionByKey","key","newCollection","action","first","getActionsByType","type","getActionsByLayoutHint","hints","layouthint","has","hasActionsByLayoutHint","length","routePath","enabledRoutes","isDisabled","path","selfhref","join"],"sources":["../../../src/models/actions/ActionCollection.js"],"sourcesContent":["// @flow\nimport BaseCollection from \"../base/BaseCollection\";\nimport ActionModel from \"./ActionModel\";\n\n/**\n * Collection of actions\n */\nexport default class ActionCollection extends BaseCollection<ActionModel> {\n constructor(actions?: Object, actionsContributions?: Object) {\n super();\n\n // no actions gives an empty collection\n if (!Array.isArray(actions)) {\n this.collection = [];\n } else if (Array.isArray(actionsContributions)) {\n const actionModels = [];\n for (const actionData of actions) {\n const actionContribution = actionsContributions.find(\n (actionContribution) => actionContribution.name === actionData.name\n );\n\n if (actionContribution) {\n actionModels.push(new ActionModel(actionData, actionContribution));\n }\n }\n\n this.collection = actionModels;\n }\n }\n\n /**\n * Retrieve action by key\n */\n getActionByKey(key: string): ActionModel | null {\n const newCollection = new ActionCollection();\n\n newCollection.collection = this.filter((action) => action.key === key);\n\n return newCollection.first;\n }\n\n /**\n * Retrieve actions by type\n */\n getActionsByType(type: string | Array<string>): ActionCollection {\n const newCollection = new ActionCollection();\n\n newCollection.collection = this.filter((action) =>\n Array.isArray(type) ? type.includes(action.type) : action.type === type\n );\n\n return newCollection;\n }\n\n /**\n * Retrieve actions including a layout hint\n */\n getActionsByLayoutHint(...hints: Array<string>): ActionCollection {\n const newCollection = new ActionCollection();\n\n newCollection.collection = this.filter((action) =>\n action.layouthint.has(...hints)\n );\n\n return newCollection;\n }\n\n /**\n * Indicates if an action with layout hint exists\n */\n hasActionsByLayoutHint(...hints: Array<string>): boolean {\n return this.getActionsByLayoutHint(...hints).length > 0;\n }\n\n /**\n * Use as path regex for react router routes\n */\n get routePath(): string {\n const enabledRoutes = this.collection.filter(\n (action) => !action.isDisabled\n );\n\n if (enabledRoutes.length === 0) {\n return \"__NON_EXISTING_ROUTE__\";\n }\n\n const path = enabledRoutes.map((action) => action.selfhref.path).join(\"|\");\n\n return this.length > 1 ? `(${path})` : path;\n }\n}\n"],"mappings":";;;;AACA,OAAOA,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G,IAAI,CAAC,GAAGH,MAAM,CAACG,IAAI,KAAKA,IAAI,CACxE;IAED,OAAOJ,aAAa;EACtB;;EAEA;AACF;AACA;EACEK,sBAAsB,GAA4C;IAAA;IAAA,kCAAxCC,KAAK;MAALA,KAAK;IAAA;IAC7B,MAAMN,aAAa,GAAG,IAAId,gBAAgB,EAAE;IAE5Cc,aAAa,CAACR,UAAU,GAAG,wCAAI,kBAASS,MAAM,IAC5CA,MAAM,CAACM,UAAU,CAACC,GAAG,CAAC,GAAGF,KAAK,CAAC,CAChC;IAED,OAAON,aAAa;EACtB;;EAEA;AACF;AACA;EACES,sBAAsB,GAAmC;IACvD,OAAO,IAAI,CAACJ,sBAAsB,CAAC,YAAQ,CAAC,CAACK,MAAM,GAAG,CAAC;EACzD;;EAEA;AACF;AACA;EACE,IAAIC,SAAS,GAAW;IAAA;IACtB,MAAMC,aAAa,GAAG,wCAAI,CAACpB,UAAU,kBAClCS,MAAM,IAAK,CAACA,MAAM,CAACY,UAAU,CAC/B;IAED,IAAID,aAAa,CAACF,MAAM,KAAK,CAAC,EAAE;MAC9B,OAAO,wBAAwB;IACjC;IAEA,MAAMI,IAAI,GAAG,qBAAAF,aAAa,OAAbA,aAAa,EAAMX,MAAM,IAAKA,MAAM,CAACc,QAAQ,CAACD,IAAI,CAAC,CAACE,IAAI,CAAC,GAAG,CAAC;IAE1E,OAAO,IAAI,CAACN,MAAM,GAAG,CAAC,GAAI,IAAGI,IAAK,GAAE,GAAGA,IAAI;EAC7C;AACF"}
|
|
@@ -5,13 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
9
8
|
var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
|
|
10
9
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
11
10
|
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
11
|
+
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
12
12
|
var _BaseCollection = _interopRequireDefault(require("../base/BaseCollection"));
|
|
13
13
|
var _ActionModel = _interopRequireDefault(require("./ActionModel"));
|
|
14
|
-
var _exceptions = require("../../exceptions");
|
|
15
14
|
/**
|
|
16
15
|
* Collection of actions
|
|
17
16
|
*/
|
|
@@ -20,22 +19,17 @@ class ActionCollection extends _BaseCollection.default {
|
|
|
20
19
|
super();
|
|
21
20
|
|
|
22
21
|
// no actions gives an empty collection
|
|
23
|
-
if (!actions) {
|
|
22
|
+
if (!Array.isArray(actions)) {
|
|
24
23
|
this.collection = [];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (actionsContributions) {
|
|
32
|
-
const contributions = (0, _find.default)(actionsContributions).call(actionsContributions, actionContribution => actionContribution.name === action.name);
|
|
33
|
-
if (contributions) {
|
|
34
|
-
return new _ActionModel.default(action, contributions);
|
|
35
|
-
}
|
|
24
|
+
} else if (Array.isArray(actionsContributions)) {
|
|
25
|
+
const actionModels = [];
|
|
26
|
+
for (const actionData of actions) {
|
|
27
|
+
const actionContribution = (0, _find.default)(actionsContributions).call(actionsContributions, actionContribution => actionContribution.name === actionData.name);
|
|
28
|
+
if (actionContribution) {
|
|
29
|
+
actionModels.push(new _ActionModel.default(actionData, actionContribution));
|
|
36
30
|
}
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
}
|
|
32
|
+
this.collection = actionModels;
|
|
39
33
|
}
|
|
40
34
|
}
|
|
41
35
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import BaseCollection from "../base/BaseCollection";
|
|
3
3
|
import ActionModel from "./ActionModel";
|
|
4
|
-
import { IllegalArgumentException } from "../../exceptions";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Collection of actions
|
|
@@ -11,28 +10,21 @@ export default class ActionCollection extends BaseCollection<ActionModel> {
|
|
|
11
10
|
super();
|
|
12
11
|
|
|
13
12
|
// no actions gives an empty collection
|
|
14
|
-
if (!actions) {
|
|
13
|
+
if (!Array.isArray(actions)) {
|
|
15
14
|
this.collection = [];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const contributions = actionsContributions.find(
|
|
26
|
-
(actionContribution) => actionContribution.name === action.name
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
if (contributions) {
|
|
30
|
-
return new ActionModel(action, contributions);
|
|
31
|
-
}
|
|
15
|
+
} else if (Array.isArray(actionsContributions)) {
|
|
16
|
+
const actionModels = [];
|
|
17
|
+
for (const actionData of actions) {
|
|
18
|
+
const actionContribution = actionsContributions.find(
|
|
19
|
+
(actionContribution) => actionContribution.name === actionData.name
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
if (actionContribution) {
|
|
23
|
+
actionModels.push(new ActionModel(actionData, actionContribution));
|
|
32
24
|
}
|
|
25
|
+
}
|
|
33
26
|
|
|
34
|
-
|
|
35
|
-
});
|
|
27
|
+
this.collection = actionModels;
|
|
36
28
|
}
|
|
37
29
|
}
|
|
38
30
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionCollection.js","names":["ActionCollection","BaseCollection","constructor","actions","actionsContributions","
|
|
1
|
+
{"version":3,"file":"ActionCollection.js","names":["ActionCollection","BaseCollection","constructor","actions","actionsContributions","Array","isArray","collection","actionModels","actionData","actionContribution","name","push","ActionModel","getActionByKey","key","newCollection","action","first","getActionsByType","type","getActionsByLayoutHint","hints","layouthint","has","hasActionsByLayoutHint","length","routePath","enabledRoutes","isDisabled","path","selfhref","join"],"sources":["../../../src/models/actions/ActionCollection.js"],"sourcesContent":["// @flow\nimport BaseCollection from \"../base/BaseCollection\";\nimport ActionModel from \"./ActionModel\";\n\n/**\n * Collection of actions\n */\nexport default class ActionCollection extends BaseCollection<ActionModel> {\n constructor(actions?: Object, actionsContributions?: Object) {\n super();\n\n // no actions gives an empty collection\n if (!Array.isArray(actions)) {\n this.collection = [];\n } else if (Array.isArray(actionsContributions)) {\n const actionModels = [];\n for (const actionData of actions) {\n const actionContribution = actionsContributions.find(\n (actionContribution) => actionContribution.name === actionData.name\n );\n\n if (actionContribution) {\n actionModels.push(new ActionModel(actionData, actionContribution));\n }\n }\n\n this.collection = actionModels;\n }\n }\n\n /**\n * Retrieve action by key\n */\n getActionByKey(key: string): ActionModel | null {\n const newCollection = new ActionCollection();\n\n newCollection.collection = this.filter((action) => action.key === key);\n\n return newCollection.first;\n }\n\n /**\n * Retrieve actions by type\n */\n getActionsByType(type: string | Array<string>): ActionCollection {\n const newCollection = new ActionCollection();\n\n newCollection.collection = this.filter((action) =>\n Array.isArray(type) ? type.includes(action.type) : action.type === type\n );\n\n return newCollection;\n }\n\n /**\n * Retrieve actions including a layout hint\n */\n getActionsByLayoutHint(...hints: Array<string>): ActionCollection {\n const newCollection = new ActionCollection();\n\n newCollection.collection = this.filter((action) =>\n action.layouthint.has(...hints)\n );\n\n return newCollection;\n }\n\n /**\n * Indicates if an action with layout hint exists\n */\n hasActionsByLayoutHint(...hints: Array<string>): boolean {\n return this.getActionsByLayoutHint(...hints).length > 0;\n }\n\n /**\n * Use as path regex for react router routes\n */\n get routePath(): string {\n const enabledRoutes = this.collection.filter(\n (action) => !action.isDisabled\n );\n\n if (enabledRoutes.length === 0) {\n return \"__NON_EXISTING_ROUTE__\";\n }\n\n const path = enabledRoutes.map((action) => action.selfhref.path).join(\"|\");\n\n return this.length > 1 ? `(${path})` : path;\n }\n}\n"],"mappings":";;;;;;;;;;;AACA;AACA;AAEA;AACA;AACA;AACe,MAAMA,gBAAgB,SAASC,uBAAc,CAAc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,sBAAsB,GAA4C;IAAA;IAAA,kCAAxCC,KAAK;MAALA,KAAK;IAAA;IAC7B,MAAMN,aAAa,GAAG,IAAIhB,gBAAgB,EAAE;IAE5CgB,aAAa,CAACT,UAAU,GAAG,qCAAI,kBAASU,MAAM,IAC5CA,MAAM,CAACM,UAAU,CAACC,GAAG,CAAC,GAAGF,KAAK,CAAC,CAChC;IAED,OAAON,aAAa;EACtB;;EAEA;AACF;AACA;EACES,sBAAsB,GAAmC;IACvD,OAAO,IAAI,CAACJ,sBAAsB,CAAC,YAAQ,CAAC,CAACK,MAAM,GAAG,CAAC;EACzD;;EAEA;AACF;AACA;EACE,IAAIC,SAAS,GAAW;IAAA;IACtB,MAAMC,aAAa,GAAG,qCAAI,CAACrB,UAAU,kBAClCU,MAAM,IAAK,CAACA,MAAM,CAACY,UAAU,CAC/B;IAED,IAAID,aAAa,CAACF,MAAM,KAAK,CAAC,EAAE;MAC9B,OAAO,wBAAwB;IACjC;IAEA,MAAMI,IAAI,GAAG,kBAAAF,aAAa,OAAbA,aAAa,EAAMX,MAAM,IAAKA,MAAM,CAACc,QAAQ,CAACD,IAAI,CAAC,CAACE,IAAI,CAAC,GAAG,CAAC;IAE1E,OAAO,IAAI,CAACN,MAAM,GAAG,CAAC,GAAI,IAAGI,IAAK,GAAE,GAAGA,IAAI;EAC7C;AACF;AAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import ActionCollection from "../ActionCollection";
|
|
2
2
|
import ActionModel from "../ActionModel";
|
|
3
|
-
import { IllegalArgumentException } from "../../../exceptions";
|
|
4
3
|
|
|
5
4
|
describe("actionCollection", () => {
|
|
6
5
|
const collectionData = [
|
|
@@ -62,9 +61,8 @@ describe("actionCollection", () => {
|
|
|
62
61
|
});
|
|
63
62
|
|
|
64
63
|
it("should throw an error when action data is available but no contributions", () => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}).toThrow(IllegalArgumentException);
|
|
64
|
+
const coll = new ActionCollection(collectionData);
|
|
65
|
+
expect(coll).toHaveLength(0);
|
|
68
66
|
});
|
|
69
67
|
|
|
70
68
|
it("should be able to create an ActionCollection with standard modular ui json", () => {
|
|
@@ -83,4 +81,18 @@ describe("actionCollection", () => {
|
|
|
83
81
|
ActionModel
|
|
84
82
|
);
|
|
85
83
|
});
|
|
84
|
+
|
|
85
|
+
it("should be able to create an ActionCollection with part of contributions available", () => {
|
|
86
|
+
const actionCollection = new ActionCollection(collectionData, [
|
|
87
|
+
{
|
|
88
|
+
name: "sample2",
|
|
89
|
+
label: "Example of an action by layouthint",
|
|
90
|
+
type: "generic",
|
|
91
|
+
layouthint: ["testaction"],
|
|
92
|
+
},
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
expect(actionCollection).toHaveLength(1);
|
|
96
|
+
expect(actionCollection.getActionsByType("form")).toHaveLength(0);
|
|
97
|
+
});
|
|
86
98
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import BaseCollection from "../base/BaseCollection";
|
|
3
3
|
import ActionModel from "./ActionModel";
|
|
4
|
-
import { IllegalArgumentException } from "../../exceptions";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Collection of actions
|
|
@@ -11,28 +10,21 @@ export default class ActionCollection extends BaseCollection<ActionModel> {
|
|
|
11
10
|
super();
|
|
12
11
|
|
|
13
12
|
// no actions gives an empty collection
|
|
14
|
-
if (!actions) {
|
|
13
|
+
if (!Array.isArray(actions)) {
|
|
15
14
|
this.collection = [];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const contributions = actionsContributions.find(
|
|
26
|
-
(actionContribution) => actionContribution.name === action.name
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
if (contributions) {
|
|
30
|
-
return new ActionModel(action, contributions);
|
|
31
|
-
}
|
|
15
|
+
} else if (Array.isArray(actionsContributions)) {
|
|
16
|
+
const actionModels = [];
|
|
17
|
+
for (const actionData of actions) {
|
|
18
|
+
const actionContribution = actionsContributions.find(
|
|
19
|
+
(actionContribution) => actionContribution.name === actionData.name
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
if (actionContribution) {
|
|
23
|
+
actionModels.push(new ActionModel(actionData, actionContribution));
|
|
32
24
|
}
|
|
25
|
+
}
|
|
33
26
|
|
|
34
|
-
|
|
35
|
-
});
|
|
27
|
+
this.collection = actionModels;
|
|
36
28
|
}
|
|
37
29
|
}
|
|
38
30
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import ActionCollection from "../ActionCollection";
|
|
2
2
|
import ActionModel from "../ActionModel";
|
|
3
|
-
import { IllegalArgumentException } from "../../../exceptions";
|
|
4
3
|
|
|
5
4
|
describe("actionCollection", () => {
|
|
6
5
|
const collectionData = [
|
|
@@ -62,9 +61,8 @@ describe("actionCollection", () => {
|
|
|
62
61
|
});
|
|
63
62
|
|
|
64
63
|
it("should throw an error when action data is available but no contributions", () => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}).toThrow(IllegalArgumentException);
|
|
64
|
+
const coll = new ActionCollection(collectionData);
|
|
65
|
+
expect(coll).toHaveLength(0);
|
|
68
66
|
});
|
|
69
67
|
|
|
70
68
|
it("should be able to create an ActionCollection with standard modular ui json", () => {
|
|
@@ -83,4 +81,18 @@ describe("actionCollection", () => {
|
|
|
83
81
|
ActionModel
|
|
84
82
|
);
|
|
85
83
|
});
|
|
84
|
+
|
|
85
|
+
it("should be able to create an ActionCollection with part of contributions available", () => {
|
|
86
|
+
const actionCollection = new ActionCollection(collectionData, [
|
|
87
|
+
{
|
|
88
|
+
name: "sample2",
|
|
89
|
+
label: "Example of an action by layouthint",
|
|
90
|
+
type: "generic",
|
|
91
|
+
layouthint: ["testaction"],
|
|
92
|
+
},
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
expect(actionCollection).toHaveLength(1);
|
|
96
|
+
expect(actionCollection.getActionsByType("form")).toHaveLength(0);
|
|
97
|
+
});
|
|
86
98
|
});
|