Skip to content

Commit e0e5b19

Browse files
authored
Merge pull request #3157 from adumesny/master
dd code coverage
2 parents 44fe4dd + 17a4fe3 commit e0e5b19

File tree

9 files changed

+1265
-24
lines changed

9 files changed

+1265
-24
lines changed

angular/doc/api/base-widget.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ The default implementation automatically assigns input data to component propert
8080

8181
```typescript
8282
deserialize(w: NgGridStackWidget) {
83-
super.deserialize(w); // Call parent for basic setup
84-
83+
super.deserialize(w); // Call parent for basic setup
84+
8585
// Custom initialization logic
8686
if (w.input?.complexData) {
8787
this.processComplexData(w.input.complexData);

angular/doc/api/gridstack.component.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ this.gridComponent.grid.addWidget({x: 0, y: 0, w: 2, h: 1});
127127
new GridstackComponent(elementRef): GridstackComponent;
128128
```
129129

130-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:252](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L252)
130+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:253](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L253)
131131

132132
###### Parameters
133133

@@ -155,7 +155,7 @@ Register a list of Angular components for dynamic creation.
155155

156156
| Parameter | Type | Description |
157157
| ------ | ------ | ------ |
158-
| `typeList` | `Type`\<`Object`\>[] | Array of component types to register |
158+
| `typeList` | `Type`\<`object`\>[] | Array of component types to register |
159159

160160
###### Returns
161161

@@ -184,7 +184,7 @@ Extract the selector string from an Angular component type.
184184

185185
| Parameter | Type | Description |
186186
| ------ | ------ | ------ |
187-
| `type` | `Type`\<`Object`\> | The component type to get selector from |
187+
| `type` | `Type`\<`object`\> | The component type to get selector from |
188188

189189
###### Returns
190190

@@ -198,7 +198,7 @@ The component's selector string
198198
ngOnInit(): void;
199199
```
200200

201-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:266](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L266)
201+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:267](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L267)
202202

203203
A callback method that is invoked immediately after the
204204
default change detector has checked the directive's
@@ -222,7 +222,7 @@ OnInit.ngOnInit
222222
ngAfterContentInit(): void;
223223
```
224224

225-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:276](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L276)
225+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:277](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L277)
226226

227227
wait until after all DOM is ready to init gridstack children (after angular ngFor and sub-components run first)
228228

@@ -242,7 +242,7 @@ AfterContentInit.ngAfterContentInit
242242
ngOnDestroy(): void;
243243
```
244244

245-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:284](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L284)
245+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:285](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L285)
246246

247247
A callback method that performs custom clean-up, invoked immediately
248248
before a directive, pipe, or service instance is destroyed.
@@ -263,7 +263,7 @@ OnDestroy.ngOnDestroy
263263
updateAll(): void;
264264
```
265265

266-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:298](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L298)
266+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:299](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L299)
267267

