1
+ ///<reference types="jest" />
2
+
3
+ import * as React from "react" ;
4
+ import { mount , configure } from "enzyme" ;
5
+ import * as Adapter from 'enzyme-adapter-react-16' ;
6
+ import { DocumentLibraryBrowser } from "../../../src/controls/filePicker/controls/DocumentLibraryBrowser/DocumentLibraryBrowser" ;
7
+ import { MockFileBrowserService } from "../../mock/services/MockFileBrowserService" ;
8
+ import { assert } from "chai" ;
9
+ import { ILibrary } from "../../../src/services/FileBrowserService.types" ;
10
+
11
+ configure ( { adapter : new Adapter ( ) } ) ;
12
+
13
+ describe ( "<DocumentLibraryBrowser />" , ( ) => {
14
+ test ( "should load initial data" , async ( ) => {
15
+ let browserService = new MockFileBrowserService ( ) ;
16
+ browserService . getSiteMediaLibrariesResult = [ {
17
+ title : "Test library title" ,
18
+ absoluteUrl : "https://test.sharepoint.com/sites/test-site/TestLibrary" ,
19
+ serverRelativeUrl : "/sites/test-site/TestLibrary" ,
20
+ webRelativeUrl : "/sites/test-site/TestLibrary" ,
21
+ iconPath : "/sites/test-site/Assets/icon.png"
22
+ } ]
23
+ let documentLibraryBrowser = mount ( < DocumentLibraryBrowser
24
+ fileBrowserService = { browserService as any }
25
+ onOpenLibrary = { ( ) => {
26
+
27
+ } }
28
+ /> ) ;
29
+ assert . equal ( documentLibraryBrowser . getDOMNode ( ) . tagName , "SPINNER" ) ;
30
+
31
+ await documentLibraryBrowser . instance ( ) . componentDidMount ( ) ;
32
+ documentLibraryBrowser . update ( ) ;
33
+
34
+ assert . equal ( documentLibraryBrowser . getDOMNode ( ) . tagName , "DIV" ) ;
35
+ assert . deepEqual ( documentLibraryBrowser . instance ( ) . state . lists , browserService . getSiteMediaLibrariesResult ) ;
36
+ } ) ;
37
+ test ( "should render library title" , async ( ) => {
38
+ let browserService = new MockFileBrowserService ( ) ;
39
+ browserService . getSiteMediaLibrariesResult = [ {
40
+ title : "Test library title" ,
41
+ absoluteUrl : "https://test.sharepoint.com/sites/test-site/TestLibrary" ,
42
+ serverRelativeUrl : "/sites/test-site/TestLibrary" ,
43
+ webRelativeUrl : "/sites/test-site/TestLibrary" ,
44
+ iconPath : "/sites/test-site/Assets/icon.png"
45
+ } ]
46
+ let documentLibraryBrowser = mount ( < DocumentLibraryBrowser
47
+ fileBrowserService = { browserService as any }
48
+ onOpenLibrary = { ( ) => {
49
+
50
+ } }
51
+ /> ) ;
52
+ //@ts -ignore
53
+ let libraryTitle = documentLibraryBrowser . instance ( ) . _onRenderLibraryTile ( browserService . getSiteMediaLibrariesResult [ 0 ] , 0 ) ;
54
+ let iconControl = libraryTitle . props . children . props . children . props . children [ 0 ] ;
55
+ let buttonControl = libraryTitle . props . children . props . children . props . children [ 1 ] ;
56
+ assert . equal ( iconControl . type , "Image" ) ;
57
+ assert . equal ( buttonControl . type , "DefaultButton" ) ;
58
+ } ) ;
59
+ test ( "should call onOpenLibrary" , async ( ) => {
60
+ let asserted = false ;
61
+ let browserService = new MockFileBrowserService ( ) ;
62
+ browserService . getSiteMediaLibrariesResult = [ {
63
+ title : "Test library title" ,
64
+ absoluteUrl : "https://test.sharepoint.com/sites/test-site/TestLibrary" ,
65
+ serverRelativeUrl : "/sites/test-site/TestLibrary" ,
66
+ webRelativeUrl : "/sites/test-site/TestLibrary" ,
67
+ iconPath : "/sites/test-site/Assets/icon.png"
68
+ } ]
69
+ let documentLibraryBrowser = mount ( < DocumentLibraryBrowser
70
+ fileBrowserService = { browserService as any }
71
+ onOpenLibrary = { ( selectedLibrary : ILibrary ) => {
72
+ asserted = true ;
73
+ assert . deepEqual ( selectedLibrary , browserService . getSiteMediaLibrariesResult [ 0 ] ) ;
74
+ } }
75
+ /> ) ;
76
+ //@ts -ignore
77
+ documentLibraryBrowser . instance ( ) . _handleOpenLibrary ( browserService . getSiteMediaLibrariesResult [ 0 ] ) ;
78
+ assert . isTrue ( asserted ) ;
79
+ } ) ;
80
+ test ( "should _getItemCountForPage 0" , async ( ) => {
81
+ let browserService = new MockFileBrowserService ( ) ;
82
+ let documentLibraryBrowser = mount ( < DocumentLibraryBrowser
83
+ fileBrowserService = { browserService as any }
84
+ onOpenLibrary = { ( selectedLibrary : ILibrary ) => {
85
+ } }
86
+ /> ) ;
87
+ //@ts -ignore
88
+ documentLibraryBrowser . instance ( ) . _columnsCount = 4 ;
89
+ //@ts -ignore
90
+ assert . equal ( documentLibraryBrowser . instance ( ) . _getItemCountForPage ( 0 , {
91
+ width : 1000
92
+ } ) , 12 ) ;
93
+ } ) ;
94
+ } ) ;
0 commit comments