1
1
import { Component } from '@angular/core' ;
2
- import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2
+ import { TestBed } from '@angular/core/testing' ;
3
3
import { expect } from 'chai' ;
4
4
import { CalendarModule , DateAdapter } from '../src' ;
5
5
import { adapterFactory } from '../src/date-adapters/date-fns' ;
6
6
7
7
@Component ( {
8
8
template :
9
- '<button mwlCalendarPreviousView [view]="view" [(viewDate)]="viewDate">Previous</button>'
9
+ '<button mwlCalendarPreviousView [view]="view" [(viewDate)]="viewDate" [excludeDays]="excludeDays" >Previous</button>'
10
10
} )
11
11
class TestComponent {
12
12
public view : string ;
13
13
public viewDate : Date ;
14
+ excludeDays : number [ ] ;
14
15
}
15
16
16
17
describe ( 'calendarPreviousView directive' , ( ) => {
@@ -27,9 +28,7 @@ describe('calendarPreviousView directive', () => {
27
28
} ) ;
28
29
29
30
it ( 'should decrease the view date by 1 month' , ( ) => {
30
- const fixture : ComponentFixture < TestComponent > = TestBed . createComponent (
31
- TestComponent
32
- ) ;
31
+ const fixture = TestBed . createComponent < TestComponent > ( TestComponent ) ;
33
32
fixture . componentInstance . view = 'month' ;
34
33
fixture . componentInstance . viewDate = new Date ( '2017-02-28' ) ;
35
34
fixture . detectChanges ( ) ;
@@ -42,9 +41,7 @@ describe('calendarPreviousView directive', () => {
42
41
} ) ;
43
42
44
43
it ( 'should decrease the view date by 1 week' , ( ) => {
45
- const fixture : ComponentFixture < TestComponent > = TestBed . createComponent (
46
- TestComponent
47
- ) ;
44
+ const fixture = TestBed . createComponent < TestComponent > ( TestComponent ) ;
48
45
fixture . componentInstance . view = 'week' ;
49
46
fixture . componentInstance . viewDate = new Date ( '2017-01-28' ) ;
50
47
fixture . detectChanges ( ) ;
@@ -57,9 +54,7 @@ describe('calendarPreviousView directive', () => {
57
54
} ) ;
58
55
59
56
it ( 'should decrease the view date by 1 day' , ( ) => {
60
- const fixture : ComponentFixture < TestComponent > = TestBed . createComponent (
61
- TestComponent
62
- ) ;
57
+ const fixture = TestBed . createComponent < TestComponent > ( TestComponent ) ;
63
58
fixture . componentInstance . view = 'day' ;
64
59
fixture . componentInstance . viewDate = new Date ( '2017-01-28' ) ;
65
60
fixture . detectChanges ( ) ;
@@ -70,4 +65,18 @@ describe('calendarPreviousView directive', () => {
70
65
) ;
71
66
fixture . destroy ( ) ;
72
67
} ) ;
68
+
69
+ it ( 'should decrease the view date by 1 day, skipping weekends' , ( ) => {
70
+ const fixture = TestBed . createComponent < TestComponent > ( TestComponent ) ;
71
+ fixture . componentInstance . view = 'day' ;
72
+ fixture . componentInstance . viewDate = new Date ( '2018-06-18' ) ;
73
+ fixture . componentInstance . excludeDays = [ 0 , 6 ] ;
74
+ fixture . detectChanges ( ) ;
75
+ fixture . nativeElement . querySelector ( 'button' ) . click ( ) ;
76
+ fixture . detectChanges ( ) ;
77
+ expect ( fixture . componentInstance . viewDate ) . to . deep . equal (
78
+ new Date ( '2018-06-15' )
79
+ ) ;
80
+ fixture . destroy ( ) ;
81
+ } ) ;
73
82
} ) ;
0 commit comments