1+ import { assert } from 'chai'
2+ import * as fs from 'fs' ;
3+
4+ import { getClient , randomString } from "./test-helper"
5+ import { WorkbookWorksheet , WorkbookRange } from '@microsoft/microsoft-graph-types'
6+
7+ declare const describe , it ;
8+
9+ const ExcelFilename = `empty-spreadsheet-${ randomString ( ) } .xlsx` ;
10+
11+ describe ( 'Excel' , function ( ) {
12+ this . timeout ( 10 * 1000 ) ;
13+ it ( 'Uploads an Excel file to OneDrive' , function ( ) {
14+
15+ let file = fs . readFileSync ( './spec/types/empty-spreadsheet.xlsx' ) ;
16+ return getClient ( )
17+ . api ( `/me/drive/root/children/${ ExcelFilename } /content` )
18+ . put ( file ) ;
19+ } ) ;
20+
21+ it ( 'Lists the worksheets in an excel file' , function ( ) {
22+ return getClient ( )
23+ . api ( `/me/drive/root:/${ ExcelFilename } :/workbook/worksheets` )
24+ . get ( )
25+ . then ( ( res ) => {
26+ let worksheets = res . value as WorkbookWorksheet [ ] ;
27+ let sheet1 = worksheets [ 0 ] ;
28+ assert . isNumber ( sheet1 . position ) ;
29+ assert . isString ( sheet1 . visibility ) ;
30+ assert . isString ( sheet1 . id ) ;
31+ assert . isUndefined ( sheet1 [ 'random fake property that should be null' ] ) ;
32+ return Promise . resolve ( ) ;
33+ } )
34+ } )
35+
36+ it ( 'Updates workbook worksheet range' , function ( ) {
37+ let sampleData :WorkbookRange = {
38+ values : [
39+ [ 'cell a1' , 'cell a2' ] ,
40+ [ 'cell b1' , 'cell b2' ]
41+ ]
42+ } ;
43+ return getClient ( )
44+ . api ( `/me/drive/root:/${ ExcelFilename } :/workbook/worksheets/Sheet1/range(address='A1:B2')` )
45+ . patch ( sampleData )
46+ } )
47+
48+ it ( 'GETs the used range of the worksheet' , function ( ) {
49+ return getClient ( )
50+ . api ( `/me/drive/root:/${ ExcelFilename } :/workbook/worksheets/Sheet1/range/usedrange` )
51+ . get ( )
52+ . then ( ( res :WorkbookRange ) => {
53+ assert . isNumber ( res . cellCount ) ;
54+ assert . isString ( res . address ) ;
55+ assert . isUndefined ( res [ 'other prop' ] )
56+ } )
57+ } )
58+ } ) ;
0 commit comments