@zeedhi/teknisa-components-common 1.107.2 → 1.108.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.
- package/LICENSE +21 -21
- package/README.md +7 -7
- package/coverage/clover.xml +772 -692
- package/coverage/coverage-final.json +47 -47
- package/coverage/lcov-report/index.html +15 -15
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +2 -2
- package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +2 -2
- package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +7 -7
- package/coverage/lcov-report/tests/__helpers__/index.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +1 -1
- package/coverage/lcov.info +1459 -1275
- package/dist/tek-components-common.esm.js +375 -252
- package/dist/tek-components-common.umd.js +375 -252
- package/jest.config.js +1 -1
- package/package.json +2 -2
- package/tests/__helpers__/component-event-helper.ts +5 -5
- package/tests/__helpers__/flush-promises-helper.ts +3 -3
- package/tests/__helpers__/get-child-helper.ts +27 -27
- package/tests/__helpers__/index.ts +3 -3
- package/tests/__helpers__/mock-created-helper.ts +12 -12
- package/tests/__mocks__/@zeedhi/core/i18n.js +74 -74
- package/tests/__mocks__/@zeedhi/core.js +4 -4
- package/tests/unit/components/crud/crud-add-button.spec.ts +56 -56
- package/tests/unit/components/crud/crud-button.spec.ts +94 -94
- package/tests/unit/components/crud/crud-cancel-button.spec.ts +91 -91
- package/tests/unit/components/crud/crud-delete-button.spec.ts +122 -122
- package/tests/unit/components/crud/crud-form.spec.ts +165 -165
- package/tests/unit/components/crud/crud-save-button.spec.ts +118 -118
- package/tests/unit/components/tek-breadcrumb-header/tek-breadcrumb-header.spec.ts +42 -42
- package/tests/unit/components/tek-card-title/CardTitle.spec.ts +34 -34
- package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +470 -470
- package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +364 -364
- package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +112 -112
- package/tests/unit/components/tek-grid/filter-helper.spec.ts +148 -148
- package/tests/unit/components/tek-grid/grid-column.spec.ts +270 -270
- package/tests/unit/components/tek-grid/grid-columns-button.spec.ts +195 -195
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +967 -967
- package/tests/unit/components/tek-grid/grid.spec.ts +3340 -3116
- package/tests/unit/components/tek-grid/layout_options.spec.ts +980 -980
- package/tests/unit/components/tek-image/Image.spec.ts +67 -67
- package/tests/unit/components/tek-iterable-carousel/iterable-carousel.spec.ts +37 -37
- package/tests/unit/components/tek-iterable-component-render/iterable-component-render.spec.ts +200 -200
- package/tests/unit/components/tek-loading/Loading.spec.ts +30 -30
- package/tests/unit/components/tek-notifications/notifications.spec.ts +201 -201
- package/tests/unit/components/tek-product-card/product-card.spec.ts +61 -61
- package/tests/unit/components/tek-user-info/TekUserInfoContoller.spec.ts +220 -220
- package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +86 -86
- package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +430 -430
- package/tests/unit/components/tree-grid/tree-grid.spec.ts +776 -776
- package/tests/unit/utils/grid-base/delete-rows-error.spec.ts +24 -0
- package/tests/unit/utils/grid-base/export-options/button-option.spec.ts +44 -44
- package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +135 -135
- package/tests/unit/utils/grid-base/grid-controller.spec.ts +267 -174
- package/tests/unit/utils/report-filter/report-filter.spec.ts +66 -66
- package/tsconfig.eslint.json +8 -8
- package/types/components/tek-datasource/memory-datasource.d.ts +2 -4
- package/types/components/tek-datasource/rest-datasource.d.ts +6 -3
- package/types/components/tek-grid/grid.d.ts +50 -6
- package/types/components/tek-grid/interfaces.d.ts +5 -3
- package/types/components/tek-tree-grid/tree-grid.d.ts +5 -1
- package/types/utils/grid-base/grid-base.d.ts +12 -229
- package/types/utils/grid-base/grid-controller.d.ts +1 -3
- package/types/components/tek-ag-grid/default-icons.d.ts +0 -53
- package/types/components/tek-ag-grid/interfaces.d.ts +0 -9
- package/types/components/tek-ag-grid/tek-ag-grid.d.ts +0 -35
- package/types/components/tek-datasource/datasource.d.ts +0 -94
- package/types/components/tek-grid/default-icons.d.ts +0 -53
- package/types/components/tek-grid/filter-dynamic-values.d.ts +0 -9
- package/types/components/tek-grid/grid-controller.d.ts +0 -19
- package/types/components/tek-grid/grid_column.d.ts +0 -14
- package/types/components/tek-grid/grid_controller.d.ts +0 -15
- package/types/components/tek-grid/tek-grid.d.ts +0 -35
- package/types/components/tek-login/interfaces.d.ts +0 -3
- package/types/components/tek-login/login-children.d.ts +0 -3
- package/types/components/tek-login/login.d.ts +0 -58
- package/types/components/tek-login/login_children.d.ts +0 -3
package/jest.config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('../../jest.config.js');
|
|
1
|
+
module.exports = require('../../jest.config.js');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeedhi/teknisa-components-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.108.0",
|
|
4
4
|
"description": "Teknisa Components Common",
|
|
5
5
|
"author": "Zeedhi <zeedhi@teknisa.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@zeedhi/core": "^1.97.0"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "c23fc7d327e5cd145b75229b2dca54967ec803d3"
|
|
36
36
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Component } from '@zeedhi/common';
|
|
2
|
-
|
|
3
|
-
const setClick = (instance: Component, event: any = {}) => instance.click(event, {});
|
|
4
|
-
|
|
5
|
-
export { setClick };
|
|
1
|
+
import { Component } from '@zeedhi/common';
|
|
2
|
+
|
|
3
|
+
const setClick = (instance: Component, event: any = {}) => instance.click(event, {});
|
|
4
|
+
|
|
5
|
+
export { setClick };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const flushPromises = () => (new Promise(setImmediate));
|
|
2
|
-
|
|
3
|
-
export { flushPromises };
|
|
1
|
+
const flushPromises = () => (new Promise(setImmediate));
|
|
2
|
+
|
|
3
|
+
export { flushPromises };
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { IComponent } from '@zeedhi/common';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Search for a component inside an array of children
|
|
5
|
-
*
|
|
6
|
-
* The children array can be either an array of IComponent or an array of Component
|
|
7
|
-
*/
|
|
8
|
-
const getChild = <T extends IComponent>(children: any[], name: string): T => {
|
|
9
|
-
let found: any;
|
|
10
|
-
|
|
11
|
-
children.forEach((child) => {
|
|
12
|
-
if (child.name === name) {
|
|
13
|
-
found = child;
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (child.children && child.children.length > 0) {
|
|
18
|
-
const result = getChild<T>(child.children, name) as T;
|
|
19
|
-
|
|
20
|
-
if (result) found = result;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
return found;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export { getChild };
|
|
1
|
+
import { IComponent } from '@zeedhi/common';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Search for a component inside an array of children
|
|
5
|
+
*
|
|
6
|
+
* The children array can be either an array of IComponent or an array of Component
|
|
7
|
+
*/
|
|
8
|
+
const getChild = <T extends IComponent>(children: any[], name: string): T => {
|
|
9
|
+
let found: any;
|
|
10
|
+
|
|
11
|
+
children.forEach((child) => {
|
|
12
|
+
if (child.name === name) {
|
|
13
|
+
found = child;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (child.children && child.children.length > 0) {
|
|
18
|
+
const result = getChild<T>(child.children, name) as T;
|
|
19
|
+
|
|
20
|
+
if (result) found = result;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return found;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { getChild };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './component-event-helper';
|
|
2
|
-
export * from './get-child-helper';
|
|
3
|
-
export * from './mock-created-helper';
|
|
1
|
+
export * from './component-event-helper';
|
|
2
|
+
export * from './get-child-helper';
|
|
3
|
+
export * from './mock-created-helper';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ComponentRender } from '@zeedhi/common';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Function used to spy on a class' onCreated and always assign the componentId as 1
|
|
5
|
-
*/
|
|
6
|
-
const mockCreated = <T extends ComponentRender>(component: T, prototype: any) => {
|
|
7
|
-
jest.spyOn(prototype, 'onCreated').mockImplementation(() => {
|
|
8
|
-
component.componentId = 1;
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export { mockCreated };
|
|
1
|
+
import { ComponentRender } from '@zeedhi/common';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Function used to spy on a class' onCreated and always assign the componentId as 1
|
|
5
|
+
*/
|
|
6
|
+
const mockCreated = <T extends ComponentRender>(component: T, prototype: any) => {
|
|
7
|
+
jest.spyOn(prototype, 'onCreated').mockImplementation(() => {
|
|
8
|
+
component.componentId = 1;
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { mockCreated };
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mock for @zeedhi/core I18n API
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const words = {
|
|
6
|
-
TEKGRID_CONTAINS: 'contains',
|
|
7
|
-
TEKGRID_NOT_CONTAINS: 'does not contain',
|
|
8
|
-
TEKGRID_EQUALS: 'is equal to',
|
|
9
|
-
TEKGRID_NOT_EQUALS: 'is different from',
|
|
10
|
-
TEKGRID_GREATER_THAN: 'is greater than',
|
|
11
|
-
TEKGRID_LESS_THAN: 'is less than',
|
|
12
|
-
TEKGRID_GREATER_THAN_EQUALS: 'is greater or equals to',
|
|
13
|
-
TEKGRID_LESS_THAN_EQUALS: 'is less or equals to',
|
|
14
|
-
TEKGRID_IN: 'is in',
|
|
15
|
-
TEKGRID_NOT_IN: 'is not in',
|
|
16
|
-
TEKGRID_BETWEEN: 'is between',
|
|
17
|
-
TEKGRID_AND: 'and',
|
|
18
|
-
TEKGRID_OR: 'or',
|
|
19
|
-
TEKGRID_ADD: 'Add',
|
|
20
|
-
TEKGRID_DELETE: 'Delete',
|
|
21
|
-
TEKGRID_REFRESH: 'Refresh',
|
|
22
|
-
TEKGRID_COLUMNS: 'Columns',
|
|
23
|
-
TEKGRID_SAVE: 'Save',
|
|
24
|
-
TEKGRID_CANCEL: 'Cancel',
|
|
25
|
-
TEKGRID_FILTER: 'Filter',
|
|
26
|
-
TEKGRID_MULTIPLE_VALUE_HINT: 'Separate values using ";"',
|
|
27
|
-
TEKGRID_EXPORT: 'Export',
|
|
28
|
-
TEKGRID_EXPORT_AS: 'Export as {{type}}',
|
|
29
|
-
TEKGRID_COLUMN_VISIBLE: 'Visible',
|
|
30
|
-
TEKGRID_COLUMN_GROUPED: 'Grouped',
|
|
31
|
-
TEKGRID_COLUMN_AGGREGATION: 'Aggregation',
|
|
32
|
-
TEKGRID_AGGREGATION_SUM: 'Sum',
|
|
33
|
-
TEKGRID_AGGREGATION_AVG: 'Average',
|
|
34
|
-
TEKGRID_AGGREGATION_MAX: 'Maximum',
|
|
35
|
-
TEKGRID_AGGREGATION_MIN: 'Minimum',
|
|
36
|
-
TEKGRID_AGGREGATION_COUNT: 'Count',
|
|
37
|
-
NO_NOTIFICATIONS: 'No Notifications',
|
|
38
|
-
MARK_ALL_AS_READ: 'Mark all as read',
|
|
39
|
-
NOTIFICATIONS: 'Notifications',
|
|
40
|
-
SEE_ALL_NOTIFICATIONS: 'See all notifications',
|
|
41
|
-
UNAVAILABLE_IMAGE: 'Unavailable image',
|
|
42
|
-
REFRESH: 'Refresh',
|
|
43
|
-
ACTIONS: 'Actions',
|
|
44
|
-
FILTER: 'Filter',
|
|
45
|
-
LAYOUT: 'Layout: ',
|
|
46
|
-
NEW_LAYOUT: 'New layout',
|
|
47
|
-
DEFAULT_LAYOUT: 'Default',
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const notImplemented = (name, isMethod = true) => {
|
|
51
|
-
const member = isMethod ? `I18n.${name}() method` : `I18n.${name} property`;
|
|
52
|
-
throw new Error(`The ${member} is not yet implemented/mocked by the mock in 'tests/__mocks__/@zeedhi/core/i18n.ts'.`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const mock = {
|
|
56
|
-
translate: (value, variables) => {
|
|
57
|
-
let result = words[value] || value;
|
|
58
|
-
const keys = variables ? Object.keys(variables) : undefined;
|
|
59
|
-
if (keys) {
|
|
60
|
-
keys.forEach((key) => {
|
|
61
|
-
result = result.replace(`{{${key}}}`, variables[key]);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return result;
|
|
66
|
-
},
|
|
67
|
-
registerChangeListener: () => notImplemented('registerChangeListener'),
|
|
68
|
-
unregisterChangeListener: () => notImplemented('unregisterChangeListener'),
|
|
69
|
-
init: () => notImplemented('init'),
|
|
70
|
-
changeLanguage: () => notImplemented('changeLanguage'),
|
|
71
|
-
get instance() { return { language: 'en-US'} },
|
|
72
|
-
set instance(_value) { notImplemented('instance setter') },
|
|
73
|
-
}
|
|
74
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Mock for @zeedhi/core I18n API
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const words = {
|
|
6
|
+
TEKGRID_CONTAINS: 'contains',
|
|
7
|
+
TEKGRID_NOT_CONTAINS: 'does not contain',
|
|
8
|
+
TEKGRID_EQUALS: 'is equal to',
|
|
9
|
+
TEKGRID_NOT_EQUALS: 'is different from',
|
|
10
|
+
TEKGRID_GREATER_THAN: 'is greater than',
|
|
11
|
+
TEKGRID_LESS_THAN: 'is less than',
|
|
12
|
+
TEKGRID_GREATER_THAN_EQUALS: 'is greater or equals to',
|
|
13
|
+
TEKGRID_LESS_THAN_EQUALS: 'is less or equals to',
|
|
14
|
+
TEKGRID_IN: 'is in',
|
|
15
|
+
TEKGRID_NOT_IN: 'is not in',
|
|
16
|
+
TEKGRID_BETWEEN: 'is between',
|
|
17
|
+
TEKGRID_AND: 'and',
|
|
18
|
+
TEKGRID_OR: 'or',
|
|
19
|
+
TEKGRID_ADD: 'Add',
|
|
20
|
+
TEKGRID_DELETE: 'Delete',
|
|
21
|
+
TEKGRID_REFRESH: 'Refresh',
|
|
22
|
+
TEKGRID_COLUMNS: 'Columns',
|
|
23
|
+
TEKGRID_SAVE: 'Save',
|
|
24
|
+
TEKGRID_CANCEL: 'Cancel',
|
|
25
|
+
TEKGRID_FILTER: 'Filter',
|
|
26
|
+
TEKGRID_MULTIPLE_VALUE_HINT: 'Separate values using ";"',
|
|
27
|
+
TEKGRID_EXPORT: 'Export',
|
|
28
|
+
TEKGRID_EXPORT_AS: 'Export as {{type}}',
|
|
29
|
+
TEKGRID_COLUMN_VISIBLE: 'Visible',
|
|
30
|
+
TEKGRID_COLUMN_GROUPED: 'Grouped',
|
|
31
|
+
TEKGRID_COLUMN_AGGREGATION: 'Aggregation',
|
|
32
|
+
TEKGRID_AGGREGATION_SUM: 'Sum',
|
|
33
|
+
TEKGRID_AGGREGATION_AVG: 'Average',
|
|
34
|
+
TEKGRID_AGGREGATION_MAX: 'Maximum',
|
|
35
|
+
TEKGRID_AGGREGATION_MIN: 'Minimum',
|
|
36
|
+
TEKGRID_AGGREGATION_COUNT: 'Count',
|
|
37
|
+
NO_NOTIFICATIONS: 'No Notifications',
|
|
38
|
+
MARK_ALL_AS_READ: 'Mark all as read',
|
|
39
|
+
NOTIFICATIONS: 'Notifications',
|
|
40
|
+
SEE_ALL_NOTIFICATIONS: 'See all notifications',
|
|
41
|
+
UNAVAILABLE_IMAGE: 'Unavailable image',
|
|
42
|
+
REFRESH: 'Refresh',
|
|
43
|
+
ACTIONS: 'Actions',
|
|
44
|
+
FILTER: 'Filter',
|
|
45
|
+
LAYOUT: 'Layout: ',
|
|
46
|
+
NEW_LAYOUT: 'New layout',
|
|
47
|
+
DEFAULT_LAYOUT: 'Default',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const notImplemented = (name, isMethod = true) => {
|
|
51
|
+
const member = isMethod ? `I18n.${name}() method` : `I18n.${name} property`;
|
|
52
|
+
throw new Error(`The ${member} is not yet implemented/mocked by the mock in 'tests/__mocks__/@zeedhi/core/i18n.ts'.`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const mock = {
|
|
56
|
+
translate: (value, variables) => {
|
|
57
|
+
let result = words[value] || value;
|
|
58
|
+
const keys = variables ? Object.keys(variables) : undefined;
|
|
59
|
+
if (keys) {
|
|
60
|
+
keys.forEach((key) => {
|
|
61
|
+
result = result.replace(`{{${key}}}`, variables[key]);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return result;
|
|
66
|
+
},
|
|
67
|
+
registerChangeListener: () => notImplemented('registerChangeListener'),
|
|
68
|
+
unregisterChangeListener: () => notImplemented('unregisterChangeListener'),
|
|
69
|
+
init: () => notImplemented('init'),
|
|
70
|
+
changeLanguage: () => notImplemented('changeLanguage'),
|
|
71
|
+
get instance() { return { language: 'en-US'} },
|
|
72
|
+
set instance(_value) { notImplemented('instance setter') },
|
|
73
|
+
}
|
|
74
|
+
|
|
75
75
|
module.exports = mock;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const core = jest.requireActual('@zeedhi/core');
|
|
2
|
-
|
|
3
|
-
core.I18n = require('./core/i18n');
|
|
4
|
-
|
|
1
|
+
const core = jest.requireActual('@zeedhi/core');
|
|
2
|
+
|
|
3
|
+
core.I18n = require('./core/i18n');
|
|
4
|
+
|
|
5
5
|
module.exports = core;
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { CrudAddButton } from '../../../../src';
|
|
2
|
-
|
|
3
|
-
describe('CrudAddButton', () => {
|
|
4
|
-
describe('constructor()', () => {
|
|
5
|
-
it('should create new CrudAddButton with default values', () => {
|
|
6
|
-
const instance = new CrudAddButton({
|
|
7
|
-
name: 'saveButton',
|
|
8
|
-
component: 'TekCrudSaveButton',
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
expect(instance.clickShortcutKey).toBe('f2');
|
|
12
|
-
expect(instance.dark).toBeFalsy();
|
|
13
|
-
expect(instance.disabled).toBeFalsy();
|
|
14
|
-
expect(instance.fab).toBeFalsy();
|
|
15
|
-
expect(instance.fixed).toBeFalsy();
|
|
16
|
-
expect(instance.flat).toBeTruthy();
|
|
17
|
-
expect(instance.href).toBe('');
|
|
18
|
-
expect(instance.icon).toBeTruthy();
|
|
19
|
-
expect(instance.iconName).toBe('plus');
|
|
20
|
-
expect(instance.label).toBe('');
|
|
21
|
-
expect(instance.color).toBe('#666');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should create new CrudAddButton replace default values', () => {
|
|
25
|
-
const instance = new CrudAddButton({
|
|
26
|
-
name: 'saveButton',
|
|
27
|
-
component: 'TekCrudSaveButton',
|
|
28
|
-
clickShortcutKey: 'f3',
|
|
29
|
-
flat: true,
|
|
30
|
-
icon: false,
|
|
31
|
-
color: '#ddd',
|
|
32
|
-
iconName: 'complete',
|
|
33
|
-
});
|
|
34
|
-
expect(instance.clickShortcutKey).toBe('f3');
|
|
35
|
-
expect(instance.color).toBe('#ddd');
|
|
36
|
-
expect(instance.fixed).toBeFalsy();
|
|
37
|
-
expect(instance.flat).toBeTruthy();
|
|
38
|
-
expect(instance.icon).toBeFalsy();
|
|
39
|
-
expect(instance.iconName).toBe('complete');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('click()', () => {
|
|
43
|
-
const method = () => undefined;
|
|
44
|
-
const instance = new CrudAddButton({
|
|
45
|
-
name: 'saveButton',
|
|
46
|
-
component: 'TekCrudSaveButton',
|
|
47
|
-
clickShortcutKey: 'f2',
|
|
48
|
-
events: { click: method },
|
|
49
|
-
});
|
|
50
|
-
const spy = jest.spyOn((instance.events as any), 'click');
|
|
51
|
-
instance.click({} as Event, {} as HTMLElement);
|
|
52
|
-
expect(spy).toHaveBeenCalledWith({ component: instance, event: {}, element: {} });
|
|
53
|
-
spy.mockClear();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
1
|
+
import { CrudAddButton } from '../../../../src';
|
|
2
|
+
|
|
3
|
+
describe('CrudAddButton', () => {
|
|
4
|
+
describe('constructor()', () => {
|
|
5
|
+
it('should create new CrudAddButton with default values', () => {
|
|
6
|
+
const instance = new CrudAddButton({
|
|
7
|
+
name: 'saveButton',
|
|
8
|
+
component: 'TekCrudSaveButton',
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
expect(instance.clickShortcutKey).toBe('f2');
|
|
12
|
+
expect(instance.dark).toBeFalsy();
|
|
13
|
+
expect(instance.disabled).toBeFalsy();
|
|
14
|
+
expect(instance.fab).toBeFalsy();
|
|
15
|
+
expect(instance.fixed).toBeFalsy();
|
|
16
|
+
expect(instance.flat).toBeTruthy();
|
|
17
|
+
expect(instance.href).toBe('');
|
|
18
|
+
expect(instance.icon).toBeTruthy();
|
|
19
|
+
expect(instance.iconName).toBe('plus');
|
|
20
|
+
expect(instance.label).toBe('');
|
|
21
|
+
expect(instance.color).toBe('#666');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should create new CrudAddButton replace default values', () => {
|
|
25
|
+
const instance = new CrudAddButton({
|
|
26
|
+
name: 'saveButton',
|
|
27
|
+
component: 'TekCrudSaveButton',
|
|
28
|
+
clickShortcutKey: 'f3',
|
|
29
|
+
flat: true,
|
|
30
|
+
icon: false,
|
|
31
|
+
color: '#ddd',
|
|
32
|
+
iconName: 'complete',
|
|
33
|
+
});
|
|
34
|
+
expect(instance.clickShortcutKey).toBe('f3');
|
|
35
|
+
expect(instance.color).toBe('#ddd');
|
|
36
|
+
expect(instance.fixed).toBeFalsy();
|
|
37
|
+
expect(instance.flat).toBeTruthy();
|
|
38
|
+
expect(instance.icon).toBeFalsy();
|
|
39
|
+
expect(instance.iconName).toBe('complete');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('click()', () => {
|
|
43
|
+
const method = () => undefined;
|
|
44
|
+
const instance = new CrudAddButton({
|
|
45
|
+
name: 'saveButton',
|
|
46
|
+
component: 'TekCrudSaveButton',
|
|
47
|
+
clickShortcutKey: 'f2',
|
|
48
|
+
events: { click: method },
|
|
49
|
+
});
|
|
50
|
+
const spy = jest.spyOn((instance.events as any), 'click');
|
|
51
|
+
instance.click({} as Event, {} as HTMLElement);
|
|
52
|
+
expect(spy).toHaveBeenCalledWith({ component: instance, event: {}, element: {} });
|
|
53
|
+
spy.mockClear();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
import { GridEditable } from '@zeedhi/common';
|
|
2
|
-
import { KeyMap } from '@zeedhi/core';
|
|
3
|
-
import { CrudButton, CrudForm } from '../../../../src';
|
|
4
|
-
|
|
5
|
-
const dispatchEvent = (key: string, modifiers: any, repeated: boolean = false) => {
|
|
6
|
-
let prevented = false;
|
|
7
|
-
const event = new KeyboardEvent('keydown', modifiers);
|
|
8
|
-
delete (event as any).key;
|
|
9
|
-
Object.defineProperty(event, 'key', { value: key });
|
|
10
|
-
delete (event as any).code;
|
|
11
|
-
Object.defineProperty(event, 'code', { value: key });
|
|
12
|
-
|
|
13
|
-
if (repeated) {
|
|
14
|
-
delete (event as any).repeat;
|
|
15
|
-
Object.defineProperty(event, 'repeat', { value: true });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
delete (event as any).preventDefault;
|
|
19
|
-
Object.defineProperty(event, 'preventDefault', {
|
|
20
|
-
value: () => {
|
|
21
|
-
prevented = true;
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
document.dispatchEvent(event);
|
|
25
|
-
return prevented;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
describe('CrudButton', () => {
|
|
29
|
-
describe('constructor()', () => {
|
|
30
|
-
it('should init KeyMap', () => {
|
|
31
|
-
const instance = new CrudButton({ name: 'button', component: 'tekCrudButton' });
|
|
32
|
-
const element = document.createElement('div');
|
|
33
|
-
expect(instance.initKeyMap(element)).toBe(undefined);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should init shortcutClick', () => {
|
|
37
|
-
let called = false;
|
|
38
|
-
const method = () => { called = true; };
|
|
39
|
-
const keyMap = {
|
|
40
|
-
a: {
|
|
41
|
-
event: method,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
const instance = new CrudButton({
|
|
45
|
-
name: 'button',
|
|
46
|
-
component: 'tekCrudButton',
|
|
47
|
-
clickShortcutKey: 'a',
|
|
48
|
-
keyMap,
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
KeyMap.bind(instance.keyMap);
|
|
53
|
-
dispatchEvent('a', {});
|
|
54
|
-
expect(called).toBeFalsy();
|
|
55
|
-
KeyMap.unbind(instance.keyMap);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should init shortcutClick disabled', () => {
|
|
59
|
-
let called = false;
|
|
60
|
-
const method = () => { called = true; };
|
|
61
|
-
const keyMap = {
|
|
62
|
-
a: {
|
|
63
|
-
event: method,
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
const instance = new CrudButton({
|
|
67
|
-
name: 'button',
|
|
68
|
-
component: 'tekCrudButton',
|
|
69
|
-
clickShortcutKey: 'a',
|
|
70
|
-
disabled: true,
|
|
71
|
-
keyMap,
|
|
72
|
-
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
KeyMap.bind(instance.keyMap);
|
|
76
|
-
dispatchEvent('a', {});
|
|
77
|
-
expect(called).toBeFalsy();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('parent instanceof CrudForm', () => {
|
|
81
|
-
const instance = new CrudButton({ name: 'button', component: 'tekCrudButton' });
|
|
82
|
-
const crudForm = new CrudForm({ name: 'grid', component: 'CrudForm' });
|
|
83
|
-
instance.parent = crudForm;
|
|
84
|
-
expect(instance.parentIsEditing).toBeFalsy();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('parent instanceof GridEditable', () => {
|
|
88
|
-
const instance = new CrudButton({ name: 'button', component: 'tekCrudButton' });
|
|
89
|
-
const crudForm = new GridEditable({ name: 'grid', component: 'CrudForm' });
|
|
90
|
-
instance.parent = crudForm;
|
|
91
|
-
expect(instance.parentIsEditing).toBeFalsy();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
1
|
+
import { GridEditable } from '@zeedhi/common';
|
|
2
|
+
import { KeyMap } from '@zeedhi/core';
|
|
3
|
+
import { CrudButton, CrudForm } from '../../../../src';
|
|
4
|
+
|
|
5
|
+
const dispatchEvent = (key: string, modifiers: any, repeated: boolean = false) => {
|
|
6
|
+
let prevented = false;
|
|
7
|
+
const event = new KeyboardEvent('keydown', modifiers);
|
|
8
|
+
delete (event as any).key;
|
|
9
|
+
Object.defineProperty(event, 'key', { value: key });
|
|
10
|
+
delete (event as any).code;
|
|
11
|
+
Object.defineProperty(event, 'code', { value: key });
|
|
12
|
+
|
|
13
|
+
if (repeated) {
|
|
14
|
+
delete (event as any).repeat;
|
|
15
|
+
Object.defineProperty(event, 'repeat', { value: true });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
delete (event as any).preventDefault;
|
|
19
|
+
Object.defineProperty(event, 'preventDefault', {
|
|
20
|
+
value: () => {
|
|
21
|
+
prevented = true;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
document.dispatchEvent(event);
|
|
25
|
+
return prevented;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe('CrudButton', () => {
|
|
29
|
+
describe('constructor()', () => {
|
|
30
|
+
it('should init KeyMap', () => {
|
|
31
|
+
const instance = new CrudButton({ name: 'button', component: 'tekCrudButton' });
|
|
32
|
+
const element = document.createElement('div');
|
|
33
|
+
expect(instance.initKeyMap(element)).toBe(undefined);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should init shortcutClick', () => {
|
|
37
|
+
let called = false;
|
|
38
|
+
const method = () => { called = true; };
|
|
39
|
+
const keyMap = {
|
|
40
|
+
a: {
|
|
41
|
+
event: method,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const instance = new CrudButton({
|
|
45
|
+
name: 'button',
|
|
46
|
+
component: 'tekCrudButton',
|
|
47
|
+
clickShortcutKey: 'a',
|
|
48
|
+
keyMap,
|
|
49
|
+
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
KeyMap.bind(instance.keyMap);
|
|
53
|
+
dispatchEvent('a', {});
|
|
54
|
+
expect(called).toBeFalsy();
|
|
55
|
+
KeyMap.unbind(instance.keyMap);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should init shortcutClick disabled', () => {
|
|
59
|
+
let called = false;
|
|
60
|
+
const method = () => { called = true; };
|
|
61
|
+
const keyMap = {
|
|
62
|
+
a: {
|
|
63
|
+
event: method,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
const instance = new CrudButton({
|
|
67
|
+
name: 'button',
|
|
68
|
+
component: 'tekCrudButton',
|
|
69
|
+
clickShortcutKey: 'a',
|
|
70
|
+
disabled: true,
|
|
71
|
+
keyMap,
|
|
72
|
+
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
KeyMap.bind(instance.keyMap);
|
|
76
|
+
dispatchEvent('a', {});
|
|
77
|
+
expect(called).toBeFalsy();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('parent instanceof CrudForm', () => {
|
|
81
|
+
const instance = new CrudButton({ name: 'button', component: 'tekCrudButton' });
|
|
82
|
+
const crudForm = new CrudForm({ name: 'grid', component: 'CrudForm' });
|
|
83
|
+
instance.parent = crudForm;
|
|
84
|
+
expect(instance.parentIsEditing).toBeFalsy();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('parent instanceof GridEditable', () => {
|
|
88
|
+
const instance = new CrudButton({ name: 'button', component: 'tekCrudButton' });
|
|
89
|
+
const crudForm = new GridEditable({ name: 'grid', component: 'CrudForm' });
|
|
90
|
+
instance.parent = crudForm;
|
|
91
|
+
expect(instance.parentIsEditing).toBeFalsy();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|