Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

Commit 24119a5

Browse files
Valerii RadkolukaszMycs
authored andcommitted
N/ui/serverWidget enums (#19)
* Add Enums to ui/serverWidget mock * Add getSublist method to form util * Change return object on addSublist method of form util * Add simple unit test to increase code coverage * Add an other simple unit test to increase code coverage
1 parent ec00ae9 commit 24119a5

File tree

3 files changed

+72
-7
lines changed

3 files changed

+72
-7
lines changed

N/ui/serverWidget.js

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,61 @@ const Form = require('../../Utils/form');
77
* @returns {N/server/widget}
88
*/
99

10-
const FieldType = { DATE: 'date' };
11-
const FieldLayoutType = { NORMAL: 'normal' };
12-
const FieldBreakType = { STARTCOL: 'startcol' };
13-
const FieldDisplayType = { HIDDEN: 'hidden' };
14-
const SublistType = { LIST: 'list' };
10+
const FieldType = {
11+
CHECKBOX: 'checkbox',
12+
CURRENCY: 'currency',
13+
DATE: 'date',
14+
DATETIME: 'datetime',
15+
DATETIMETZ: 'datetimetz',
16+
EMAIL: 'email',
17+
FILE: 'file',
18+
FLOAT: 'float',
19+
HELP: 'help',
20+
INLINEHTML: 'inlinehtml',
21+
INTEGER: 'interger',
22+
IMAGE: 'image',
23+
LABEL: 'label',
24+
LONGTEXT: 'longtext',
25+
MULTISELECT: 'multiselect',
26+
PASSWORD: 'password',
27+
PERCENT: 'percent',
28+
PHONE: 'phone',
29+
SELECT: 'select',
30+
RADIO: 'radio',
31+
RICHTEXT: 'richtext',
32+
TEXT: 'text',
33+
TEXTAREA: 'textarea',
34+
TIMEOFDAY: 'timeofday',
35+
URL: 'url',
36+
};
37+
const FieldLayoutType = {
38+
STARTROW: 'startrow',
39+
MIDROW: 'midrow',
40+
ENDROW: 'endrow',
41+
OUTSIDE: 'outside',
42+
OUTSIDEBELOW: 'outsidebelow',
43+
OUTSIDEABOVE: 'outsideabove',
44+
NORMAL: 'normal',
45+
};
46+
const FieldBreakType = {
47+
NONE: 'none',
48+
STARTCOL: 'startcol',
49+
STARTROW: 'startrow',
50+
};
51+
const FieldDisplayType = {
52+
DISABLED: 'disabled',
53+
ENTRY: 'entry',
54+
HIDDEN: 'hidden',
55+
INLINE: 'inline',
56+
NORMAL: 'normal',
57+
READONLY: 'readonly',
58+
};
59+
const SublistType = {
60+
INLINEEDITOR: 'inlineeditor',
61+
EDITOR: 'editor',
62+
LIST: 'list',
63+
STATICLIST: 'staticlist',
64+
};
1565

1666
module.exports = {
1767
FieldType,

Tests/Utils/form.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,13 @@ describe('Testing form', () => {
99
it('Should return a function ', () => {
1010
expect(fileUnderTest).toEqual(expect.any(Function));
1111
});
12+
13+
it('Should return a object ', () => {
14+
expect(fileUnderTest()).toEqual(expect.any(Object));
15+
});
16+
17+
it('Should has own property addButton ', () => {
18+
const result = fileUnderTest().addSublist({ id: 'id', type: 'type', label: 'label' });
19+
expect(Object.prototype.hasOwnProperty.call(result, 'addButton')).toBeTruthy();
20+
});
1221
});

Utils/form.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ function NsForm(name) {
2222
getName: () => this.name,
2323
addButton: obj => this.buttons.push(obj),
2424
addSublist: (obj) => {
25-
this.sublist.push(obj);
26-
return {
25+
const list = {
26+
...obj,
2727
addField: (options) => {
2828
this.fields.push(options);
2929
return field;
3030
},
31+
addButton: (options) => {
32+
this.buttons.push(options);
33+
},
3134
setSublistValue: () => '',
3235
};
36+
this.sublist.push(list);
37+
return list;
3338
},
3439
addSubmitButton: obj => this.submitButtons.push(obj),
3540
addField: (obj) => {
@@ -38,6 +43,7 @@ function NsForm(name) {
3843
},
3944
getFields: () => this.fields,
4045
getButtons: () => this.buttons,
46+
getSublist: ({ id }) => this.sublist.find(list => list.id === id),
4147
getSubmitButtons: () => this.submitButtons,
4248
};
4349
}

0 commit comments

Comments
 (0)