1
+ import '../playlist_edit_ctrl' ;
2
+ import { describe , beforeEach , it , sinon , expect , angularMocks } from 'test/lib/common' ;
3
+ import helpers from 'test/specs/helpers' ;
4
+
5
+ describe ( 'PlaylistEditCtrl' , function ( ) {
6
+ var ctx = new helpers . ControllerTestContext ( ) ;
7
+
8
+ var dashboards = [
9
+ {
10
+ id : 2 ,
11
+ title : 'dashboard: 2'
12
+ } ,
13
+ {
14
+ id : 3 ,
15
+ title : 'dashboard: 3'
16
+ }
17
+ ] ;
18
+
19
+ var playlistSrv = { } ;
20
+ var backendSrv = {
21
+ search : ( query ) => {
22
+ return ctx . $q . when ( dashboards ) ;
23
+ }
24
+ } ;
25
+
26
+ beforeEach ( angularMocks . module ( 'grafana.core' ) ) ;
27
+ beforeEach ( angularMocks . module ( 'grafana.controllers' ) ) ;
28
+ beforeEach ( angularMocks . module ( 'grafana.services' ) ) ;
29
+ beforeEach ( ctx . providePhase ( {
30
+ playlistSrv : playlistSrv ,
31
+ backendSrv : backendSrv ,
32
+ $route : { current : { params : { } } } ,
33
+ } ) ) ;
34
+
35
+ beforeEach ( ctx . createControllerPhase ( 'PlaylistEditCtrl' ) ) ;
36
+
37
+ beforeEach ( ( ) => {
38
+ ctx . scope . $digest ( ) ;
39
+ } ) ;
40
+
41
+ describe . only ( 'searchresult returns 2 dashboards' , function ( ) {
42
+ it ( 'found dashboard should be 2' , function ( ) {
43
+ expect ( ctx . scope . foundPlaylistItems . length ) . to . be ( 2 ) ;
44
+ } ) ;
45
+
46
+ it ( 'filtred dashboard should be 2' , function ( ) {
47
+ expect ( ctx . scope . filteredPlaylistItems . length ) . to . be ( 2 ) ;
48
+ } ) ;
49
+
50
+ describe ( 'adds one dashboard to playlist' , ( ) => {
51
+ beforeEach ( ( ) => {
52
+ ctx . scope . addPlaylistItem ( { id : 2 , title : 'dashboard: 2' } ) ;
53
+ } ) ;
54
+
55
+ it ( 'playlistitems should be increased by one' , ( ) => {
56
+ expect ( ctx . scope . playlistItems . length ) . to . be ( 1 ) ;
57
+ } ) ;
58
+
59
+ it ( 'filtred playlistitems should be reduced by one' , ( ) => {
60
+ expect ( ctx . scope . filteredPlaylistItems . length ) . to . be ( 1 ) ;
61
+ } ) ;
62
+
63
+ it ( 'found dashboard should be 2' , function ( ) {
64
+ expect ( ctx . scope . foundPlaylistItems . length ) . to . be ( 2 ) ;
65
+ } ) ;
66
+
67
+ describe ( 'removes one dashboard from playlist' , ( ) => {
68
+ beforeEach ( ( ) => {
69
+ ctx . scope . removePlaylistItem ( ctx . scope . playlistItems [ 0 ] ) ;
70
+ } ) ;
71
+
72
+ it ( 'playlistitems should be increased by one' , ( ) => {
73
+ expect ( ctx . scope . playlistItems . length ) . to . be ( 0 ) ;
74
+ } ) ;
75
+
76
+ it ( 'found dashboard should be 2' , function ( ) {
77
+ expect ( ctx . scope . foundPlaylistItems . length ) . to . be ( 2 ) ;
78
+ } ) ;
79
+
80
+ it ( 'filtred playlist should be reduced by one' , ( ) => {
81
+ expect ( ctx . scope . filteredPlaylistItems . length ) . to . be ( 2 ) ;
82
+ } ) ;
83
+ } ) ;
84
+ } ) ;
85
+ } ) ;
86
+ } ) ;
0 commit comments