@imihai/angular-datetime-picker 22.0.0 → 22.0.8

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 (113) hide show
  1. package/assets/style/picker.min.css +1 -0
  2. package/fesm2022/imihai-angular-datetime-picker.mjs +5843 -0
  3. package/fesm2022/imihai-angular-datetime-picker.mjs.map +1 -0
  4. package/imihai-angular-datetime-picker-22.0.8.tgz +0 -0
  5. package/package.json +34 -77
  6. package/types/imihai-angular-datetime-picker.d.ts +2193 -0
  7. package/.browserslistrc +0 -9
  8. package/.editorconfig +0 -13
  9. package/.eslintrc.js +0 -208
  10. package/.github/workflows/ci_test.yml +0 -35
  11. package/.prettierrc +0 -2
  12. package/.travis.yml +0 -16
  13. package/angular.json +0 -221
  14. package/e2e/protractor.conf.js +0 -28
  15. package/e2e/src/app.e2e-spec.ts +0 -14
  16. package/e2e/src/app.po.ts +0 -11
  17. package/e2e/tsconfig.e2e.json +0 -13
  18. package/projects/picker/karma.conf.js +0 -62
  19. package/projects/picker/ng-package.json +0 -7
  20. package/projects/picker/package.json +0 -23
  21. package/projects/picker/src/lib/date-time/adapter/date-time-adapter.class.ts +0 -313
  22. package/projects/picker/src/lib/date-time/adapter/date-time-format.class.ts +0 -18
  23. package/projects/picker/src/lib/date-time/adapter/luxon-date-time-adapter.class.ts +0 -307
  24. package/projects/picker/src/lib/date-time/adapter/luxon-date-time-format.class.ts +0 -11
  25. package/projects/picker/src/lib/date-time/adapter/luxon-date-time.module.ts +0 -31
  26. package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time-adapter.class.ts +0 -356
  27. package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time-format.class.ts +0 -14
  28. package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time.module.ts +0 -26
  29. package/projects/picker/src/lib/date-time/calendar-body.component.html +0 -38
  30. package/projects/picker/src/lib/date-time/calendar-body.component.scss +0 -0
  31. package/projects/picker/src/lib/date-time/calendar-body.component.spec.ts +0 -120
  32. package/projects/picker/src/lib/date-time/calendar-body.component.ts +0 -190
  33. package/projects/picker/src/lib/date-time/calendar-month-view.component.html +0 -47
  34. package/projects/picker/src/lib/date-time/calendar-month-view.component.scss +0 -16
  35. package/projects/picker/src/lib/date-time/calendar-month-view.component.spec.ts +0 -394
  36. package/projects/picker/src/lib/date-time/calendar-month-view.component.ts +0 -705
  37. package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.html +0 -44
  38. package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.scss +0 -0
  39. package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.spec.ts +0 -343
  40. package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.ts +0 -465
  41. package/projects/picker/src/lib/date-time/calendar-year-view.component.html +0 -16
  42. package/projects/picker/src/lib/date-time/calendar-year-view.component.scss +0 -0
  43. package/projects/picker/src/lib/date-time/calendar-year-view.component.spec.ts +0 -381
  44. package/projects/picker/src/lib/date-time/calendar-year-view.component.ts +0 -549
  45. package/projects/picker/src/lib/date-time/calendar.component.html +0 -169
  46. package/projects/picker/src/lib/date-time/calendar.component.scss +0 -0
  47. package/projects/picker/src/lib/date-time/calendar.component.spec.ts +0 -592
  48. package/projects/picker/src/lib/date-time/calendar.component.ts +0 -496
  49. package/projects/picker/src/lib/date-time/date-time-inline.component.html +0 -1
  50. package/projects/picker/src/lib/date-time/date-time-inline.component.scss +0 -4
  51. package/projects/picker/src/lib/date-time/date-time-inline.component.ts +0 -365
  52. package/projects/picker/src/lib/date-time/date-time-picker-animation-event.ts +0 -4
  53. package/projects/picker/src/lib/date-time/date-time-picker-container.component.html +0 -126
  54. package/projects/picker/src/lib/date-time/date-time-picker-container.component.scss +0 -0
  55. package/projects/picker/src/lib/date-time/date-time-picker-container.component.ts +0 -631
  56. package/projects/picker/src/lib/date-time/date-time-picker-input.directive.ts +0 -851
  57. package/projects/picker/src/lib/date-time/date-time-picker-intl.service.ts +0 -76
  58. package/projects/picker/src/lib/date-time/date-time-picker-trigger.directive.ts +0 -88
  59. package/projects/picker/src/lib/date-time/date-time-picker.component.html +0 -0
  60. package/projects/picker/src/lib/date-time/date-time-picker.component.scss +0 -0
  61. package/projects/picker/src/lib/date-time/date-time-picker.component.spec.ts +0 -2648
  62. package/projects/picker/src/lib/date-time/date-time-picker.component.ts +0 -731
  63. package/projects/picker/src/lib/date-time/date-time.class.ts +0 -256
  64. package/projects/picker/src/lib/date-time/date-time.module.ts +0 -61
  65. package/projects/picker/src/lib/date-time/numberedFixLen.pipe.ts +0 -28
  66. package/projects/picker/src/lib/date-time/options-provider.ts +0 -44
  67. package/projects/picker/src/lib/date-time/timer-box.component.html +0 -79
  68. package/projects/picker/src/lib/date-time/timer-box.component.scss +0 -0
  69. package/projects/picker/src/lib/date-time/timer-box.component.ts +0 -175
  70. package/projects/picker/src/lib/date-time/timer.component.html +0 -58
  71. package/projects/picker/src/lib/date-time/timer.component.scss +0 -0
  72. package/projects/picker/src/lib/date-time/timer.component.spec.ts +0 -399
  73. package/projects/picker/src/lib/date-time/timer.component.ts +0 -371
  74. package/projects/picker/src/lib/dialog/dialog-config.class.ts +0 -220
  75. package/projects/picker/src/lib/dialog/dialog-container.component.html +0 -1
  76. package/projects/picker/src/lib/dialog/dialog-container.component.scss +0 -0
  77. package/projects/picker/src/lib/dialog/dialog-container.component.ts +0 -231
  78. package/projects/picker/src/lib/dialog/dialog-ref.class.ts +0 -178
  79. package/projects/picker/src/lib/dialog/dialog.module.ts +0 -25
  80. package/projects/picker/src/lib/dialog/dialog.service.ts +0 -353
  81. package/projects/picker/src/lib/utils/array.utils.ts +0 -12
  82. package/projects/picker/src/lib/utils/constants.ts +0 -59
  83. package/projects/picker/src/lib/utils/date.utils.ts +0 -97
  84. package/projects/picker/src/lib/utils/index.ts +0 -5
  85. package/projects/picker/src/lib/utils/object.utils.ts +0 -29
  86. package/projects/picker/src/public_api.ts +0 -56
  87. package/projects/picker/src/sass/picker.scss +0 -743
  88. package/projects/picker/src/test-helpers.ts +0 -125
  89. package/projects/picker/src/test.ts +0 -52
  90. package/projects/picker/tsconfig.lib.json +0 -19
  91. package/projects/picker/tsconfig.lib.prod.json +0 -7
  92. package/projects/picker/tsconfig.spec.json +0 -17
  93. package/projects/picker/tslint.json +0 -8
  94. package/src/app/app.component.html +0 -77
  95. package/src/app/app.component.scss +0 -32
  96. package/src/app/app.component.spec.ts +0 -16
  97. package/src/app/app.component.ts +0 -35
  98. package/src/assets/.gitkeep +0 -0
  99. package/src/environments/environment.prod.ts +0 -3
  100. package/src/environments/environment.ts +0 -16
  101. package/src/favicon.ico +0 -0
  102. package/src/index.html +0 -14
  103. package/src/karma.conf.js +0 -31
  104. package/src/main.ts +0 -16
  105. package/src/polyfills.ts +0 -53
  106. package/src/styles.scss +0 -7
  107. package/src/test.ts +0 -50
  108. package/src/tsconfig.app.json +0 -16
  109. package/src/tsconfig.spec.json +0 -18
  110. package/src/tslint.json +0 -17
  111. package/tsconfig.base.json +0 -31
  112. package/tsconfig.json +0 -30
  113. package/tslint.json +0 -130