268268
called when the TEMPLATE (not recommended) list of items changes - get a list of nodes and
269269
update the layout accordingly (which will take care of adding/removing items changed by Angular)
@@ -278,7 +278,7 @@ update the layout accordingly (which will take care of adding/removing items cha
278278
checkEmpty(): void;
279279
```
280280

281-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:309](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L309)
281+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:310](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L310)
282282

283283
check if the grid is empty, if so show alternative content
284284

@@ -292,7 +292,7 @@ check if the grid is empty, if so show alternative content
292292
protected hookEvents(grid?): void;
293293
```
294294
295-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:315](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L315)
295+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:316](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L316)
296296
297297
get all known events as easy to use Outputs for convenience
298298
@@ -312,7 +312,7 @@ get all known events as easy to use Outputs for convenience
312312
protected unhookEvents(grid?): void;
313313
```
314314
315-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:342](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L342)
315+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:343](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L343)
316316
317317
###### Parameters
318318
@@ -345,11 +345,11 @@ Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:342](https://gi
345345
| <a id="resizestopcb"></a> `resizeStopCB` | `public` | `EventEmitter`\<[`elementCB`](#elementcb)\> | `undefined` | Emitted when widget resize stops | [angular/projects/lib/src/lib/gridstack.component.ts:184](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L184) |
346346
| <a id="ref"></a> `ref` | `public` | \| `undefined` \| `ComponentRef`\<[`GridstackComponent`](#gridstackcomponent)\> | `undefined` | Component reference for dynamic component removal. Used internally when this component is created dynamically. | [angular/projects/lib/src/lib/gridstack.component.ts:207](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L207) |
347347
| <a id="selectortotype-1"></a> `selectorToType` | `static` | [`SelectorToType`](#selectortotype) | `{}` | Mapping of component selectors to their types for dynamic creation. This enables dynamic component instantiation from string selectors. Angular doesn't provide public access to this mapping, so we maintain our own. **Example** `GridstackComponent.addComponentToSelectorType([MyWidgetComponent]);` | [angular/projects/lib/src/lib/gridstack.component.ts:220](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L220) |
348-
| <a id="_options"></a> `_options?` | `protected` | `GridStackOptions` | `undefined` | - | [angular/projects/lib/src/lib/gridstack.component.ts:247](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L247) |
349-
| <a id="_grid"></a> `_grid?` | `protected` | `GridStack` | `undefined` | - | [angular/projects/lib/src/lib/gridstack.component.ts:248](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L248) |
350-
| <a id="_sub"></a> `_sub` | `protected` | `undefined` \| `Subscription` | `undefined` | - | [angular/projects/lib/src/lib/gridstack.component.ts:249](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L249) |
351-
| <a id="loaded"></a> `loaded?` | `protected` | `boolean` | `undefined` | - | [angular/projects/lib/src/lib/gridstack.component.ts:250](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L250) |
352-
| <a id="elementref"></a> `elementRef` | `readonly` | `ElementRef`\<[`GridCompHTMLElement`](#gridcomphtmlelement)\> | `undefined` | - | [angular/projects/lib/src/lib/gridstack.component.ts:252](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L252) |
348+
| <a id="_options"></a> `_options?` | `protected` | `GridStackOptions` | `undefined` | - | [angular/projects/lib/src/lib/gridstack.component.ts:248](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L248) |
349+
| <a id="_grid"></a> `_grid?` | `protected` | `GridStack` | `undefined` | - | [angular/projects/lib/src/lib/gridstack.component.ts:249](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L249) |
350+
| <a id="_sub"></a> `_sub` | `protected` | `undefined` \| `Subscription` | `undefined` | - | [angular/projects/lib/src/lib/gridstack.component.ts:250](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L250) |
351+
| <a id="loaded"></a> `loaded?` | `protected` | `boolean` | `undefined` | - | [angular/projects/lib/src/lib/gridstack.component.ts:251](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L251) |
352+
| <a id="elementref"></a> `elementRef` | `readonly` | `ElementRef`\<[`GridCompHTMLElement`](#gridcomphtmlelement)\> | `undefined` | - | [angular/projects/lib/src/lib/gridstack.component.ts:253](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L253) |
353353
354354
## Interfaces
355355
@@ -3095,7 +3095,7 @@ function gsCreateNgComponents(
30953095
isGrid): undefined | HTMLElement;
30963096
```
30973097
3098-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:353](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L353)
3098+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:354](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L354)
30993099
31003100
can be used when a new item needs to be created, which we do as a Angular component, or deleted (skip)
31013101
@@ -3120,7 +3120,7 @@ can be used when a new item needs to be created, which we do as a Angular compon
31203120
function gsSaveAdditionalNgInfo(n, w): void;
31213121
```
31223122
3123-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:437](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L437)
3123+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:439](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L439)
31243124
31253125
called for each item in the grid - check if additional information needs to be saved.
31263126
Note: since this is options minus gridstack protected members using Utils.removeInternalForSave(),
@@ -3146,7 +3146,7 @@ using BaseWidget.serialize()
31463146
function gsUpdateNgComponents(n): void;
31473147
```
31483148
3149-
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:456](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L456)
3149+
Defined in: [angular/projects/lib/src/lib/gridstack.component.ts:458](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/gridstack.component.ts#L458)
31503150
31513151
track when widgeta re updated (rather than created) to make sure we de-serialize them as well
31523152
@@ -3296,5 +3296,5 @@ Used for dynamic component creation based on widget selectors.
32963296
#### Index Signature
32973297
32983298
```ts
3299-
[key: string]: Type<Object>
3299+
[key: string]: Type<object>
33003300
```

angular/doc/api/types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Supports Angular-specific widget definitions and nested grids.
6868
type NgCompInputs = object;
6969
```
7070

71-
Defined in: [angular/projects/lib/src/lib/types.ts:54](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/types.ts#L54)
71+
Defined in: [angular/projects/lib/src/lib/types.ts:55](https://github.com/adumesny/gridstack.js/blob/master/angular/projects/lib/src/lib/types.ts#L55)
7272

7373
Type for component input data serialization.
7474
Maps @Input() property names to their values for widget persistence.

spec/dd-base-impl-spec.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { DDBaseImplement } from '../src/dd-base-impl';
2+
3+
describe('DDBaseImplement', () => {
4+
let baseImpl: DDBaseImplement;
5+
6+
beforeEach(() => {
7+
baseImpl = new DDBaseImplement();
8+
});
9+
10+
describe('constructor', () => {
11+
it('should create instance with undefined disabled state', () => {
12+
expect(baseImpl.disabled).toBeUndefined();
13+
});
14+
});
15+
16+
describe('enable/disable', () => {
17+
it('should enable when disabled', () => {
18+
baseImpl.disable();
19+
expect(baseImpl.disabled).toBe(true);
20+
21+
baseImpl.enable();
22+
23+
expect(baseImpl.disabled).toBe(false);
24+
});
25+
26+
it('should disable when enabled', () => {
27+
baseImpl.enable();
28+
expect(baseImpl.disabled).toBe(false);
29+
30+
baseImpl.disable();
31+
32+
expect(baseImpl.disabled).toBe(true);
33+
});
34+
35+
it('should return undefined (no chaining)', () => {
36+
expect(baseImpl.enable()).toBeUndefined();
37+
expect(baseImpl.disable()).toBeUndefined();
38+
});
39+
});
40+
41+
describe('destroy', () => {
42+
it('should clean up event register', () => {
43+
baseImpl.enable();
44+
baseImpl.on('test', () => {});
45+
46+
baseImpl.destroy();
47+
48+
// Should not throw when trying to trigger events after destroy
49+
expect(() => baseImpl.triggerEvent('test', new Event('test'))).not.toThrow();
50+
});
51+
});
52+
53+
describe('event handling', () => {
54+
beforeEach(() => {
55+
baseImpl.enable(); // Need to enable for events to trigger
56+
});
57+
58+
it('should handle on/off events', () => {
59+
const callback = vi.fn();
60+
61+
baseImpl.on('test', callback);
62+
baseImpl.triggerEvent('test', new Event('test'));
63+
64+
expect(callback).toHaveBeenCalled();
65+
});
66+
67+
it('should remove event listeners with off', () => {
68+
const callback = vi.fn();
69+
70+
baseImpl.on('test', callback);
71+
baseImpl.off('test');
72+
baseImpl.triggerEvent('test', new Event('test'));
73+
74+
expect(callback).not.toHaveBeenCalled();
75+
});
76+
77+
it('should only keep last listener for same event', () => {
78+
const callback1 = vi.fn();
79+
const callback2 = vi.fn();
80+
81+
baseImpl.on('test', callback1);
82+
baseImpl.on('test', callback2); // This overwrites callback1
83+
baseImpl.triggerEvent('test', new Event('test'));
84+
85+
expect(callback1).not.toHaveBeenCalled();
86+
expect(callback2).toHaveBeenCalled();
87+
});
88+
89+
it('should not trigger events when disabled', () => {
90+
const callback = vi.fn();
91+
92+
baseImpl.on('test', callback);
93+
baseImpl.disable();
94+
baseImpl.triggerEvent('test', new Event('test'));
95+
96+
expect(callback).not.toHaveBeenCalled();
97+
});
98+
});
99+
});

0 commit comments

Comments
 (0)