@zeedhi/teknisa-components-common 1.107.1 → 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.
Files changed (77) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +7 -7
  3. package/coverage/clover.xml +772 -692
  4. package/coverage/coverage-final.json +47 -47
  5. package/coverage/lcov-report/index.html +15 -15
  6. package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +2 -2
  7. package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +2 -2
  8. package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +7 -7
  9. package/coverage/lcov-report/tests/__helpers__/index.html +1 -1
  10. package/coverage/lcov-report/tests/__helpers__/index.ts.html +1 -1
  11. package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +1 -1
  12. package/coverage/lcov.info +1459 -1275
  13. package/dist/tek-components-common.esm.js +375 -252
  14. package/dist/tek-components-common.umd.js +375 -252
  15. package/jest.config.js +1 -1
  16. package/package.json +2 -2
  17. package/tests/__helpers__/component-event-helper.ts +5 -5
  18. package/tests/__helpers__/flush-promises-helper.ts +3 -3
  19. package/tests/__helpers__/get-child-helper.ts +27 -27
  20. package/tests/__helpers__/index.ts +3 -3
  21. package/tests/__helpers__/mock-created-helper.ts +12 -12
  22. package/tests/__mocks__/@zeedhi/core/i18n.js +74 -74
  23. package/tests/__mocks__/@zeedhi/core.js +4 -4
  24. package/tests/unit/components/crud/crud-add-button.spec.ts +56 -56
  25. package/tests/unit/components/crud/crud-button.spec.ts +94 -94
  26. package/tests/unit/components/crud/crud-cancel-button.spec.ts +91 -91
  27. package/tests/unit/components/crud/crud-delete-button.spec.ts +122 -122
  28. package/tests/unit/components/crud/crud-form.spec.ts +165 -165
  29. package/tests/unit/components/crud/crud-save-button.spec.ts +118 -118
  30. package/tests/unit/components/tek-breadcrumb-header/tek-breadcrumb-header.spec.ts +42 -42
  31. package/tests/unit/components/tek-card-title/CardTitle.spec.ts +34 -34
  32. package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +470 -470
  33. package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +364 -364
  34. package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +112 -112
  35. package/tests/unit/components/tek-grid/filter-helper.spec.ts +148 -148
  36. package/tests/unit/components/tek-grid/grid-column.spec.ts +270 -270
  37. package/tests/unit/components/tek-grid/grid-columns-button.spec.ts +195 -195
  38. package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +967 -967
  39. package/tests/unit/components/tek-grid/grid.spec.ts +3340 -3116
  40. package/tests/unit/components/tek-grid/layout_options.spec.ts +980 -980
  41. package/tests/unit/components/tek-image/Image.spec.ts +67 -67
  42. package/tests/unit/components/tek-iterable-carousel/iterable-carousel.spec.ts +37 -37
  43. package/tests/unit/components/tek-iterable-component-render/iterable-component-render.spec.ts +200 -200
  44. package/tests/unit/components/tek-loading/Loading.spec.ts +30 -30
  45. package/tests/unit/components/tek-notifications/notifications.spec.ts +201 -201
  46. package/tests/unit/components/tek-product-card/product-card.spec.ts +61 -61
  47. package/tests/unit/components/tek-user-info/TekUserInfoContoller.spec.ts +220 -220
  48. package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +86 -86
  49. package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +430 -430
  50. package/tests/unit/components/tree-grid/tree-grid.spec.ts +776 -776
  51. package/tests/unit/utils/grid-base/delete-rows-error.spec.ts +24 -0
  52. package/tests/unit/utils/grid-base/export-options/button-option.spec.ts +44 -44
  53. package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +135 -135
  54. package/tests/unit/utils/grid-base/grid-controller.spec.ts +267 -174
  55. package/tests/unit/utils/report-filter/report-filter.spec.ts +66 -66
  56. package/tsconfig.eslint.json +8 -8
  57. package/types/components/tek-datasource/memory-datasource.d.ts +2 -4
  58. package/types/components/tek-datasource/rest-datasource.d.ts +6 -3
  59. package/types/components/tek-grid/grid.d.ts +50 -6
  60. package/types/components/tek-grid/interfaces.d.ts +5 -3
  61. package/types/components/tek-tree-grid/tree-grid.d.ts +5 -1
  62. package/types/utils/grid-base/grid-base.d.ts +12 -229
  63. package/types/utils/grid-base/grid-controller.d.ts +1 -3
  64. package/types/components/tek-ag-grid/default-icons.d.ts +0 -53
  65. package/types/components/tek-ag-grid/interfaces.d.ts +0 -9
  66. package/types/components/tek-ag-grid/tek-ag-grid.d.ts +0 -35
  67. package/types/components/tek-datasource/datasource.d.ts +0 -94
  68. package/types/components/tek-grid/default-icons.d.ts +0 -53
  69. package/types/components/tek-grid/filter-dynamic-values.d.ts +0 -9
  70. package/types/components/tek-grid/grid-controller.d.ts +0 -19
  71. package/types/components/tek-grid/grid_column.d.ts +0 -14
  72. package/types/components/tek-grid/grid_controller.d.ts +0 -15
  73. package/types/components/tek-grid/tek-grid.d.ts +0 -35
  74. package/types/components/tek-login/interfaces.d.ts +0 -3
  75. package/types/components/tek-login/login-children.d.ts +0 -3
  76. package/types/components/tek-login/login.d.ts +0 -58
  77. 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.107.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": "ce6aeb7a4ebfca43f9ecb85ed411037f6032d214"
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
+ });