@@ -1,2648 +0,0 @@
1
- /**
2
- * date-time-picker.component.spec
3
- */
4
-
5
- import { OwlDateTimeComponent } from './date-time-picker.component';
6
- import {
7
- ComponentFixture,
8
- fakeAsync,
9
- flush,
10
- inject,
11
- TestBed
12
- } from '@angular/core/testing';
13
- import {
14
- Component,
15
- FactoryProvider,
16
- Type,
17
- ValueProvider,
18
- ViewChild
19
- } from '@angular/core';
20
- import { OwlDateTimeInputDirective } from './date-time-picker-input.directive';
21
- import { UntypedFormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
22
- import { OwlDateTimeModule } from './date-time.module';
23
- import { OverlayContainer } from '@angular/cdk/overlay';
24
- import { OwlNativeDateTimeModule } from './adapter/native-date-time.module';
25
- import {
26
- dispatchKeyboardEvent,
27
- dispatchMouseEvent,
28
- createKeyboardEvent,
29
- dispatchEvent,
30
- dispatchFakeEvent
31
- } from '../../test-helpers';
32
- import { ENTER, ESCAPE, RIGHT_ARROW, UP_ARROW } from '@angular/cdk/keycodes';
33
- import { By } from '@angular/platform-browser';
34
- import { OwlDateTimeContainerComponent } from './date-time-picker-container.component';
35
- import { OwlDateTimeTriggerDirective } from './date-time-picker-trigger.directive';
36
- import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
37
- import {DateView} from './date-time.class';
38
-
39
- const JAN = 0,
40
- FEB = 1,
41
- MAR = 2,
42
- APR = 3,
43
- MAY = 4,
44
- JUN = 5,
45
- JUL = 6,
46
- AUG = 7,
47
- SEP = 8,
48
- OCT = 9,
49
- NOV = 10,
50
- DEC = 11;
51
-
52
- describe('OwlDateTimeComponent', () => {
53
- const SUPPORTS_INTL = typeof Intl !== 'undefined';
54
-
55
- // Creates a test component fixture.
56
- function createComponent(
57
- component: Type<any>,
58
- imports: Type<any>[] = [],
59
- providers: (FactoryProvider | ValueProvider)[] = [],
60
- entryComponents: Type<any>[] = []
61
- ): ComponentFixture<any> {
62
- TestBed.configureTestingModule({
63
- imports: [
64
- FormsModule,
65
- OwlDateTimeModule,
66
- ReactiveFormsModule,
67
- ...imports
68
- ],
69
- providers,
70
- declarations: [component, ...entryComponents],
71
- animationsEnabled: true // required for picker container open/close animations
72
- });
73
-
74
- TestBed.overrideModule(BrowserDynamicTestingModule, {
75
-
76
- }).compileComponents();
77
-
78
- return TestBed.createComponent(component);
79
- }
80
-
81
- beforeEach(() => {
82
- spyOn(HTMLElement.prototype, 'animate').and.callFake(() => {
83
- return {
84
- finished: new Promise(resolve => setTimeout(resolve, 100)), // finish animation after 100ms
85
- play: () => {},
86
- cancel: () => {}
87
- } as any;
88
- });
89
- });
90
-
91
- afterEach(inject([OverlayContainer], (container: OverlayContainer) => {
92
- container.ngOnDestroy();
93
- }));
94
-
95
- describe('with OwlNativeDateTimeModule', () => {
96
- describe('standard DateTimePicker', () => {
97
- let fixture: ComponentFixture<StandardDateTimePickerComponent>;
98
- let testComponent: StandardDateTimePickerComponent;
99
- let containerElement: HTMLElement;
100
-
101
- beforeEach(fakeAsync(() => {
102
- fixture = createComponent(StandardDateTimePickerComponent, [
103
- OwlNativeDateTimeModule
104
- ]);
105
- fixture.detectChanges();
106
- testComponent = fixture.componentInstance;
107
- }));
108
-
109
- afterEach(fakeAsync(() => {
110
- testComponent.dateTimePicker.close();
111
- fixture.detectChanges();
112
- flush();
113
- }));
114
-
115
- it('should initialize with correct value shown in input', () => {
116
- if (SUPPORTS_INTL) {
117
- expect(
118
- fixture.nativeElement.querySelector('input').value
119
- ).toBe('1/1/2020, 12:00 AM');
120
- }
121
- });
122
-
123
- it('should open popup when pickerMode is "popup"', () => {
124
- expect(
125
- document.querySelector('.cdk-overlay-pane.owl-dt-popup')
126
- ).toBeNull();
127
-
128
- testComponent.dateTimePicker.open();
129
- fixture.detectChanges();
130
-
131
- expect(
132
- document.querySelector('.cdk-overlay-pane.owl-dt-popup')
133
- ).not.toBeNull();
134
- });
135
-
136
- it('should open dialog when pickerMode is "dialog"', () => {
137
- testComponent.pickerMode = 'dialog';
138
- fixture.detectChanges();
139
-
140
- expect(
141
- document.querySelector(
142
- '.owl-dt-dialog owl-dialog-container'
143
- )
144
- ).toBeNull();
145
-
146
- testComponent.dateTimePicker.open();
147
- fixture.detectChanges();
148
-
149
- expect(
150
- document.querySelector(
151
- '.owl-dt-dialog owl-dialog-container'
152
- )
153
- ).not.toBeNull();
154
- });
155
-
156
- it('should open dateTimePicker if opened input is set to true', fakeAsync(() => {
157
- testComponent.opened = true;
158
- fixture.detectChanges();
159
- flush();
160
-
161
- expect(
162
- document.querySelector('.owl-dt-container')
163
- ).not.toBeNull();
164
-
165
- testComponent.opened = false;
166
- fixture.detectChanges();
167
- flush();
168
-
169
- expect(document.querySelector('.owl-dt-container')).toBeNull();
170
- }));
171
-
172
- it('should NOT open dateTimePicker if it is disabled', () => {
173
- testComponent.disabled = true;
174
- fixture.detectChanges();
175
-
176
- expect(document.querySelector('.cdk-overlay-pane')).toBeNull();
177
- expect(
178
- document.querySelector('owl-date-time-container')
179
- ).toBeNull();
180
-
181
- testComponent.dateTimePicker.open();
182
- fixture.detectChanges();
183
-
184
- expect(document.querySelector('.cdk-overlay-pane')).toBeNull();
185
- expect(
186
- document.querySelector('owl-date-time-container')
187
- ).toBeNull();
188
- });
189
-
190
- it('disabled dateTimePicker input should open the picker panel if dateTimePicker is enabled', () => {
191
- testComponent.dateTimePicker.disabled = false;
192
- testComponent.dateTimePickerInput.disabled = true;
193
- fixture.detectChanges();
194
-
195
- expect(document.querySelector('.cdk-overlay-pane')).toBeNull();
196
-
197
- testComponent.dateTimePicker.open();
198
- fixture.detectChanges();
199
-
200
- expect(
201
- document.querySelector('.cdk-overlay-pane')
202
- ).not.toBeNull();
203
- });
204
-
205
- it('should close popup when fn close is called', fakeAsync(() => {
206
- testComponent.dateTimePicker.open();
207
- fixture.detectChanges();
208
- flush();
209
-
210
- const popup = document.querySelector('.cdk-overlay-pane');
211
- expect(popup).not.toBeNull();
212
- expect(
213
- parseInt(getComputedStyle(popup).height, 10)
214
- ).not.toBe(0);
215
-
216
- testComponent.dateTimePicker.close();
217
- fixture.detectChanges();
218
- flush();
219
-
220
- const newHeight = getComputedStyle(popup).height;
221
- expect(newHeight).toBe('0px');
222
- }));
223
-
224
- it('should close the popup when pressing ESCAPE', fakeAsync(() => {
225
- testComponent.dateTimePicker.open();
226
- fixture.detectChanges();
227
- flush();
228
-
229
- expect(testComponent.dateTimePicker.opened).toBe(
230
- true,
231
- 'Expected dateTimePicker to be open.'
232
- );
233
-
234
- dispatchKeyboardEvent(document.body, 'keydown', ESCAPE);
235
- fixture.detectChanges();
236
- flush();
237
-
238
- expect(testComponent.dateTimePicker.opened).toBe(
239
- false,
240
- 'Expected dateTimePicker to be closed.'
241
- );
242
- }));
243
-
244
- it('should close dialog when fn close is called', fakeAsync(() => {
245
- testComponent.pickerMode = 'dialog';
246
- fixture.detectChanges();
247
-
248
- testComponent.dateTimePicker.open();
249
- fixture.detectChanges();
250
- flush();
251
-
252
- expect(
253
- document.querySelector('owl-dialog-container')
254
- ).not.toBeNull();
255
-
256
- testComponent.dateTimePicker.close();
257
- fixture.detectChanges();
258
- flush();
259
-
260
- expect(
261
- document.querySelector('owl-dialog-container')
262
- ).toBeNull();
263
- }));
264
-
265
- it('should close popup panel when cancel button clicked', fakeAsync(() => {
266
- testComponent.dateTimePicker.open();
267
- fixture.detectChanges();
268
- flush();
269
- expect(testComponent.dateTimePicker.opened).toBe(
270
- true,
271
- 'Expected dateTimePicker to be opened.'
272
- );
273
-
274
- const containerDebugElement = fixture.debugElement.query(
275
- By.directive(OwlDateTimeContainerComponent)
276
- );
277
- containerElement = containerDebugElement.nativeElement;
278
-
279
- const btns = containerElement.querySelectorAll(
280
- '.owl-dt-container-control-button'
281
- );
282
- dispatchMouseEvent(btns[0], 'click'); // 'Cancel' button
283
- fixture.detectChanges();
284
- flush();
285
-
286
- expect(testComponent.dateTimePicker.opened).toBe(
287
- false,
288
- 'Expected dateTimePicker to be closed.'
289
- );
290
- }));
291
-
292
- it('should close popup panel and not update input value when cancel button clicked', fakeAsync(() => {
293
- testComponent.dateTimePicker.open();
294
- fixture.detectChanges();
295
- flush();
296
- expect(testComponent.dateTimePicker.opened).toBe(
297
- true,
298
- 'Expected dateTimePicker to be opened.'
299
- );
300
-
301
- const containerDebugElement = fixture.debugElement.query(
302
- By.directive(OwlDateTimeContainerComponent)
303
- );
304
- containerElement = containerDebugElement.nativeElement;
305
-
306
- const monthCell = containerElement.querySelector(
307
- '[aria-label="January 2, 2020"]'
308
- );
309
- (monthCell as HTMLElement).click();
310
- fixture.detectChanges();
311
-
312
- const btns = containerElement.querySelectorAll(
313
- '.owl-dt-container-control-button'
314
- );
315
- dispatchMouseEvent(btns[0], 'click'); // 'Cancel' button
316
- fixture.detectChanges();
317
- flush();
318
-
319
- expect(testComponent.dateTimePicker.opened).toBe(
320
- false,
321
- 'Expected dateTimePicker to be closed.'
322
- );
323
- expect(testComponent.dateTimePickerInput.value).toEqual(
324
- new Date(2020, JAN, 1)
325
- ); // not update to clicked value
326
- }));
327
-
328
- it('should update input value to pickerMoment value and close popup panel when set button clicked', fakeAsync(() => {
329
- testComponent.dateTimePicker.open();
330
- fixture.detectChanges();
331
- flush();
332
- expect(testComponent.dateTimePicker.opened).toBe(
333
- true,
334
- 'Expected dateTimePicker to be opened.'
335
- );
336
-
337
- const containerDebugElement = fixture.debugElement.query(
338
- By.directive(OwlDateTimeContainerComponent)
339
- );
340
- containerElement = containerDebugElement.nativeElement;
341
- expect(
342
- containerDebugElement.componentInstance.pickerMoment
343
- ).toEqual(new Date(2020, JAN, 1));
344
-
345
- const btns = containerElement.querySelectorAll(
346
- '.owl-dt-container-control-button'
347
- );
348
- dispatchMouseEvent(btns[1], 'click'); // 'Set' button
349
- fixture.detectChanges();
350
- flush();
351
-
352
- expect(testComponent.dateTimePicker.opened).toBe(
353
- false,
354
- 'Expected dateTimePicker to be closed.'
355
- );
356
- expect(testComponent.dateTimePickerInput.value).toEqual(
357
- new Date(2020, JAN, 1)
358
- );
359
- }));
360
-
361
- it('should update input value to clicked date value and close popup panel when set button clicked', fakeAsync(() => {
362
- testComponent.dateTimePicker.open();
363
- fixture.detectChanges();
364
- flush();
365
- expect(testComponent.dateTimePicker.opened).toBe(
366
- true,
367
- 'Expected dateTimePicker to be opened.'
368
- );
369
-
370
- const containerDebugElement = fixture.debugElement.query(
371
- By.directive(OwlDateTimeContainerComponent)
372
- );
373
- containerElement = containerDebugElement.nativeElement;
374
- expect(
375
- containerDebugElement.componentInstance.pickerMoment
376
- ).toEqual(new Date(2020, JAN, 1));
377
-
378
- const monthCell = containerElement.querySelector(
379
- '[aria-label="January 2, 2020"]'
380
- );
381
- (monthCell as HTMLElement).click();
382
- fixture.detectChanges();
383
-
384
- const btns = containerElement.querySelectorAll(
385
- '.owl-dt-container-control-button'
386
- );
387
- dispatchMouseEvent(btns[1], 'click'); // 'Set' button
388
- fixture.detectChanges();
389
- flush();
390
-
391
- expect(testComponent.dateTimePicker.opened).toBe(
392
- false,
393
- 'Expected dateTimePicker to be closed.'
394
- );
395
- expect(testComponent.dateTimePickerInput.value).toEqual(
396
- new Date(2020, JAN, 2)
397
- );
398
- }));
399
-
400
- it('should set startAt fallback to input value', () => {
401
- expect(testComponent.dateTimePicker.startAt).toEqual(
402
- new Date(2020, JAN, 1)
403
- );
404
- });
405
-
406
- it('input should aria-owns owl-date-time-container after opened in popup mode', fakeAsync(() => {
407
- const inputEl = fixture.debugElement.query(By.css('input'))
408
- .nativeElement;
409
- expect(inputEl.getAttribute('aria-owns')).toBeNull();
410
-
411
- testComponent.dateTimePicker.open();
412
- fixture.detectChanges();
413
- flush();
414
- fixture.detectChanges();
415
-
416
- const ownedElementId = inputEl.getAttribute('aria-owns');
417
- expect(ownedElementId).not.toBeNull();
418
-
419
- const ownedElement = document.getElementById(ownedElementId);
420
- expect(ownedElement).not.toBeNull();
421
- expect((ownedElement as Element).tagName.toLowerCase()).toBe(
422
- 'owl-date-time-container'
423
- );
424
- }));
425
-
426
- it('input should aria-owns owl-date-time-container after opened in dialog mode', fakeAsync(() => {
427
- testComponent.pickerMode = 'dialog';
428
- fixture.detectChanges();
429
-
430
- const inputEl = fixture.debugElement.query(By.css('input'))
431
- .nativeElement;
432
- expect(inputEl.getAttribute('aria-owns')).toBeNull();
433
-
434
- testComponent.dateTimePicker.open();
435
- fixture.detectChanges();
436
- flush();
437
- fixture.detectChanges();
438
-
439
- const ownedElementId = inputEl.getAttribute('aria-owns');
440
- expect(ownedElementId).not.toBeNull();
441
-
442
- const ownedElement = document.getElementById(ownedElementId);
443
- expect(ownedElement).not.toBeNull();
444
- expect((ownedElement as Element).tagName.toLowerCase()).toBe(
445
- 'owl-date-time-container'
446
- );
447
- }));
448
-
449
- it('should close the picker popup panel using ALT + UP_ARROW', fakeAsync(() => {
450
- testComponent.dateTimePicker.open();
451
- fixture.detectChanges();
452
- flush();
453
-
454
- expect(testComponent.dateTimePicker.opened).toBe(true);
455
-
456
- const event = createKeyboardEvent('keydown', UP_ARROW);
457
- Object.defineProperty(event, 'altKey', { get: () => true });
458
-
459
- dispatchEvent(document.body, event);
460
- fixture.detectChanges();
461
- flush();
462
-
463
- expect(testComponent.dateTimePicker.opened).toBe(false);
464
- }));
465
-
466
- describe('with only calendar', () => {
467
- beforeEach(() => {
468
- testComponent.pickerType = 'calendar';
469
- fixture.detectChanges();
470
- });
471
-
472
- it('should initialize with correct value shown in input', () => {
473
- if (SUPPORTS_INTL) {
474
- expect(
475
- fixture.nativeElement.querySelector('input').value
476
- ).toBe('1/1/2020');
477
- }
478
- });
479
-
480
- it('should NOT have any container control button', fakeAsync(() => {
481
- testComponent.dateTimePicker.open();
482
- fixture.detectChanges();
483
- flush();
484
- expect(testComponent.dateTimePicker.opened).toBe(
485
- true,
486
- 'Expected dateTimePicker to be opened.'
487
- );
488
-
489
- const containerDebugElement = fixture.debugElement.query(
490
- By.directive(OwlDateTimeContainerComponent)
491
- );
492
- containerElement = containerDebugElement.nativeElement;
493
- const btns = containerElement.querySelectorAll(
494
- '.owl-dt-container-control-button'
495
- );
496
-
497
- expect(btns.length).toBe(0);
498
- }));
499
-
500
- it('should update input value to clicked date value and close popup panel when date cell is clicked', fakeAsync(() => {
501
- testComponent.dateTimePicker.open();
502
- fixture.detectChanges();
503
- flush();
504
- expect(testComponent.dateTimePicker.opened).toBe(
505
- true,
506
- 'Expected dateTimePicker to be opened.'
507
- );
508
-
509
- const containerDebugElement = fixture.debugElement.query(
510
- By.directive(OwlDateTimeContainerComponent)
511
- );
512
- containerElement = containerDebugElement.nativeElement;
513
- expect(
514
- containerDebugElement.componentInstance.pickerMoment
515
- ).toEqual(new Date(2020, JAN, 1));
516
-
517
- const dateCell = containerElement.querySelector(
518
- '[aria-label="January 2, 2020"]'
519
- );
520
- dispatchMouseEvent(dateCell, 'click');
521
- fixture.detectChanges();
522
- flush();
523
-
524
- expect(testComponent.dateTimePicker.opened).toBe(
525
- false,
526
- 'Expected dateTimePicker to be closed.'
527
- );
528
- expect(testComponent.dateTimePickerInput.value).toEqual(
529
- new Date(2020, JAN, 2)
530
- );
531
- }));
532
-
533
- it('should update input value to clicked date value and close popup panel when date cell is clicked via pressing enter',
534
- fakeAsync(() => {
535
- testComponent.dateTimePicker.open();
536
- fixture.detectChanges();
537
- flush();
538
- expect(testComponent.dateTimePicker.opened).toBe(
539
- true,
540
- 'Expected dateTimePicker to be opened.'
541
- );
542
-
543
- const containerDebugElement = fixture.debugElement.query(
544
- By.directive(OwlDateTimeContainerComponent)
545
- );
546
- containerElement = containerDebugElement.nativeElement;
547
- expect(
548
- containerDebugElement.componentInstance.pickerMoment
549
- ).toEqual(new Date(2020, JAN, 1));
550
-
551
- const calendarBodyEl = containerElement.querySelector(
552
- '.owl-dt-calendar-body'
553
- );
554
-
555
- dispatchKeyboardEvent(
556
- calendarBodyEl,
557
- 'keydown',
558
- RIGHT_ARROW
559
- );
560
- fixture.detectChanges();
561
- flush();
562
- dispatchKeyboardEvent(calendarBodyEl, 'keydown', ENTER);
563
- fixture.detectChanges();
564
- flush();
565
-
566
- expect(testComponent.dateTimePicker.opened).toBe(
567
- false,
568
- 'Expected dateTimePicker to be closed.'
569
- );
570
- expect(testComponent.dateTimePickerInput.value).toEqual(
571
- new Date(2020, JAN, 2)
572
- );
573
- }));
574
-
575
- it('should close popup panel when click on the selected date', fakeAsync(() => {
576
- testComponent.dateTimePicker.open();
577
- fixture.detectChanges();
578
- flush();
579
- expect(testComponent.dateTimePicker.opened).toBe(
580
- true,
581
- 'Expected dateTimePicker to be opened.'
582
- );
583
-
584
- const containerDebugElement = fixture.debugElement.query(
585
- By.directive(OwlDateTimeContainerComponent)
586
- );
587
- containerElement = containerDebugElement.nativeElement;
588
- expect(
589
- containerDebugElement.componentInstance.pickerMoment
590
- ).toEqual(new Date(2020, JAN, 1));
591
- expect(testComponent.dateTimePicker.selected).toEqual(
592
- new Date(2020, JAN, 1)
593
- );
594
-
595
- const dateCell = containerElement.querySelector(
596
- '[aria-label="January 1, 2020"]'
597
- );
598
- dispatchMouseEvent(dateCell, 'click');
599
- fixture.detectChanges();
600
- flush();
601
-
602
- expect(testComponent.dateTimePicker.opened).toBe(
603
- false,
604
- 'Expected dateTimePicker to be closed.'
605
- );
606
- expect(testComponent.dateTimePickerInput.value).toEqual(
607
- new Date(2020, JAN, 1)
608
- );
609
- }));
610
- });
611
-
612
- describe('with only timer', () => {
613
- beforeEach(() => {
614
- testComponent.pickerType = 'timer';
615
- fixture.detectChanges();
616
- });
617
-
618
- it('should initialize with correct value shown in input', () => {
619
- if (SUPPORTS_INTL) {
620
- expect(
621
- fixture.nativeElement.querySelector('input').value
622
- ).toBe('12:00 AM');
623
- }
624
- });
625
-
626
- it('should have container control buttons', fakeAsync(() => {
627
- testComponent.dateTimePicker.open();
628
- fixture.detectChanges();
629
- flush();
630
- expect(testComponent.dateTimePicker.opened).toBe(
631
- true,
632
- 'Expected dateTimePicker to be opened.'
633
- );
634
-
635
- const containerDebugElement = fixture.debugElement.query(
636
- By.directive(OwlDateTimeContainerComponent)
637
- );
638
- containerElement = containerDebugElement.nativeElement;
639
- const btns = containerElement.querySelectorAll(
640
- '.owl-dt-container-control-button'
641
- );
642
-
643
- expect(btns.length).toBe(2);
644
- }));
645
- });
646
- });
647
-
648
- describe('range DateTimePicker', () => {
649
- let fixture: ComponentFixture<RangeDateTimePickerComponent>;
650
- let testComponent: RangeDateTimePickerComponent;
651
- let containerElement: HTMLElement;
652
-
653
- beforeEach(fakeAsync(() => {
654
- fixture = createComponent(RangeDateTimePickerComponent, [
655
- OwlNativeDateTimeModule
656
- ]);
657
- fixture.detectChanges();
658
- testComponent = fixture.componentInstance;
659
- }));
660
-
661
- afterEach(fakeAsync(() => {
662
- testComponent.dateTimePicker.close();
663
- fixture.detectChanges();
664
- flush();
665
- }));
666
-
667
- it('should initialize with correct value shown in input', () => {
668
- if (SUPPORTS_INTL) {
669
- expect(
670
- fixture.nativeElement.querySelector('input').value
671
- ).toBe('1/1/2020, 12:00 AM - 2/1/2020, 12:00 AM');
672
- }
673
- });
674
-
675
- it('should have default activeSelectedIndex value as 0', () => {
676
- testComponent.dateTimePicker.open();
677
- fixture.detectChanges();
678
-
679
- const containerDebugElement = fixture.debugElement.query(
680
- By.directive(OwlDateTimeContainerComponent)
681
- );
682
- expect(
683
- containerDebugElement.componentInstance.activeSelectedIndex
684
- ).toBe(0);
685
- });
686
-
687
- it('clicking the dateCell should set the rangeFrom value when both rangeFrom and rangeTo had NO value', fakeAsync(() => {
688
- testComponent.dates = [];
689
- fixture.detectChanges();
690
-
691
- testComponent.dateTimePicker.open();
692
- fixture.detectChanges();
693
- flush();
694
-
695
- expect(testComponent.dateTimePicker.selecteds.length).toBe(0);
696
-
697
- const containerDebugElement = fixture.debugElement.query(
698
- By.directive(OwlDateTimeContainerComponent)
699
- );
700
- containerElement = containerDebugElement.nativeElement;
701
-
702
- const dateCell = containerElement.querySelector(
703
- '[aria-label="January 2, 2020"]'
704
- );
705
- dispatchMouseEvent(dateCell, 'click');
706
- fixture.detectChanges();
707
- flush();
708
-
709
- expect(
710
- containerDebugElement.componentInstance.activeSelectedIndex
711
- ).toBe(0);
712
- expect(testComponent.dateTimePicker.selecteds.length).toBe(2);
713
- expect(testComponent.dateTimePicker.selecteds[0]).toEqual(
714
- new Date(2020, JAN, 2)
715
- );
716
- expect(testComponent.dateTimePicker.selecteds[1]).toBe(null);
717
- }));
718
-
719
- it('clicking the dateCell should set the rangeFrom value when both rangeFrom and rangeTo already had value', fakeAsync(() => {
720
- testComponent.dateTimePicker.open();
721
- fixture.detectChanges();
722
- flush();
723
-
724
- expect(testComponent.dateTimePicker.selecteds.length).toBe(2);
725
-
726
- const containerDebugElement = fixture.debugElement.query(
727
- By.directive(OwlDateTimeContainerComponent)
728
- );
729
- containerElement = containerDebugElement.nativeElement;
730
-
731
- const dateCell = containerElement.querySelector(
732
- '[aria-label="January 2, 2020"]'
733
- );
734
- dispatchMouseEvent(dateCell, 'click');
735
- fixture.detectChanges();
736
- flush();
737
-
738
- expect(
739
- containerDebugElement.componentInstance.activeSelectedIndex
740
- ).toBe(0);
741
- expect(testComponent.dateTimePicker.selecteds.length).toBe(2);
742
- expect(testComponent.dateTimePicker.selecteds[0]).toEqual(
743
- new Date(2020, JAN, 2)
744
- );
745
- expect(testComponent.dateTimePicker.selecteds[1]).toBe(null);
746
- }));
747
-
748
- it('clicking the dateCell should set the rangeFrom value when dateCell value is before the old rangeFrom value',
749
- fakeAsync(() => {
750
- testComponent.dates = [new Date(2020, JAN, 2), null];
751
- fixture.detectChanges();
752
-
753
- testComponent.dateTimePicker.open();
754
- fixture.detectChanges();
755
- flush();
756
-
757
- expect(testComponent.dateTimePicker.selecteds.length).toBe(2);
758
-
759
- const containerDebugElement = fixture.debugElement.query(
760
- By.directive(OwlDateTimeContainerComponent)
761
- );
762
- containerElement = containerDebugElement.nativeElement;
763
-
764
- const dateCell = containerElement.querySelector(
765
- '[aria-label="January 1, 2020"]'
766
- );
767
- dispatchMouseEvent(dateCell, 'click');
768
- fixture.detectChanges();
769
- flush();
770
-
771
- expect(
772
- containerDebugElement.componentInstance.activeSelectedIndex
773
- ).toBe(0);
774
- expect(testComponent.dateTimePicker.selecteds.length).toBe(2);
775
- expect(testComponent.dateTimePicker.selecteds[0]).toEqual(
776
- new Date(2020, JAN, 1)
777
- );
778
- expect(testComponent.dateTimePicker.selecteds[1]).toBe(null);
779
- }));
780
-
781
- it('clicking the dateCell should set the rangeTo value when rangeFrom already had value', fakeAsync(() => {
782
- testComponent.dates = [new Date(2020, JAN, 2), null];
783
- fixture.detectChanges();
784
-
785
- testComponent.dateTimePicker.open();
786
- fixture.detectChanges();
787
- flush();
788
-
789
- expect(testComponent.dateTimePicker.selecteds.length).toBe(2);
790
-
791
- const containerDebugElement = fixture.debugElement.query(
792
- By.directive(OwlDateTimeContainerComponent)
793
- );
794
- containerElement = containerDebugElement.nativeElement;
795
-
796
- const dateCell = containerElement.querySelector(
797
- '[aria-label="January 3, 2020"]'
798
- );
799
- dispatchMouseEvent(dateCell, 'click');
800
- fixture.detectChanges();
801
- flush();
802
-
803
- expect(
804
- containerDebugElement.componentInstance.activeSelectedIndex
805
- ).toBe(1);
806
- expect(testComponent.dateTimePicker.selecteds.length).toBe(2);
807
- expect(testComponent.dateTimePicker.selecteds[0]).toEqual(
808
- new Date(2020, JAN, 2)
809
- );
810
- expect(testComponent.dateTimePicker.selecteds[1]).toEqual(
811
- new Date(2020, JAN, 3)
812
- );
813
- }));
814
-
815
- it('if startAt value is set, the start time value should be shown in the rangeTo calendar start time', fakeAsync(() => {
816
- testComponent.startAt = new Date('1/19/2020, 09:33 AM');
817
- testComponent.dateTimePicker.open();
818
- fixture.detectChanges();
819
- flush();
820
-
821
- const containerDebugElement = fixture.debugElement.query(
822
- By.directive(OwlDateTimeContainerComponent)
823
- );
824
- containerElement = containerDebugElement.nativeElement;
825
- const timeCells = containerElement.querySelectorAll<HTMLInputElement>('.owl-dt-timer-input');
826
-
827
- expect(timeCells[0].value).toEqual('09');
828
- expect(timeCells[1].value).toEqual('33');
829
- }));
830
-
831
-
832
- it('if endAt value is set, the end time value should be shown in the rangeTo calendar end time', fakeAsync(() => {
833
- testComponent.dates = [new Date(2020, JAN, 2), null];
834
- testComponent.endAt = new Date('1/19/2020, 10:55 PM');
835
- fixture.detectChanges();
836
-
837
- testComponent.dateTimePicker.open();
838
- fixture.detectChanges();
839
- flush();
840
-
841
- const containerDebugElement = fixture.debugElement.query(
842
- By.directive(OwlDateTimeContainerComponent)
843
- );
844
- containerElement = containerDebugElement.nativeElement;
845
- const dateCell = containerElement.querySelector(
846
- '[aria-label="January 20, 2020"]'
847
- );
848
- dispatchMouseEvent(dateCell, 'click');
849
- fixture.detectChanges();
850
- flush();
851
-
852
- const timeCells = containerElement.querySelectorAll<HTMLInputElement>('.owl-dt-timer-input');
853
-
854
- expect(timeCells[0].value).toEqual('22');
855
- expect(timeCells[1].value).toEqual('55');
856
- }));
857
-
858
- it('auto select previous time if dates is selected', fakeAsync(() => {
859
- testComponent.dates = [new Date('1/19/2020, 09:33 AM'), new Date('1/22/2020, 10:44 PM')];
860
- testComponent.dateTimePicker.open();
861
- fixture.detectChanges();
862
-
863
- const containerDebugElement = fixture.debugElement.query(
864
- By.directive(OwlDateTimeContainerComponent)
865
- );
866
- containerElement = containerDebugElement.nativeElement;
867
- const dateCell = containerElement.querySelector(
868
- '[aria-label="January 20, 2020"]'
869
- );
870
- dispatchMouseEvent(dateCell, 'click');
871
- fixture.detectChanges();
872
- flush();
873
-
874
- const timeInput = containerElement.querySelectorAll<HTMLInputElement>('.owl-dt-timer-input');
875
-
876
- expect(timeInput[0].value).toEqual('09');
877
- expect(timeInput[1].value).toEqual('33');
878
-
879
- }));
880
-
881
- it('should have the container info row', () => {
882
- testComponent.dateTimePicker.open();
883
- fixture.detectChanges();
884
-
885
- const containerDebugElement = fixture.debugElement.query(
886
- By.directive(OwlDateTimeContainerComponent)
887
- );
888
- containerElement = containerDebugElement.nativeElement;
889
-
890
- const infoRow = containerElement.querySelector(
891
- '.owl-dt-container-info'
892
- );
893
-
894
- expect(infoRow).toBeTruthy();
895
- });
896
-
897
- it('should set the activeSelectedIndex via clicking the info row radio', fakeAsync(() => {
898
- testComponent.dateTimePicker.open();
899
- fixture.detectChanges();
900
-
901
- const containerDebugElement = fixture.debugElement.query(
902
- By.directive(OwlDateTimeContainerComponent)
903
- );
904
- containerElement = containerDebugElement.nativeElement;
905
-
906
- const radioBtns = containerElement.querySelectorAll(
907
- '.owl-dt-container-range'
908
- );
909
-
910
- for (let i = 0; i < radioBtns.length; i++) {
911
- dispatchMouseEvent(radioBtns[i], 'click');
912
- fixture.detectChanges();
913
- flush();
914
-
915
- expect(
916
- containerDebugElement.componentInstance
917
- .activeSelectedIndex
918
- ).toBe(i);
919
- }
920
- }));
921
-
922
- describe('with only calendar', () => {
923
- beforeEach(() => {
924
- testComponent.pickerType = 'calendar';
925
- fixture.detectChanges();
926
- });
927
-
928
- it('should initialize with correct value shown in input', () => {
929
- if (SUPPORTS_INTL) {
930
- expect(
931
- fixture.nativeElement.querySelector('input').value
932
- ).toBe('1/1/2020 - 2/1/2020');
933
- }
934
- });
935
-
936
- it('should NOT close the dateTimePicker popup panel when only the rangeFrom value is selected', fakeAsync(() => {
937
- testComponent.dates = [];
938
- fixture.detectChanges();
939
-
940
- testComponent.dateTimePicker.open();
941
- fixture.detectChanges();
942
- flush();
943
-
944
- expect(testComponent.dateTimePicker.selecteds.length).toBe(
945
- 0
946
- );
947
-
948
- const containerDebugElement = fixture.debugElement.query(
949
- By.directive(OwlDateTimeContainerComponent)
950
- );
951
- containerElement = containerDebugElement.nativeElement;
952
-
953
- const dateCell = containerElement.querySelector(
954
- '[aria-label="January 2, 2020"]'
955
- );
956
- dispatchMouseEvent(dateCell, 'click');
957
- fixture.detectChanges();
958
- flush();
959
-
960
- expect(testComponent.dateTimePicker.opened).toBe(
961
- true,
962
- 'Expected dateTimePicker to be opened.'
963
- );
964
- }));
965
-
966
- it('should close the dateTimePicker popup panel when both the rangeFrom and the rangeTo value are selected',
967
- fakeAsync(() => {
968
- testComponent.dates = [];
969
- fixture.detectChanges();
970
-
971
- testComponent.dateTimePicker.open();
972
- fixture.detectChanges();
973
- flush();
974
-
975
- expect(testComponent.dateTimePicker.selecteds.length).toBe(
976
- 0
977
- );
978
-
979
- const containerDebugElement = fixture.debugElement.query(
980
- By.directive(OwlDateTimeContainerComponent)
981
- );
982
- containerElement = containerDebugElement.nativeElement;
983
-
984
- let dateCell = containerElement.querySelector(
985
- '[aria-label="January 2, 2020"]'
986
- );
987
- dispatchMouseEvent(dateCell, 'click');
988
- fixture.detectChanges();
989
- flush();
990
-
991
- dateCell = containerElement.querySelector(
992
- '[aria-label="January 3, 2020"]'
993
- );
994
- dispatchMouseEvent(dateCell, 'click');
995
- fixture.detectChanges();
996
- flush();
997
-
998
- expect(testComponent.dateTimePicker.selecteds.length).toBe(
999
- 2
1000
- );
1001
- expect(testComponent.dateTimePicker.opened).toBe(
1002
- false,
1003
- 'Expected dateTimePicker to be closed.'
1004
- );
1005
- }));
1006
- });
1007
- });
1008
-
1009
- describe('DateTimePicker with too many inputs', () => {
1010
- it('should throw when multiple inputs registered', fakeAsync(() => {
1011
- const fixture = createComponent(MultiInputDateTimePickerComponent, [
1012
- OwlNativeDateTimeModule
1013
- ]);
1014
- expect(() => fixture.detectChanges()).toThrow();
1015
- }));
1016
- });
1017
-
1018
- describe('DateTimePicker with no input', () => {
1019
- let fixture: ComponentFixture<NoInputDateTimePickerComponent>;
1020
- let testComponent: NoInputDateTimePickerComponent;
1021
-
1022
- beforeEach(fakeAsync(() => {
1023
- fixture = createComponent(NoInputDateTimePickerComponent, [
1024
- OwlNativeDateTimeModule
1025
- ]);
1026
- fixture.detectChanges();
1027
-
1028
- testComponent = fixture.componentInstance;
1029
- }));
1030
-
1031
- afterEach(fakeAsync(() => {
1032
- testComponent.dateTimePicker.close();
1033
- fixture.detectChanges();
1034
- }));
1035
-
1036
- it('should NOT throw when accessing disabled property', () => {
1037
- expect(
1038
- () => testComponent.dateTimePicker.disabled
1039
- ).not.toThrow();
1040
- });
1041
-
1042
- it('should throw when opened with no registered inputs', fakeAsync(() => {
1043
- expect(() => testComponent.dateTimePicker.open()).toThrow();
1044
- }));
1045
- });
1046
-
1047
- describe('DateTimePicker with startAt', () => {
1048
- let fixture: ComponentFixture<DateTimePickerWithStartAtComponent>;
1049
- let testComponent: DateTimePickerWithStartAtComponent;
1050
-
1051
- beforeEach(fakeAsync(() => {
1052
- fixture = createComponent(DateTimePickerWithStartAtComponent, [
1053
- OwlNativeDateTimeModule
1054
- ]);
1055
- fixture.detectChanges();
1056
-
1057
- testComponent = fixture.componentInstance;
1058
- }));
1059
-
1060
- afterEach(fakeAsync(() => {
1061
- testComponent.dateTimePicker.close();
1062
- fixture.detectChanges();
1063
- }));
1064
-
1065
- it('should override input value by explicit startAt', () => {
1066
- expect(testComponent.dateTimePicker.startAt).toEqual(
1067
- new Date(2010, JAN, 1)
1068
- );
1069
- });
1070
- });
1071
-
1072
- describe('DateTimePicker with startView', () => {
1073
- let fixture: ComponentFixture<DateTimePickerWithStartViewComponent>;
1074
- let testComponent: DateTimePickerWithStartViewComponent;
1075
- let containerDebugElement;
1076
- let containerElement;
1077
-
1078
- beforeEach(() => {
1079
- fixture = createComponent(DateTimePickerWithStartViewComponent, [
1080
- OwlNativeDateTimeModule
1081
- ]);
1082
- fixture.detectChanges();
1083
-
1084
- testComponent = fixture.componentInstance;
1085
- });
1086
-
1087
- afterEach(() => {
1088
- testComponent.dateTimePicker.close();
1089
- fixture.detectChanges();
1090
- });
1091
-
1092
- describe('set to year', () => {
1093
- beforeEach(() => {
1094
- testComponent.startView = DateView.YEAR;
1095
- fixture.detectChanges();
1096
- });
1097
-
1098
- it('should start at the year view', () => {
1099
- testComponent.dateTimePicker.open();
1100
- fixture.detectChanges();
1101
-
1102
- containerDebugElement = fixture.debugElement.query(
1103
- By.directive(OwlDateTimeContainerComponent)
1104
- );
1105
- containerElement = containerDebugElement.nativeElement;
1106
- const yearTable = containerElement.querySelector(
1107
- 'table.owl-dt-calendar-year-table'
1108
- );
1109
- expect(yearTable).toBeTruthy();
1110
- });
1111
-
1112
- it('should fire monthSelected when user selects calendar month in year view', fakeAsync(() => {
1113
- spyOn(testComponent, 'onMonthSelection');
1114
- expect(
1115
- testComponent.onMonthSelection
1116
- ).not.toHaveBeenCalled();
1117
-
1118
- testComponent.dateTimePicker.open();
1119
- fixture.detectChanges();
1120
-
1121
- containerDebugElement = fixture.debugElement.query(
1122
- By.directive(OwlDateTimeContainerComponent)
1123
- );
1124
- containerElement = containerDebugElement.nativeElement;
1125
- const cells = containerElement.querySelectorAll(
1126
- '.owl-dt-calendar-cell'
1127
- );
1128
-
1129
- dispatchMouseEvent(cells[0], 'click');
1130
- fixture.detectChanges();
1131
- flush();
1132
-
1133
- expect(testComponent.onMonthSelection).toHaveBeenCalled();
1134
- }));
1135
- });
1136
-
1137
- describe('set to multi-years', () => {
1138
- beforeEach(() => {
1139
- testComponent.startView = DateView.MULTI_YEARS;
1140
- fixture.detectChanges();
1141
- });
1142
-
1143
- it('should start at the multi-years view', () => {
1144
- testComponent.dateTimePicker.open();
1145
- fixture.detectChanges();
1146
-
1147
- containerDebugElement = fixture.debugElement.query(
1148
- By.directive(OwlDateTimeContainerComponent)
1149
- );
1150
- containerElement = containerDebugElement.nativeElement;
1151
- const multiYearTable = containerElement.querySelector(
1152
- 'table.owl-dt-calendar-multi-year-table'
1153
- );
1154
- expect(multiYearTable).toBeTruthy();
1155
- });
1156
-
1157
- it('should fire yearSelected when user selects calendar year in multi-years view', fakeAsync(() => {
1158
- spyOn(testComponent, 'onYearSelection');
1159
- expect(
1160
- testComponent.onYearSelection
1161
- ).not.toHaveBeenCalled();
1162
-
1163
- testComponent.dateTimePicker.open();
1164
- fixture.detectChanges();
1165
-
1166
- containerDebugElement = fixture.debugElement.query(
1167
- By.directive(OwlDateTimeContainerComponent)
1168
- );
1169
- containerElement = containerDebugElement.nativeElement;
1170
- const cells = containerElement.querySelectorAll(
1171
- '.owl-dt-calendar-cell'
1172
- );
1173
-
1174
- dispatchMouseEvent(cells[0], 'click');
1175
- fixture.detectChanges();
1176
- flush();
1177
-
1178
- expect(testComponent.onYearSelection).toHaveBeenCalled();
1179
- }));
1180
- });
1181
- });
1182
-
1183
- describe('DateTimePicker with NgModel', () => {
1184
- let fixture: ComponentFixture<DateTimePickerWithNgModelComponent>;
1185
- let testComponent: DateTimePickerWithNgModelComponent;
1186
-
1187
- beforeEach(fakeAsync(() => {
1188
- fixture = createComponent(DateTimePickerWithNgModelComponent, [
1189
- OwlNativeDateTimeModule
1190
- ]);
1191
- fixture.detectChanges();
1192
- fixture.whenStable().then(() => {
1193
- fixture.detectChanges();
1194
-
1195
- testComponent = fixture.componentInstance;
1196
- });
1197
- }));
1198
-
1199
- afterEach(fakeAsync(() => {
1200
- testComponent.dateTimePicker.close();
1201
- fixture.detectChanges();
1202
- flush();
1203
- }));
1204
-
1205
- it('should update dateTimePicker when model changes', fakeAsync(() => {
1206
- expect(testComponent.dateTimePickerInput.value).toBeNull();
1207
- expect(testComponent.dateTimePicker.selected).toBeNull();
1208
-
1209
- const selected = new Date(2017, JAN, 1);
1210
- testComponent.moment = selected;
1211
- fixture.detectChanges();
1212
- flush();
1213
- fixture.detectChanges();
1214
-
1215
- expect(testComponent.dateTimePickerInput.value).toEqual(
1216
- selected
1217
- );
1218
- expect(testComponent.dateTimePicker.selected).toEqual(selected);
1219
- }));
1220
-
1221
- it('should update model when date is selected', fakeAsync(() => {
1222
- expect(testComponent.moment).toBeNull();
1223
- expect(testComponent.dateTimePickerInput.value).toBeNull();
1224
-
1225
- const selected = new Date(2017, JAN, 1);
1226
- testComponent.dateTimePicker.select(selected);
1227
- fixture.detectChanges();
1228
- flush();
1229
- testComponent.dateTimePicker.confirmSelect();
1230
- fixture.detectChanges();
1231
- flush();
1232
- fixture.detectChanges();
1233
-
1234
- expect(testComponent.moment).toEqual(selected);
1235
- expect(testComponent.dateTimePickerInput.value).toEqual(
1236
- selected
1237
- );
1238
- }));
1239
-
1240
- it('should mark input dirty after input event', () => {
1241
- const inputEl = fixture.debugElement.query(By.css('input'))
1242
- .nativeElement;
1243
-
1244
- expect(inputEl.classList).toContain('ng-pristine');
1245
-
1246
- inputEl.value = '2001-01-01';
1247
- dispatchFakeEvent(inputEl, 'input');
1248
- fixture.detectChanges();
1249
-
1250
- expect(inputEl.classList).toContain('ng-dirty');
1251
- });
1252
-
1253
- it('should mark input dirty after date selected', fakeAsync(() => {
1254
- const inputEl = fixture.debugElement.query(By.css('input'))
1255
- .nativeElement;
1256
-
1257
- expect(inputEl.classList).toContain('ng-pristine');
1258
-
1259
- testComponent.dateTimePicker.select(new Date(2017, JAN, 1));
1260
- fixture.detectChanges();
1261
- flush();
1262
- testComponent.dateTimePicker.confirmSelect();
1263
- fixture.detectChanges();
1264
- flush();
1265
- fixture.detectChanges();
1266
-
1267
- expect(inputEl.classList).toContain('ng-dirty');
1268
- }));
1269
-
1270
- it('should not mark dirty after model change', fakeAsync(() => {
1271
- const inputEl = fixture.debugElement.query(By.css('input'))
1272
- .nativeElement;
1273
-
1274
- expect(inputEl.classList).toContain('ng-pristine');
1275
-
1276
- testComponent.moment = new Date(2017, JAN, 1);
1277
- fixture.detectChanges();
1278
- flush();
1279
- fixture.detectChanges();
1280
-
1281
- expect(inputEl.classList).toContain('ng-pristine');
1282
- }));
1283
-
1284
- it('should mark input touched on blur', () => {
1285
- const inputEl = fixture.debugElement.query(By.css('input'))
1286
- .nativeElement;
1287
-
1288
- expect(inputEl.classList).toContain('ng-untouched');
1289
-
1290
- dispatchFakeEvent(inputEl, 'focus');
1291
- fixture.detectChanges();
1292
-
1293
- expect(inputEl.classList).toContain('ng-untouched');
1294
-
1295
- dispatchFakeEvent(inputEl, 'blur');
1296
- fixture.detectChanges();
1297
-
1298
- expect(inputEl.classList).toContain('ng-touched');
1299
- });
1300
-
1301
- it('should not reformat invalid dates on blur', () => {
1302
- const inputEl = fixture.debugElement.query(By.css('input'))
1303
- .nativeElement;
1304
-
1305
- inputEl.value = 'very-valid-date';
1306
- dispatchFakeEvent(inputEl, 'input');
1307
- fixture.detectChanges();
1308
-
1309
- dispatchFakeEvent(inputEl, 'blur');
1310
- fixture.detectChanges();
1311
-
1312
- expect(inputEl.value).toBe('very-valid-date');
1313
- });
1314
-
1315
- it('should mark input touched on calendar selection', fakeAsync(() => {
1316
- const inputEl = fixture.debugElement.query(By.css('input'))
1317
- .nativeElement;
1318
-
1319
- expect(inputEl.classList).toContain('ng-untouched');
1320
-
1321
- testComponent.dateTimePicker.select(new Date(2017, JAN, 1));
1322
- fixture.detectChanges();
1323
- flush();
1324
- testComponent.dateTimePicker.confirmSelect();
1325
- fixture.detectChanges();
1326
- flush();
1327
- fixture.detectChanges();
1328
-
1329
- expect(inputEl.classList).toContain('ng-touched');
1330
- }));
1331
-
1332
- describe('with range mode', () => {
1333
- beforeEach(() => {
1334
- testComponent.selectMode = 'range';
1335
- fixture.detectChanges();
1336
- expect(testComponent.dateTimePicker.selectMode).toBe(
1337
- 'range'
1338
- );
1339
- });
1340
-
1341
- it('should update dateTimePicker when model changes', fakeAsync(() => {
1342
- expect(
1343
- testComponent.dateTimePickerInput.values.length
1344
- ).toBe(0);
1345
- expect(testComponent.dateTimePicker.selecteds.length).toBe(
1346
- 0
1347
- );
1348
-
1349
- const from = new Date(2017, JAN, 1);
1350
- const to = new Date(2017, JAN, 3);
1351
- testComponent.moment = [from, to];
1352
- fixture.detectChanges();
1353
- flush();
1354
- fixture.detectChanges();
1355
-
1356
- expect(
1357
- testComponent.dateTimePickerInput.values.length
1358
- ).toBe(2);
1359
- expect(testComponent.dateTimePickerInput.values[0]).toEqual(
1360
- from
1361
- );
1362
- expect(testComponent.dateTimePickerInput.values[1]).toEqual(
1363
- to
1364
- );
1365
- expect(testComponent.dateTimePicker.selecteds.length).toBe(
1366
- 2
1367
- );
1368
- expect(testComponent.dateTimePicker.selecteds[0]).toEqual(
1369
- from
1370
- );
1371
- expect(testComponent.dateTimePicker.selecteds[1]).toEqual(
1372
- to
1373
- );
1374
- }));
1375
-
1376
- it('should update model when date is selected', fakeAsync(() => {
1377
- expect(testComponent.moment).toBeNull();
1378
- expect(
1379
- testComponent.dateTimePickerInput.values.length
1380
- ).toBe(0);
1381
-
1382
- const from = new Date(2017, JAN, 1);
1383
- const to = new Date(2017, JAN, 3);
1384
- testComponent.dateTimePicker.select([from, to]);
1385
- fixture.detectChanges();
1386
- flush();
1387
- testComponent.dateTimePicker.confirmSelect();
1388
- fixture.detectChanges();
1389
- flush();
1390
- fixture.detectChanges();
1391
-
1392
- expect(testComponent.moment[0]).toEqual(from);
1393
- expect(testComponent.moment[1]).toEqual(to);
1394
- expect(
1395
- testComponent.dateTimePickerInput.values.length
1396
- ).toBe(2);
1397
- expect(testComponent.dateTimePickerInput.values[0]).toEqual(
1398
- from
1399
- );
1400
- expect(testComponent.dateTimePickerInput.values[1]).toEqual(
1401
- to
1402
- );
1403
- }));
1404
- });
1405
-
1406
- describe('with rangeFrom mode', () => {
1407
- beforeEach(() => {
1408
- testComponent.selectMode = 'rangeFrom';
1409
- fixture.detectChanges();
1410
- expect(testComponent.dateTimePicker.selectMode).toBe(
1411
- 'rangeFrom'
1412
- );
1413
- });
1414
-
1415
- it('should update dateTimePicker when model changes', fakeAsync(() => {
1416
- expect(
1417
- testComponent.dateTimePickerInput.values.length
1418
- ).toBe(0);
1419
- expect(testComponent.dateTimePicker.selecteds.length).toBe(
1420
- 0
1421
- );
1422
-
1423
- const from = new Date(2017, JAN, 1);
1424
- testComponent.moment = [from];
1425
- fixture.detectChanges();
1426
- flush();
1427
- fixture.detectChanges();
1428
-
1429
- expect(testComponent.dateTimePickerInput.values[0]).toEqual(
1430
- from
1431
- );
1432
- expect(
1433
- testComponent.dateTimePickerInput.values[1]
1434
- ).toBeFalsy();
1435
- expect(testComponent.dateTimePicker.selecteds[0]).toEqual(
1436
- from
1437
- );
1438
- expect(
1439
- testComponent.dateTimePicker.selecteds[1]
1440
- ).toBeFalsy();
1441
- }));
1442
-
1443
- it('should only update fromValue when date is selected', fakeAsync(() => {
1444
- const from = new Date(2017, JAN, 1);
1445
- const to = new Date(2017, JAN, 3);
1446
- testComponent.moment = [from, to];
1447
- fixture.detectChanges();
1448
- flush();
1449
- fixture.detectChanges();
1450
-
1451
- testComponent.dateTimePicker.open();
1452
- fixture.detectChanges();
1453
- flush();
1454
-
1455
- const newSelectedFrom = new Date(2017, JAN, 2);
1456
- const containerDebugElement = fixture.debugElement.query(
1457
- By.directive(OwlDateTimeContainerComponent)
1458
- );
1459
- containerDebugElement.componentInstance.dateSelected(
1460
- newSelectedFrom
1461
- );
1462
- fixture.detectChanges();
1463
- flush();
1464
- testComponent.dateTimePicker.confirmSelect();
1465
- fixture.detectChanges();
1466
- flush();
1467
- fixture.detectChanges();
1468
-
1469
- expect(testComponent.dateTimePicker.selecteds[0]).toEqual(
1470
- newSelectedFrom
1471
- );
1472
- expect(testComponent.dateTimePicker.selecteds[1]).toEqual(
1473
- to
1474
- );
1475
- expect(testComponent.dateTimePickerInput.values[0]).toEqual(
1476
- newSelectedFrom
1477
- );
1478
- expect(testComponent.dateTimePickerInput.values[1]).toEqual(
1479
- to
1480
- );
1481
- expect(testComponent.moment[0]).toEqual(newSelectedFrom);
1482
- expect(testComponent.moment[1]).toEqual(to);
1483
- }));
1484
-
1485
- it('should update fromValue and set toValue to null when date is selected after toValue', fakeAsync(() => {
1486
- const from = new Date(2017, JAN, 1);
1487
- const to = new Date(2017, JAN, 3);
1488
- testComponent.moment = [from, to];
1489
- fixture.detectChanges();
1490
- flush();
1491
- fixture.detectChanges();
1492
-
1493
- testComponent.dateTimePicker.open();
1494
- fixture.detectChanges();
1495
- flush();
1496
-
1497
- const newSelectedFrom = new Date(2017, JAN, 4);
1498
- const containerDebugElement = fixture.debugElement.query(
1499
- By.directive(OwlDateTimeContainerComponent)
1500
- );
1501
- containerDebugElement.componentInstance.dateSelected(
1502
- newSelectedFrom
1503
- );
1504
- fixture.detectChanges();
1505
- flush();
1506
- testComponent.dateTimePicker.confirmSelect();
1507
- fixture.detectChanges();
1508
- flush();
1509
- fixture.detectChanges();
1510
-
1511
- expect(testComponent.dateTimePicker.selecteds[0]).toEqual(
1512
- newSelectedFrom
1513
- );
1514
- expect(
1515
- testComponent.dateTimePicker.selecteds[1]
1516
- ).toBeFalsy();
1517
- expect(testComponent.dateTimePickerInput.values[0]).toEqual(
1518
- newSelectedFrom
1519
- );
1520
- expect(
1521
- testComponent.dateTimePickerInput.values[1]
1522
- ).toBeFalsy();
1523
- expect(testComponent.moment[0]).toEqual(newSelectedFrom);
1524
- expect(testComponent.moment[1]).toBeFalsy();
1525
- }));
1526
- });
1527
-
1528
- describe('with rangeTo mode', () => {
1529
- beforeEach(() => {
1530
- testComponent.selectMode = 'rangeTo';
1531
- fixture.detectChanges();
1532
- expect(testComponent.dateTimePicker.selectMode).toBe(
1533
- 'rangeTo'
1534
- );
1535
- });
1536
-
1537
- it('should update dateTimePicker when model changes', fakeAsync(() => {
1538
- expect(
1539
- testComponent.dateTimePickerInput.values.length
1540
- ).toBe(0);
1541
- expect(testComponent.dateTimePicker.selecteds.length).toBe(
1542
- 0
1543
- );
1544
-
1545
- const to = new Date(2017, JAN, 3);
1546
- testComponent.moment = [null, to];
1547
- fixture.detectChanges();
1548
- flush();
1549
- fixture.detectChanges();
1550
-
1551
- expect(
1552
- testComponent.dateTimePickerInput.values[0]
1553
- ).toBeFalsy();
1554
- expect(testComponent.dateTimePickerInput.values[1]).toEqual(
1555
- to
1556
- );
1557
- expect(
1558
- testComponent.dateTimePicker.selecteds[0]
1559
- ).toBeFalsy();
1560
- expect(testComponent.dateTimePicker.selecteds[1]).toEqual(
1561
- to
1562
- );
1563
- }));
1564
-
1565
- it('should only update toValue when date is selected', fakeAsync(() => {
1566
- const from = new Date(2017, JAN, 1);
1567
- const to = new Date(2017, JAN, 3);
1568
- testComponent.moment = [from, to];
1569
- fixture.detectChanges();
1570
- flush();
1571
- fixture.detectChanges();
1572
-
1573
- testComponent.dateTimePicker.open();
1574
- fixture.detectChanges();
1575
- flush();
1576
-
1577
- const newSelectedTo = new Date(2017, JAN, 4);
1578
- const containerDebugElement = fixture.debugElement.query(
1579
- By.directive(OwlDateTimeContainerComponent)
1580
- );
1581
- containerDebugElement.componentInstance.dateSelected(
1582
- newSelectedTo
1583
- );
1584
- fixture.detectChanges();
1585
- flush();
1586
- testComponent.dateTimePicker.confirmSelect();
1587
- fixture.detectChanges();
1588
- flush();
1589
- fixture.detectChanges();
1590
-
1591
- expect(testComponent.dateTimePicker.selecteds[0]).toEqual(
1592
- from
1593
- );
1594
- expect(testComponent.dateTimePicker.selecteds[1]).toEqual(
1595
- newSelectedTo
1596
- );
1597
- expect(testComponent.dateTimePickerInput.values[0]).toEqual(
1598
- from
1599
- );
1600
- expect(testComponent.dateTimePickerInput.values[1]).toEqual(
1601
- newSelectedTo
1602
- );
1603
- expect(testComponent.moment[0]).toEqual(from);
1604
- expect(testComponent.moment[1]).toEqual(newSelectedTo);
1605
- }));
1606
-
1607
- it('should update toValue and set fromValue to null when date is selected before fromValue', fakeAsync(() => {
1608
- const from = new Date(2017, JAN, 2);
1609
- const to = new Date(2017, JAN, 3);
1610
- testComponent.moment = [from, to];
1611
- fixture.detectChanges();
1612
- flush();
1613
- fixture.detectChanges();
1614
-
1615
- testComponent.dateTimePicker.open();
1616
- fixture.detectChanges();
1617
- flush();
1618
-
1619
- const newSelectedTo = new Date(2017, JAN, 1);
1620
- const containerDebugElement = fixture.debugElement.query(
1621
- By.directive(OwlDateTimeContainerComponent)
1622
- );
1623
- containerDebugElement.componentInstance.dateSelected(
1624
- newSelectedTo
1625
- );
1626
- fixture.detectChanges();
1627
- flush();
1628
- testComponent.dateTimePicker.confirmSelect();
1629
- fixture.detectChanges();
1630
- flush();
1631
- fixture.detectChanges();
1632
-
1633
- expect(
1634
- testComponent.dateTimePicker.selecteds[0]
1635
- ).toBeFalsy();
1636
- expect(testComponent.dateTimePicker.selecteds[1]).toEqual(
1637
- newSelectedTo
1638
- );
1639
- expect(
1640
- testComponent.dateTimePickerInput.values[0]
1641
- ).toBeFalsy();
1642
- expect(testComponent.dateTimePickerInput.values[1]).toEqual(
1643
- newSelectedTo
1644
- );
1645
- expect(testComponent.moment[0]).toBeFalsy();
1646
- expect(testComponent.moment[1]).toEqual(newSelectedTo);
1647
- }));
1648
- });
1649
- });
1650
-
1651
- describe('DateTimePicker with FormControl', () => {
1652
- let fixture: ComponentFixture<DateTimePickerWithFormControlComponent>;
1653
- let testComponent: DateTimePickerWithFormControlComponent;
1654
-
1655
- beforeEach(fakeAsync(() => {
1656
- fixture = createComponent(DateTimePickerWithFormControlComponent, [
1657
- OwlNativeDateTimeModule
1658
- ]);
1659
- fixture.detectChanges();
1660
-
1661
- testComponent = fixture.componentInstance;
1662
- }));
1663
-
1664
- afterEach(fakeAsync(() => {
1665
- testComponent.dateTimePicker.close();
1666
- fixture.detectChanges();
1667
- }));
1668
-
1669
- it('should update dateTimePicker when formControl changes', () => {
1670
- expect(testComponent.dateTimePickerInput.value).toBeNull();
1671
- expect(testComponent.dateTimePicker.selected).toBeNull();
1672
-
1673
- const selected = new Date(2017, JAN, 1);
1674
- testComponent.formControl.setValue(selected);
1675
- fixture.detectChanges();
1676
-
1677
- expect(testComponent.dateTimePickerInput.value).toEqual(
1678
- selected
1679
- );
1680
- expect(testComponent.dateTimePicker.selected).toEqual(selected);
1681
- });
1682
-
1683
- it('should update formControl when date is selected', fakeAsync(() => {
1684
- expect(testComponent.formControl.value).toBeNull();
1685
- expect(testComponent.dateTimePickerInput.value).toBeNull();
1686
-
1687
- const selected = new Date(2017, JAN, 1);
1688
- testComponent.dateTimePicker.select(selected);
1689
- fixture.detectChanges();
1690
- flush();
1691
- testComponent.dateTimePicker.confirmSelect();
1692
- fixture.detectChanges();
1693
- flush();
1694
- fixture.detectChanges();
1695
-
1696
- expect(testComponent.formControl.value).toEqual(selected);
1697
- expect(testComponent.dateTimePickerInput.value).toEqual(
1698
- selected
1699
- );
1700
- }));
1701
-
1702
- it('should disable input when form control disabled', () => {
1703
- const inputEl = fixture.debugElement.query(By.css('input'))
1704
- .nativeElement;
1705
-
1706
- expect(inputEl.disabled).toBe(false);
1707
-
1708
- testComponent.formControl.disable();
1709
- fixture.detectChanges();
1710
-
1711
- expect(inputEl.disabled).toBe(true);
1712
- });
1713
-
1714
- it('should disable toggle when form control disabled', () => {
1715
- expect(testComponent.dateTimePickerToggle.disabled).toBe(false);
1716
-
1717
- testComponent.formControl.disable();
1718
- fixture.detectChanges();
1719
-
1720
- expect(testComponent.dateTimePickerToggle.disabled).toBe(true);
1721
- });
1722
- });
1723
-
1724
- describe('DateTimePicker with owlDateTimeTrigger', () => {
1725
- let fixture: ComponentFixture<DateTimePickerWithTriggerComponent>;
1726
- let testComponent: DateTimePickerWithTriggerComponent;
1727
-
1728
- beforeEach(fakeAsync(() => {
1729
- fixture = createComponent(DateTimePickerWithTriggerComponent, [
1730
- OwlNativeDateTimeModule
1731
- ]);
1732
- fixture.detectChanges();
1733
-
1734
- testComponent = fixture.componentInstance;
1735
- }));
1736
-
1737
- afterEach(fakeAsync(() => {
1738
- testComponent.dateTimePicker.close();
1739
- fixture.detectChanges();
1740
- flush();
1741
- }));
1742
-
1743
- it('should open the picker when trigger clicked', () => {
1744
- expect(
1745
- document.querySelector('owl-date-time-container')
1746
- ).toBeNull();
1747
-
1748
- const toggle = fixture.debugElement.query(By.css('button'));
1749
- dispatchMouseEvent(toggle.nativeElement, 'click');
1750
- fixture.detectChanges();
1751
-
1752
- expect(
1753
- document.querySelector('owl-date-time-container')
1754
- ).not.toBeNull();
1755
- });
1756
-
1757
- it('should not open the picker when trigger clicked if dateTimePicker is disabled', () => {
1758
- testComponent.dateTimePicker.disabled = true;
1759
- fixture.detectChanges();
1760
- const toggle = fixture.debugElement.query(By.css('button'))
1761
- .nativeElement;
1762
-
1763
- expect(toggle.classList).toContain('owl-dt-trigger-disabled');
1764
- expect(
1765
- document.querySelector('owl-date-time-container')
1766
- ).toBeNull();
1767
-
1768
- dispatchMouseEvent(toggle, 'click');
1769
- fixture.detectChanges();
1770
-
1771
- expect(
1772
- document.querySelector('owl-date-time-container')
1773
- ).toBeNull();
1774
- });
1775
-
1776
- it('should not open the picker when trigger clicked if input is disabled', () => {
1777
- expect(testComponent.dateTimePicker.disabled).toBe(false);
1778
-
1779
- testComponent.dateTimePickerInput.disabled = true;
1780
- fixture.detectChanges();
1781
- const toggle = fixture.debugElement.query(By.css('button'))
1782
- .nativeElement;
1783
-
1784
- expect(toggle.classList).toContain('owl-dt-trigger-disabled');
1785
- expect(
1786
- document.querySelector('owl-date-time-container')
1787
- ).toBeNull();
1788
-
1789
- dispatchMouseEvent(toggle, 'click');
1790
- fixture.detectChanges();
1791
-
1792
- expect(
1793
- document.querySelector('owl-date-time-container')
1794
- ).toBeNull();
1795
- });
1796
- });
1797
-
1798
- describe('DateTimePicker with min and max validation', () => {
1799
- let fixture: ComponentFixture<
1800
- DateTimePickerWithMinAndMaxValidationComponent
1801
- >;
1802
- let testComponent: DateTimePickerWithMinAndMaxValidationComponent;
1803
- let minMoment;
1804
- let maxMoment;
1805
-
1806
- beforeEach(fakeAsync(() => {
1807
- fixture = createComponent(
1808
- DateTimePickerWithMinAndMaxValidationComponent,
1809
- [OwlNativeDateTimeModule]
1810
- );
1811
- fixture.detectChanges();
1812
-
1813
- testComponent = fixture.componentInstance;
1814
-
1815
- minMoment = new Date(2010, JAN, 1, 0, 30, 30);
1816
- maxMoment = new Date(2020, JAN, 1, 23, 30, 30);
1817
- testComponent.min = minMoment;
1818
- testComponent.max = maxMoment;
1819
- fixture.detectChanges();
1820
- }));
1821
-
1822
- afterEach(fakeAsync(() => {
1823
- testComponent.dateTimePicker.close();
1824
- fixture.detectChanges();
1825
- flush();
1826
- }));
1827
-
1828
- it('should use min and max dates specified by the input', () => {
1829
- expect(testComponent.dateTimePicker.minDateTime).toEqual(
1830
- minMoment
1831
- );
1832
- expect(testComponent.dateTimePicker.maxDateTime).toEqual(
1833
- maxMoment
1834
- );
1835
- });
1836
-
1837
- it('should mark invalid when value is before minMoment', fakeAsync(() => {
1838
- testComponent.date = new Date(2009, DEC, 31);
1839
- fixture.detectChanges();
1840
- flush();
1841
- fixture.detectChanges();
1842
-
1843
- expect(
1844
- fixture.debugElement.query(By.css('input')).nativeElement
1845
- .classList
1846
- ).toContain('ng-invalid');
1847
- }));
1848
-
1849
- it('should mark invalid when value is after maxMoment', fakeAsync(() => {
1850
- testComponent.date = new Date(2020, JAN, 2);
1851
- fixture.detectChanges();
1852
- flush();
1853
-
1854
- fixture.detectChanges();
1855
-
1856
- expect(
1857
- fixture.debugElement.query(By.css('input')).nativeElement
1858
- .classList
1859
- ).toContain('ng-invalid');
1860
- }));
1861
-
1862
- it('should not mark invalid when value equals minMoment', fakeAsync(() => {
1863
- testComponent.date = new Date(minMoment);
1864
- fixture.detectChanges();
1865
- flush();
1866
- fixture.detectChanges();
1867
-
1868
- expect(
1869
- fixture.debugElement.query(By.css('input')).nativeElement
1870
- .classList
1871
- ).not.toContain('ng-invalid');
1872
- }));
1873
-
1874
- it('should not mark invalid when value equals maxMoment', fakeAsync(() => {
1875
- testComponent.date = new Date(maxMoment);
1876
- fixture.detectChanges();
1877
- flush();
1878
- fixture.detectChanges();
1879
-
1880
- expect(
1881
- fixture.debugElement.query(By.css('input')).nativeElement
1882
- .classList
1883
- ).not.toContain('ng-invalid');
1884
- }));
1885
-
1886
- it('should not mark invalid when value is between minMoment and maxMoment', fakeAsync(() => {
1887
- testComponent.date = new Date(2010, JAN, 2);
1888
- fixture.detectChanges();
1889
- flush();
1890
- fixture.detectChanges();
1891
-
1892
- expect(
1893
- fixture.debugElement.query(By.css('input')).nativeElement
1894
- .classList
1895
- ).not.toContain('ng-invalid');
1896
- }));
1897
-
1898
- it('should disable all decrease-time buttons when value equals minMoment', fakeAsync(() => {
1899
- testComponent.date = new Date(minMoment);
1900
- fixture.detectChanges();
1901
- flush();
1902
- fixture.detectChanges();
1903
-
1904
- testComponent.dateTimePicker.open();
1905
- fixture.detectChanges();
1906
- flush();
1907
- fixture.detectChanges();
1908
- const calendarDebugElement = fixture.debugElement.query(
1909
- By.directive(OwlDateTimeContainerComponent)
1910
- );
1911
- const calendarElement = calendarDebugElement.nativeElement;
1912
-
1913
- const decreaseHourBtn = calendarElement.querySelector(
1914
- '[aria-label="Minus a hour"]'
1915
- );
1916
- const decreaseMinuteBtn = calendarElement.querySelector(
1917
- '[aria-label="Minus a minute"]'
1918
- );
1919
- const decreaseSecondBtn = calendarElement.querySelector(
1920
- '[aria-label="Minus a second"]'
1921
- );
1922
- expect(decreaseHourBtn.hasAttribute('disabled')).toBe(true);
1923
- expect(decreaseMinuteBtn.hasAttribute('disabled')).toBe(true);
1924
- expect(decreaseSecondBtn.hasAttribute('disabled')).toBe(true);
1925
- }));
1926
-
1927
- it('should disable all increase-time buttons when value equals maxMoment', fakeAsync(() => {
1928
- testComponent.date = new Date(maxMoment);
1929
- fixture.detectChanges();
1930
- flush();
1931
- fixture.detectChanges();
1932
-
1933
- testComponent.dateTimePicker.open();
1934
- fixture.detectChanges();
1935
- flush();
1936
- fixture.detectChanges();
1937
- const calendarDebugElement = fixture.debugElement.query(
1938
- By.directive(OwlDateTimeContainerComponent)
1939
- );
1940
- const calendarElement = calendarDebugElement.nativeElement;
1941
-
1942
- const increaseHourBtn = calendarElement.querySelector(
1943
- '[aria-label="Add a hour"]'
1944
- );
1945
- const increaseMinuteBtn = calendarElement.querySelector(
1946
- '[aria-label="Add a minute"]'
1947
- );
1948
- const increaseSecondBtn = calendarElement.querySelector(
1949
- '[aria-label="Add a second"]'
1950
- );
1951
- expect(increaseHourBtn.hasAttribute('disabled')).toBe(true);
1952
- expect(increaseMinuteBtn.hasAttribute('disabled')).toBe(true);
1953
- expect(increaseSecondBtn.hasAttribute('disabled')).toBe(true);
1954
- }));
1955
- });
1956
-
1957
- describe('DateTimePicker with filter validation', () => {
1958
- let fixture: ComponentFixture<DateTimePickerWithFilterValidationComponent>;
1959
- let testComponent: DateTimePickerWithFilterValidationComponent;
1960
-
1961
- beforeEach(fakeAsync(() => {
1962
- fixture = createComponent(DateTimePickerWithFilterValidationComponent, [
1963
- OwlNativeDateTimeModule
1964
- ]);
1965
- fixture.detectChanges();
1966
- testComponent = fixture.componentInstance;
1967
- }));
1968
-
1969
- afterEach(fakeAsync(() => {
1970
- testComponent.dateTimePicker.close();
1971
- fixture.detectChanges();
1972
- flush();
1973
- }));
1974
-
1975
- it('should mark input invalid', fakeAsync(() => {
1976
- testComponent.date = new Date(2017, JAN, 1);
1977
- fixture.detectChanges();
1978
- flush();
1979
- fixture.detectChanges();
1980
-
1981
- expect(
1982
- fixture.debugElement.query(By.css('input')).nativeElement
1983
- .classList
1984
- ).toContain('ng-invalid');
1985
-
1986
- testComponent.date = new Date(2017, JAN, 2);
1987
- fixture.detectChanges();
1988
- flush();
1989
- fixture.detectChanges();
1990
-
1991
- expect(
1992
- fixture.debugElement.query(By.css('input')).nativeElement
1993
- .classList
1994
- ).not.toContain('ng-invalid');
1995
- }));
1996
-
1997
- it('should disable filtered calendar cells', fakeAsync(() => {
1998
- testComponent.date = new Date(2017, JAN, 3);
1999
- fixture.detectChanges();
2000
- flush();
2001
- fixture.detectChanges();
2002
-
2003
- testComponent.dateTimePicker.open();
2004
- fixture.detectChanges();
2005
- flush();
2006
- fixture.detectChanges();
2007
-
2008
- expect(
2009
- document.querySelector('owl-date-time-container')
2010
- ).not.toBeNull();
2011
-
2012
- const cellOne = document.querySelector(
2013
- '[aria-label="January 1, 2017"]'
2014
- );
2015
- const cellTwo = document.querySelector(
2016
- '[aria-label="January 2, 2017"]'
2017
- );
2018
-
2019
- expect(cellOne.classList).toContain(
2020
- 'owl-dt-calendar-cell-disabled'
2021
- );
2022
- expect(cellTwo.classList).not.toContain(
2023
- 'owl-dt-calendar-cell-disabled'
2024
- );
2025
- }));
2026
- });
2027
-
2028
- describe('DateTimePicker with change and input events', () => {
2029
- let fixture: ComponentFixture<
2030
- DateTimePickerWithChangeAndInputEventsComponent
2031
- >;
2032
- let testComponent: DateTimePickerWithChangeAndInputEventsComponent;
2033
- let inputEl: HTMLInputElement;
2034
-
2035
- beforeEach(fakeAsync(() => {
2036
- fixture = createComponent(
2037
- DateTimePickerWithChangeAndInputEventsComponent,
2038
- [OwlNativeDateTimeModule]
2039
- );
2040
- fixture.detectChanges();
2041
- testComponent = fixture.componentInstance;
2042
- inputEl = fixture.debugElement.query(By.css('input'))
2043
- .nativeElement;
2044
-
2045
- spyOn(testComponent, 'handleChange');
2046
- spyOn(testComponent, 'handleInput');
2047
- spyOn(testComponent, 'handleDateTimeChange');
2048
- spyOn(testComponent, 'handleDateTimeInput');
2049
- }));
2050
-
2051
- afterEach(fakeAsync(() => {
2052
- testComponent.dateTimePicker.close();
2053
- fixture.detectChanges();
2054
- flush();
2055
- }));
2056
-
2057
- it('should fire input and dateTimeInput events when user types input', () => {
2058
- expect(testComponent.handleChange).not.toHaveBeenCalled();
2059
- expect(
2060
- testComponent.handleDateTimeChange
2061
- ).not.toHaveBeenCalled();
2062
- expect(testComponent.handleInput).not.toHaveBeenCalled();
2063
- expect(
2064
- testComponent.handleDateTimeInput
2065
- ).not.toHaveBeenCalled();
2066
-
2067
- inputEl.value = '2001-01-01';
2068
- dispatchFakeEvent(inputEl, 'input');
2069
- fixture.detectChanges();
2070
-
2071
- expect(testComponent.handleChange).not.toHaveBeenCalled();
2072
- expect(
2073
- testComponent.handleDateTimeChange
2074
- ).not.toHaveBeenCalled();
2075
- expect(testComponent.handleInput).toHaveBeenCalled();
2076
- expect(testComponent.handleDateTimeInput).toHaveBeenCalled();
2077
- });
2078
-
2079
- it('should fire change and dateTimeChange events when user commits typed input', () => {
2080
- expect(testComponent.handleChange).not.toHaveBeenCalled();
2081
- expect(
2082
- testComponent.handleDateTimeChange
2083
- ).not.toHaveBeenCalled();
2084
- expect(testComponent.handleInput).not.toHaveBeenCalled();
2085
- expect(
2086
- testComponent.handleDateTimeInput
2087
- ).not.toHaveBeenCalled();
2088
-
2089
- dispatchFakeEvent(inputEl, 'change');
2090
- fixture.detectChanges();
2091
-
2092
- expect(testComponent.handleChange).toHaveBeenCalled();
2093
- expect(testComponent.handleDateTimeChange).toHaveBeenCalled();
2094
- expect(testComponent.handleInput).not.toHaveBeenCalled();
2095
- expect(
2096
- testComponent.handleDateTimeInput
2097
- ).not.toHaveBeenCalled();
2098
- });
2099
-
2100
- it('should fire dateTimeChange and dateTimeInput events when user selects calendar date', fakeAsync(() => {
2101
- expect(testComponent.handleChange).not.toHaveBeenCalled();
2102
- expect(
2103
- testComponent.handleDateTimeChange
2104
- ).not.toHaveBeenCalled();
2105
- expect(testComponent.handleInput).not.toHaveBeenCalled();
2106
- expect(
2107
- testComponent.handleDateTimeInput
2108
- ).not.toHaveBeenCalled();
2109
-
2110
- testComponent.dateTimePicker.open();
2111
- fixture.detectChanges();
2112
-
2113
- expect(
2114
- document.querySelector('owl-date-time-container')
2115
- ).not.toBeNull();
2116
-
2117
- const cells = document.querySelectorAll(
2118
- '.owl-dt-calendar-cell'
2119
- );
2120
- dispatchMouseEvent(cells[0], 'click');
2121
- fixture.detectChanges();
2122
- flush();
2123
- testComponent.dateTimePicker.confirmSelect();
2124
- fixture.detectChanges();
2125
- flush();
2126
- fixture.detectChanges();
2127
-
2128
- expect(testComponent.handleChange).not.toHaveBeenCalled();
2129
- expect(testComponent.handleDateTimeChange).toHaveBeenCalled();
2130
- expect(testComponent.handleInput).not.toHaveBeenCalled();
2131
- expect(testComponent.handleDateTimeInput).toHaveBeenCalled();
2132
- }));
2133
-
2134
- it('should fire dateTimeChange and dateTimeInput events when user change hour', fakeAsync(() => {
2135
- expect(testComponent.handleChange).not.toHaveBeenCalled();
2136
- expect(
2137
- testComponent.handleDateTimeChange
2138
- ).not.toHaveBeenCalled();
2139
- expect(testComponent.handleInput).not.toHaveBeenCalled();
2140
- expect(
2141
- testComponent.handleDateTimeInput
2142
- ).not.toHaveBeenCalled();
2143
-
2144
- testComponent.dateTimePicker.open();
2145
- fixture.detectChanges();
2146
-
2147
- expect(
2148
- document.querySelector('owl-date-time-container')
2149
- ).not.toBeNull();
2150
-
2151
- const increaseHourBtn = document.querySelector(
2152
- '[aria-label="Add a hour"]'
2153
- );
2154
- dispatchMouseEvent(increaseHourBtn, 'click');
2155
- fixture.detectChanges();
2156
- flush();
2157
- testComponent.dateTimePicker.confirmSelect();
2158
- fixture.detectChanges();
2159
- flush();
2160
- fixture.detectChanges();
2161
-
2162
- testComponent.dateTimePicker.open();
2163
- fixture.detectChanges();
2164
-
2165
- const decreaseHourBtn = document.querySelector(
2166
- '[aria-label="Minus a hour"]'
2167
- );
2168
- dispatchMouseEvent(decreaseHourBtn, 'click');
2169
- fixture.detectChanges();
2170
- flush();
2171
- testComponent.dateTimePicker.confirmSelect();
2172
- fixture.detectChanges();
2173
- flush();
2174
- fixture.detectChanges();
2175
-
2176
- expect(testComponent.handleChange).not.toHaveBeenCalled();
2177
- expect(
2178
- testComponent.handleDateTimeChange
2179
- ).toHaveBeenCalledTimes(2);
2180
- expect(testComponent.handleInput).not.toHaveBeenCalled();
2181
- expect(testComponent.handleDateTimeInput).toHaveBeenCalledTimes(
2182
- 2
2183
- );
2184
- }));
2185
-
2186
- it('should fire dateTimeChange and dateTimeInput events when user change minute', fakeAsync(() => {
2187
- expect(testComponent.handleChange).not.toHaveBeenCalled();
2188
- expect(
2189
- testComponent.handleDateTimeChange
2190
- ).not.toHaveBeenCalled();
2191
- expect(testComponent.handleInput).not.toHaveBeenCalled();
2192
- expect(
2193
- testComponent.handleDateTimeInput
2194
- ).not.toHaveBeenCalled();
2195
-
2196
- testComponent.dateTimePicker.open();
2197
- fixture.detectChanges();
2198
-
2199
- expect(
2200
- document.querySelector('owl-date-time-container')
2201
- ).not.toBeNull();
2202
-
2203
- const increaseMinuteBtn = document.querySelector(
2204
- '[aria-label="Add a minute"]'
2205
- );
2206
- dispatchMouseEvent(increaseMinuteBtn, 'click');
2207
- fixture.detectChanges();
2208
- flush();
2209
- testComponent.dateTimePicker.confirmSelect();
2210
- fixture.detectChanges();
2211
- flush();
2212
- fixture.detectChanges();
2213
-
2214
- testComponent.dateTimePicker.open();
2215
- fixture.detectChanges();
2216
-
2217
- const decreaseMinuteBtn = document.querySelector(
2218
- '[aria-label="Minus a minute"]'
2219
- );
2220
- dispatchMouseEvent(decreaseMinuteBtn, 'click');
2221
- fixture.detectChanges();
2222
- flush();
2223
- testComponent.dateTimePicker.confirmSelect();
2224
- fixture.detectChanges();
2225
- flush();
2226
- fixture.detectChanges();
2227
-
2228
- expect(testComponent.handleChange).not.toHaveBeenCalled();
2229
- expect(
2230
- testComponent.handleDateTimeChange
2231
- ).toHaveBeenCalledTimes(2);
2232
- expect(testComponent.handleInput).not.toHaveBeenCalled();
2233
- expect(testComponent.handleDateTimeInput).toHaveBeenCalledTimes(
2234
- 2
2235
- );
2236
- }));
2237
-
2238
- it('should fire dateTimeChange and dateTimeInput events when user change second', fakeAsync(() => {
2239
- expect(testComponent.handleChange).not.toHaveBeenCalled();
2240
- expect(
2241
- testComponent.handleDateTimeChange
2242
- ).not.toHaveBeenCalled();
2243
- expect(testComponent.handleInput).not.toHaveBeenCalled();
2244
- expect(
2245
- testComponent.handleDateTimeInput
2246
- ).not.toHaveBeenCalled();
2247
-
2248
- testComponent.dateTimePicker.open();
2249
- fixture.detectChanges();
2250
-
2251
- expect(
2252
- document.querySelector('owl-date-time-container')
2253
- ).not.toBeNull();
2254
-
2255
- const increaseSecondBtn = document.querySelector(
2256
- '[aria-label="Add a second"]'
2257
- );
2258
- dispatchMouseEvent(increaseSecondBtn, 'click');
2259
- fixture.detectChanges();
2260
- flush();
2261
- testComponent.dateTimePicker.confirmSelect();
2262
- fixture.detectChanges();
2263
- flush();
2264
- fixture.detectChanges();
2265
-
2266
- testComponent.dateTimePicker.open();
2267
- fixture.detectChanges();
2268
-
2269
- const decreaseSecondBtn = document.querySelector(
2270
- '[aria-label="Minus a second"]'
2271
- );
2272
- dispatchMouseEvent(decreaseSecondBtn, 'click');
2273
- fixture.detectChanges();
2274
- flush();
2275
- testComponent.dateTimePicker.confirmSelect();
2276
- fixture.detectChanges();
2277
- flush();
2278
- fixture.detectChanges();
2279
-
2280
- expect(testComponent.handleChange).not.toHaveBeenCalled();
2281
- expect(
2282
- testComponent.handleDateTimeChange
2283
- ).toHaveBeenCalledTimes(2);
2284
- expect(testComponent.handleInput).not.toHaveBeenCalled();
2285
- expect(testComponent.handleDateTimeInput).toHaveBeenCalledTimes(
2286
- 2
2287
- );
2288
- }));
2289
-
2290
- it('should NOT fire the dateTimeInput event if the value has not changed', () => {
2291
- expect(
2292
- testComponent.handleDateTimeInput
2293
- ).not.toHaveBeenCalled();
2294
-
2295
- inputEl.value = '12/12/2012';
2296
- dispatchFakeEvent(inputEl, 'input');
2297
- fixture.detectChanges();
2298
-
2299
- expect(testComponent.handleDateTimeInput).toHaveBeenCalledTimes(
2300
- 1
2301
- );
2302
- dispatchFakeEvent(inputEl, 'input');
2303
- fixture.detectChanges();
2304
-
2305
- expect(testComponent.handleDateTimeInput).toHaveBeenCalledTimes(
2306
- 1
2307
- );
2308
- });
2309
- });
2310
-
2311
- describe('DateTimePicker with ISO strings', () => {
2312
- let fixture: ComponentFixture<DateTimePickerWithISOStringsComponent>;
2313
- let testComponent: DateTimePickerWithISOStringsComponent;
2314
-
2315
- beforeEach(fakeAsync(() => {
2316
- fixture = createComponent(DateTimePickerWithISOStringsComponent, [
2317
- OwlNativeDateTimeModule
2318
- ]);
2319
- fixture.detectChanges();
2320
- testComponent = fixture.componentInstance;
2321
- }));
2322
-
2323
- afterEach(fakeAsync(() => {
2324
- testComponent.dateTimePicker.close();
2325
- fixture.detectChanges();
2326
- flush();
2327
- }));
2328
-
2329
- it('should coerce ISO strings', fakeAsync(() => {
2330
- expect(() => fixture.detectChanges()).not.toThrow();
2331
- flush();
2332
- fixture.detectChanges();
2333
-
2334
- expect(testComponent.dateTimePicker.startAt).toEqual(
2335
- new Date(2017, JUL, 1)
2336
- );
2337
- expect(testComponent.dateTimePickerInput.value).toEqual(
2338
- new Date(2017, JUN, 1)
2339
- );
2340
- expect(testComponent.dateTimePickerInput.min).toEqual(
2341
- new Date(2017, JAN, 1)
2342
- );
2343
- expect(testComponent.dateTimePickerInput.max).toEqual(
2344
- new Date(2017, DEC, 31)
2345
- );
2346
- }));
2347
- });
2348
-
2349
- describe('DateTimePicker with events', () => {
2350
- let fixture: ComponentFixture<DateTimePickerWithEventsComponent>;
2351
- let testComponent: DateTimePickerWithEventsComponent;
2352
-
2353
- beforeEach(fakeAsync(() => {
2354
- fixture = createComponent(DateTimePickerWithEventsComponent, [
2355
- OwlNativeDateTimeModule
2356
- ]);
2357
- fixture.detectChanges();
2358
- testComponent = fixture.componentInstance;
2359
- }));
2360
-
2361
- afterEach(fakeAsync(() => {
2362
- testComponent.dateTimePicker.close();
2363
- fixture.detectChanges();
2364
- flush();
2365
- }));
2366
-
2367
- it('should dispatch an event when a dateTimePicker is opened', fakeAsync(() => {
2368
- testComponent.dateTimePicker.open();
2369
- fixture.detectChanges();
2370
- flush();
2371
-
2372
- expect(testComponent.openedSpy).toHaveBeenCalled();
2373
- }));
2374
-
2375
- it('should dispatch an event when a dateTimePicker is closed', fakeAsync(() => {
2376
- testComponent.dateTimePicker.open();
2377
- fixture.detectChanges();
2378
- flush();
2379
-
2380
- testComponent.dateTimePicker.close();
2381
- flush();
2382
- fixture.detectChanges();
2383
-
2384
- expect(testComponent.closedSpy).toHaveBeenCalled();
2385
- }));
2386
- });
2387
- });
2388
-
2389
- describe('with missing DateTimeAdapter and OWL_DATE_TIME_FORMATS', () => {
2390
- it('should throw when created', () => {
2391
- expect(() => createComponent(StandardDateTimePickerComponent)).toThrowError(
2392
- /OwlDateTimePicker: No provider found for .*/
2393
- );
2394
- });
2395
- });
2396
- });
2397
-
2398
- @Component({
2399
- standalone: false,
2400
- template: `
2401
- <input [owlDateTime]="dt" [value]="date">
2402
- <owl-date-time [opened]="opened"
2403
- [disabled]="disabled"
2404
- [pickerType]="pickerType"
2405
- [pickerMode]="pickerMode" #dt></owl-date-time>
2406
- `
2407
- })
2408
- class StandardDateTimePickerComponent {
2409
- date: Date | null = new Date(2020, JAN, 1);
2410
- pickerType = 'both';
2411
- pickerMode = 'popup';
2412
- opened = false;
2413
- disabled = false;
2414
- @ViewChild('dt', { static: true })
2415
- dateTimePicker: OwlDateTimeComponent<Date>;
2416
- @ViewChild(OwlDateTimeInputDirective, { static: true })
2417
- dateTimePickerInput: OwlDateTimeInputDirective<Date>;
2418
- }
2419
-
2420
- @Component({
2421
- standalone: false,
2422
- template: `
2423
- <input [owlDateTime]="dt" [selectMode]="selectMode" [values]="dates">
2424
- <owl-date-time [startAt]="startAt" [endAt]="endAt"
2425
- [pickerType]="pickerType" #dt></owl-date-time>
2426
- `
2427
- })
2428
- class RangeDateTimePickerComponent {
2429
- dates: Date[] | null = [new Date(2020, JAN, 1), new Date(2020, FEB, 1)];
2430
- selectMode = 'range';
2431
- pickerType = 'both';
2432
- startAt = new Date(2020, JAN, 1);
2433
- endAt = new Date(2020, JAN, 2);
2434
- @ViewChild('dt', { static: true })
2435
- dateTimePicker: OwlDateTimeComponent<Date>;
2436
- @ViewChild(OwlDateTimeInputDirective, { static: true })
2437
- dateTimePickerInput: OwlDateTimeInputDirective<Date>;
2438
- }
2439
-
2440
- @Component({
2441
- standalone: false,
2442
- template: `
2443
- <input [owlDateTime]="dt">
2444
- <input [owlDateTime]="dt">
2445
- <owl-date-time #dt></owl-date-time>
2446
- `
2447
- })
2448
- class MultiInputDateTimePickerComponent { }
2449
-
2450
- @Component({
2451
- standalone: false,
2452
- template: `
2453
- <owl-date-time #dt></owl-date-time>
2454
- `
2455
- })
2456
- class NoInputDateTimePickerComponent {
2457
- @ViewChild('dt', { static: true })
2458
- dateTimePicker: OwlDateTimeComponent<Date>;
2459
- }
2460
-
2461
- @Component({
2462
- standalone: false,
2463
- template: `
2464
- <input [owlDateTime]="dt" [value]="date">
2465
- <owl-date-time #dt [startAt]="startDate"></owl-date-time>
2466
- `
2467
- })
2468
- class DateTimePickerWithStartAtComponent {
2469
- date = new Date(2020, JAN, 1);
2470
- startDate = new Date(2010, JAN, 1);
2471
- @ViewChild('dt', { static: true })
2472
- dateTimePicker: OwlDateTimeComponent<Date>;
2473
- }
2474
-
2475
- @Component({
2476
- standalone: false,
2477
- template: `
2478
- <input [owlDateTime]="dt" [value]="date">
2479
- <owl-date-time #dt [startView]="startView"
2480
- (monthSelected)="onMonthSelection()"
2481
- (yearSelected)="onYearSelection()"></owl-date-time>
2482
- `
2483
- })
2484
- class DateTimePickerWithStartViewComponent {
2485
- date = new Date(2020, JAN, 1);
2486
- startView = 'month';
2487
- @ViewChild('dt', { static: true })
2488
- dateTimePicker: OwlDateTimeComponent<Date>;
2489
-
2490
- onMonthSelection() { }
2491
-
2492
- onYearSelection() { }
2493
- }
2494
-
2495
- @Component({
2496
- standalone: false,
2497
- template: `
2498
- <input [(ngModel)]="moment" [selectMode]="selectMode" [owlDateTime]="dt">
2499
- <owl-date-time #dt></owl-date-time>
2500
- `
2501
- })
2502
- class DateTimePickerWithNgModelComponent {
2503
- moment: Date[] | Date | null = null;
2504
- selectMode = 'single';
2505
- @ViewChild('dt', { static: true })
2506
- dateTimePicker: OwlDateTimeComponent<Date>;
2507
- @ViewChild(OwlDateTimeInputDirective, { static: true })
2508
- dateTimePickerInput: OwlDateTimeInputDirective<Date>;
2509
- }
2510
-
2511
- @Component({
2512
- standalone: false,
2513
- template: `
2514
- <input [formControl]="formControl"
2515
- [owlDateTime]="dt"
2516
- [owlDateTimeTrigger]="dt">
2517
- <owl-date-time #dt></owl-date-time>
2518
- `
2519
- })
2520
- class DateTimePickerWithFormControlComponent {
2521
- formControl = new UntypedFormControl();
2522
- @ViewChild('dt', { static: true })
2523
- dateTimePicker: OwlDateTimeComponent<Date>;
2524
- @ViewChild(OwlDateTimeInputDirective, { static: true })
2525
- dateTimePickerInput: OwlDateTimeInputDirective<Date>;
2526
- @ViewChild(OwlDateTimeTriggerDirective, { static: true })
2527
- dateTimePickerToggle: OwlDateTimeTriggerDirective<Date>;
2528
- }
2529
-
2530
- @Component({
2531
- standalone: false,
2532
- template: `
2533
- <input [owlDateTime]="dt">
2534
- <button [owlDateTimeTrigger]="dt">Icon</button>
2535
- <owl-date-time #dt></owl-date-time>
2536
- `
2537
- })
2538
- class DateTimePickerWithTriggerComponent {
2539
- @ViewChild('dt', { static: true })
2540
- dateTimePicker: OwlDateTimeComponent<Date>;
2541
- @ViewChild(OwlDateTimeInputDirective, { static: true })
2542
- dateTimePickerInput: OwlDateTimeInputDirective<Date>;
2543
- }
2544
-
2545
- @Component({
2546
- standalone: false,
2547
- template: `
2548
- <input [(ngModel)]="date" [min]="min" [max]="max"
2549
- [owlDateTime]="dt"
2550
- [owlDateTimeTrigger]="dt">
2551
- <owl-date-time [showSecondsTimer]="true" #dt></owl-date-time>
2552
- `
2553
- })
2554
- class DateTimePickerWithMinAndMaxValidationComponent {
2555
- @ViewChild('dt', { static: true })
2556
- dateTimePicker: OwlDateTimeComponent<Date>;
2557
- @ViewChild(OwlDateTimeInputDirective, { static: true })
2558
- dateTimePickerInput: OwlDateTimeInputDirective<Date>;
2559
- @ViewChild(OwlDateTimeTriggerDirective, { static: true })
2560
- dateTimePickerToggle: OwlDateTimeTriggerDirective<Date>;
2561
-
2562
- date: Date | null;
2563
- min: Date;
2564
- max: Date;
2565
- }
2566
-
2567
- @Component({
2568
- standalone: false,
2569
- template: `
2570
- <input [(ngModel)]="date"
2571
- [owlDateTimeFilter]="filter"
2572
- [owlDateTime]="dt"
2573
- [owlDateTimeTrigger]="dt">
2574
- <owl-date-time [showSecondsTimer]="true" #dt></owl-date-time>
2575
- `
2576
- })
2577
- class DateTimePickerWithFilterValidationComponent {
2578
- @ViewChild('dt', { static: true })
2579
- dateTimePicker: OwlDateTimeComponent<Date>;
2580
- @ViewChild(OwlDateTimeInputDirective, { static: true })
2581
- dateTimePickerInput: OwlDateTimeInputDirective<Date>;
2582
- @ViewChild(OwlDateTimeTriggerDirective, { static: true })
2583
- dateTimePickerToggle: OwlDateTimeTriggerDirective<Date>;
2584
- date: Date;
2585
- filter = (date: Date) => date.getDate() !== 1;
2586
- }
2587
-
2588
- @Component({
2589
- standalone: false,
2590
- template: `
2591
- <input [owlDateTime]="dt"
2592
- [owlDateTimeTrigger]="dt"
2593
- (change)="handleChange()"
2594
- (input)="handleInput()"
2595
- (dateTimeChange)="handleDateTimeChange()"
2596
- (dateTimeInput)="handleDateTimeInput()">
2597
- <owl-date-time [showSecondsTimer]="true" #dt></owl-date-time>
2598
- `
2599
- })
2600
- class DateTimePickerWithChangeAndInputEventsComponent {
2601
- @ViewChild('dt', { static: true })
2602
- dateTimePicker: OwlDateTimeComponent<Date>;
2603
- @ViewChild(OwlDateTimeInputDirective, { static: true })
2604
- dateTimePickerInput: OwlDateTimeInputDirective<Date>;
2605
- @ViewChild(OwlDateTimeTriggerDirective, { static: true })
2606
- dateTimePickerToggle: OwlDateTimeTriggerDirective<Date>;
2607
-
2608
- handleChange() { }
2609
-
2610
- handleInput() { }
2611
-
2612
- handleDateTimeChange() { }
2613
-
2614
- handleDateTimeInput() { }
2615
- }
2616
-
2617
- @Component({
2618
- standalone: false,
2619
- template: `
2620
- <input [owlDateTime]="dt" [(ngModel)]="value" [min]="min" [max]="max">
2621
- <owl-date-time #dt [startAt]="startAt"></owl-date-time>
2622
- `
2623
- })
2624
- class DateTimePickerWithISOStringsComponent {
2625
- value = new Date(2017, JUN, 1).toISOString();
2626
- min = new Date(2017, JAN, 1).toISOString();
2627
- max = new Date(2017, DEC, 31).toISOString();
2628
- startAt = new Date(2017, JUL, 1).toISOString();
2629
- @ViewChild('dt', { static: true })
2630
- dateTimePicker: OwlDateTimeComponent<Date>;
2631
- @ViewChild(OwlDateTimeInputDirective, { static: true })
2632
- dateTimePickerInput: OwlDateTimeInputDirective<Date>;
2633
- }
2634
-
2635
- @Component({
2636
- standalone: false,
2637
- template: `
2638
- <input [(ngModel)]="selected" [owlDateTime]="dt">
2639
- <owl-date-time (afterPickerOpen)="openedSpy()" (afterPickerClosed)="closedSpy()" #dt></owl-date-time>
2640
- `
2641
- })
2642
- class DateTimePickerWithEventsComponent {
2643
- selected: Date | null = null;
2644
- openedSpy = jasmine.createSpy('opened spy');
2645
- closedSpy = jasmine.createSpy('closed spy');
2646
- @ViewChild('dt', { static: true })
2647
- dateTimePicker: OwlDateTimeComponent<Date>;
2648
- }