Skip to content

Commit 01f1216

Browse files
author
Matt Mazzola
authored
Update to powerbi-models dependency to 0.9.1 (microsoft#49)
* Non-breaking update to powerbi-models dependency to 0.9.0 which has support for validateDashboardLoad. Update embed load to call abstract validate method which is provided by concrete Report and Dashboard classes. * Add type specific load and validation functions in the mockApp. * Update powerbi-models to 0.9.1 to include schema fix.
1 parent 5f699ca commit 01f1216

8 files changed

Lines changed: 105 additions & 70 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
},
7575
"dependencies": {
7676
"http-post-message": "^0.2.3",
77-
"powerbi-models": "^0.7.4",
77+
"powerbi-models": "^0.9.1",
7878
"powerbi-router": "^0.1.4",
7979
"window-post-message-proxy": "^0.2.4"
8080
},

src/dashboard.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class Dashboard extends embed.Embed implements IDashboardNode {
4040
*/
4141
constructor(service: service.Service, element: HTMLElement, config: embed.IEmbedConfiguration) {
4242
super(service, element, config);
43+
this.loadPath = "/dashboard/load";
4344
Array.prototype.push.apply(this.allowedEvents, Dashboard.allowedEvents);
4445
}
4546

@@ -79,4 +80,11 @@ export class Dashboard extends embed.Embed implements IDashboardNode {
7980

8081
return dashboardId;
8182
}
83+
84+
/**
85+
* Validate load configuration.
86+
*/
87+
validate(config: models.IDashboardLoadConfiguration): models.IError[] {
88+
return models.validateDashboardLoad(config);
89+
}
8290
}

src/embed.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface IEmbedConfiguration {
4040
filters?: models.IFilter[];
4141
}
4242

43-
export interface IInternalEmbedConfiguration extends models.ILoadConfiguration {
43+
export interface IInternalEmbedConfiguration extends models.IReportLoadConfiguration {
4444
uniqueId: string;
4545
type: string;
4646
embedUrl: string;
@@ -107,6 +107,11 @@ export abstract class Embed {
107107
*/
108108
config: IInternalEmbedConfiguration;
109109

110+
/**
111+
* Url used in the load request.
112+
*/
113+
loadPath: string;
114+
110115
/**
111116
* Creates an instance of Embed.
112117
*
@@ -162,25 +167,20 @@ export abstract class Embed {
162167
* @param {models.ILoadConfiguration} config
163168
* @returns {Promise<void>}
164169
*/
165-
load(config: models.ILoadConfiguration): Promise<void> {
166-
const errors = models.validateLoad(config);
170+
load(config: models.IReportLoadConfiguration | models.IDashboardLoadConfiguration): Promise<void> {
171+
const errors = this.validate(config);
167172
if (errors) {
168173
throw errors;
169174
}
170-
171-
let loadPath = '/report/load';
172-
if(this.config && this.config.type === 'dashboard') {
173-
loadPath = '/dashboard/load';
174-
}
175-
176-
return this.service.hpm.post<void>(loadPath, config, { uid: this.config.uniqueId }, this.iframe.contentWindow)
177-
.then(response => {
178-
utils.assign(this.config, config);
179-
return response.body;
180-
},
181-
response => {
182-
throw response.body;
183-
});
175+
176+
return this.service.hpm.post<void>(this.loadPath, config, { uid: this.config.uniqueId }, this.iframe.contentWindow)
177+
.then(response => {
178+
utils.assign(this.config, config);
179+
return response.body;
180+
},
181+
response => {
182+
throw response.body;
183+
});
184184
}
185185

186186
/**
@@ -332,7 +332,6 @@ export abstract class Embed {
332332
exitFullscreen.call(document);
333333
}
334334

335-
336335
/**
337336
* Returns true if the iframe is rendered in fullscreen mode,
338337
* otherwise returns false.
@@ -346,4 +345,9 @@ export abstract class Embed {
346345

347346
return options.some(option => document[option] === iframe);
348347
}
348+
349+
/**
350+
* Validate load configuration.
351+
*/
352+
abstract validate(config: models.IReportLoadConfiguration | models.IDashboardLoadConfiguration): models.IError[];
349353
}

src/report.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export class Report extends embed.Embed implements IReportNode, IFilterable {
5353
const configCopy = utils.assign({ settings }, config);
5454

5555
super(service, element, configCopy);
56+
this.loadPath = "/report/load";
5657
Array.prototype.push.apply(this.allowedEvents, Report.allowedEvents);
5758
}
5859

@@ -272,4 +273,11 @@ export class Report extends embed.Embed implements IReportNode, IFilterable {
272273
throw response.body;
273274
});
274275
}
276+
277+
/**
278+
* Validate load configuration.
279+
*/
280+
validate(config: models.IReportLoadConfiguration): models.IError[] {
281+
return models.validateReportLoad(config);
282+
}
275283
}

src/tile.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as models from 'powerbi-models';
12
import { Embed } from './embed';
23

34
/**
@@ -16,6 +17,13 @@ export class Tile extends Embed {
1617
* @returns {string}
1718
*/
1819
getId(): string {
19-
throw Error('Not implemented. Embedding tiles is not supported yet.');
20+
throw new Error('Not implemented. Embedding tiles is not supported yet.');
21+
}
22+
23+
/**
24+
* Validate load configuration.
25+
*/
26+
validate(config: any): models.IError[] {
27+
throw new Error('Not implemented. Embedding tiles is not supported yet.');
2028
}
2129
}

test/test.spec.ts

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -750,22 +750,22 @@ describe('Protocol', function () {
750750

751751
iframeLoaded
752752
.then(() => {
753-
spyApp.validateLoad.and.returnValue(Promise.reject(null));
753+
spyApp.validateReportLoad.and.returnValue(Promise.reject(null));
754754

755755
// Act
756756
hpm.post<models.IError>('/report/load', testData.load, { uid: testData.uniqueId })
757757
.then(() => {
758758
expect(false).toBe(true);
759-
spyApp.validateLoad.calls.reset();
759+
spyApp.validateReportLoad.calls.reset();
760760
done();
761761
})
762762
.catch(response => {
763763
// Assert
764-
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.load);
765-
expect(spyApp.load).not.toHaveBeenCalledWith(testData.load);
764+
expect(spyApp.validateReportLoad).toHaveBeenCalledWith(testData.load);
765+
expect(spyApp.reportLoad).not.toHaveBeenCalledWith(testData.load);
766766
expect(response.statusCode).toEqual(400);
767767
// Cleanup
768-
spyApp.validateLoad.calls.reset();
768+
spyApp.validateReportLoad.calls.reset();
769769
done();
770770
});
771771
});
@@ -784,17 +784,17 @@ describe('Protocol', function () {
784784

785785
iframeLoaded
786786
.then(() => {
787-
spyApp.validateLoad.and.returnValue(Promise.resolve(null));
787+
spyApp.validateReportLoad.and.returnValue(Promise.resolve(null));
788788
// Act
789789
hpm.post<void>('/report/load', testData.load)
790790
.then(response => {
791791
// Assert
792-
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.load);
793-
expect(spyApp.load).toHaveBeenCalledWith(testData.load);
792+
expect(spyApp.validateReportLoad).toHaveBeenCalledWith(testData.load);
793+
expect(spyApp.reportLoad).toHaveBeenCalledWith(testData.load);
794794
expect(response.statusCode).toEqual(202);
795795
// Cleanup
796-
spyApp.validateLoad.calls.reset();
797-
spyApp.load.calls.reset();
796+
spyApp.validateReportLoad.calls.reset();
797+
spyApp.reportLoad.calls.reset();
798798
done();
799799
});
800800
});
@@ -822,19 +822,19 @@ describe('Protocol', function () {
822822

823823
iframeLoaded
824824
.then(() => {
825-
spyApp.load.and.returnValue(Promise.resolve(testData.load));
825+
spyApp.reportLoad.and.returnValue(Promise.resolve(testData.load));
826826

827827
// Act
828828
hpm.post<void>('/report/load', testData.load, { uid: testData.uniqueId })
829829
.then(response => {
830830
setTimeout(() => {
831831
// Assert
832-
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.load);
833-
expect(spyApp.load).toHaveBeenCalledWith(testData.load);
832+
expect(spyApp.validateReportLoad).toHaveBeenCalledWith(testData.load);
833+
expect(spyApp.reportLoad).toHaveBeenCalledWith(testData.load);
834834
expect(spyHandler.handle).toHaveBeenCalledWith(jasmine.objectContaining(testExpectedEvent));
835835
// Cleanup
836-
spyApp.validateLoad.calls.reset();
837-
spyApp.load.calls.reset();
836+
spyApp.validateReportLoad.calls.reset();
837+
spyApp.reportLoad.calls.reset();
838838
done();
839839
});
840840
});
@@ -864,19 +864,19 @@ describe('Protocol', function () {
864864

865865
iframeLoaded
866866
.then(() => {
867-
spyApp.load.and.returnValue(Promise.reject(testData.error));
867+
spyApp.reportLoad.and.returnValue(Promise.reject(testData.error));
868868

869869
// Act
870870
hpm.post<void>('/report/load', testData.load, { uid: testData.uniqueId })
871871
.then(response => {
872872
setTimeout(() => {
873873
// Assert
874-
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.load);
875-
expect(spyApp.load).toHaveBeenCalledWith(testData.load);
874+
expect(spyApp.validateReportLoad).toHaveBeenCalledWith(testData.load);
875+
expect(spyApp.reportLoad).toHaveBeenCalledWith(testData.load);
876876
expect(spyHandler.handle).toHaveBeenCalledWith(jasmine.objectContaining(testExpectedEvent));
877877
// Cleanup
878-
spyApp.validateLoad.calls.reset();
879-
spyApp.load.calls.reset();
878+
spyApp.validateReportLoad.calls.reset();
879+
spyApp.reportLoad.calls.reset();
880880
done();
881881
});
882882
});
@@ -899,17 +899,17 @@ describe('Protocol', function () {
899899

900900
iframeLoaded
901901
.then(() => {
902-
spyApp.validateLoad.and.returnValue(Promise.resolve(null));
902+
spyApp.validateDashboardLoad.and.returnValue(Promise.resolve(null));
903903
// Act
904904
hpm.post<void>('/dashboard/load', testData.load)
905905
.then(response => {
906906
// Assert
907-
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.load);
908-
expect(spyApp.load).toHaveBeenCalledWith(testData.load);
907+
expect(spyApp.validateDashboardLoad).toHaveBeenCalledWith(testData.load);
908+
expect(spyApp.dashboardLoad).toHaveBeenCalledWith(testData.load);
909909
expect(response.statusCode).toEqual(202);
910910
// Cleanup
911-
spyApp.validateLoad.calls.reset();
912-
spyApp.load.calls.reset();
911+
spyApp.validateDashboardLoad.calls.reset();
912+
spyApp.dashboardLoad.calls.reset();
913913
done();
914914
});
915915
});
@@ -930,22 +930,22 @@ describe('Protocol', function () {
930930

931931
iframeLoaded
932932
.then(() => {
933-
spyApp.validateLoad.and.returnValue(Promise.reject(null));
933+
spyApp.validateDashboardLoad.and.returnValue(Promise.reject(null));
934934

935935
// Act
936936
hpm.post<models.IError>('/dashboard/load', testData.load, { uid: testData.uniqueId })
937937
.then(() => {
938938
expect(false).toBe(true);
939-
spyApp.validateLoad.calls.reset();
939+
spyApp.validateDashboardLoad.calls.reset();
940940
done();
941941
})
942942
.catch(response => {
943943
// Assert
944-
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.load);
945-
expect(spyApp.load).not.toHaveBeenCalledWith(testData.load);
944+
expect(spyApp.validateDashboardLoad).toHaveBeenCalledWith(testData.load);
945+
expect(spyApp.dashboardLoad).not.toHaveBeenCalledWith(testData.load);
946946
expect(response.statusCode).toEqual(400);
947947
// Cleanup
948-
spyApp.validateLoad.calls.reset();
948+
spyApp.validateDashboardLoad.calls.reset();
949949
done();
950950
});
951951
});
@@ -1093,7 +1093,7 @@ describe('Protocol', function () {
10931093
expect(response.statusCode).toEqual(202);
10941094
expect(spyHandler.handle).toHaveBeenCalledWith(jasmine.objectContaining(expectedEvent));
10951095
// Cleanup
1096-
spyApp.validateLoad.calls.reset();
1096+
spyApp.validateReportLoad.calls.reset();
10971097
spyApp.setPage.calls.reset();
10981098
done();
10991099
});
@@ -1132,7 +1132,7 @@ describe('Protocol', function () {
11321132
expect(response.statusCode).toEqual(202);
11331133
expect(spyHandler.handle).toHaveBeenCalledWith(jasmine.objectContaining(expectedEvent));
11341134
// Cleanup
1135-
spyApp.validateLoad.calls.reset();
1135+
spyApp.validateReportLoad.calls.reset();
11361136
spyApp.setPage.calls.reset();
11371137
done();
11381138
});
@@ -3125,7 +3125,8 @@ describe('SDK-to-MockApp', function () {
31253125
iframeHpm2 = setupEmbedMockApp(iframe2.contentWindow, window, logMessages, 'SDK-to-MockApp IframeWpmp2');
31263126

31273127
// Reset load handler
3128-
spyApp.validateLoad.calls.reset();
3128+
spyApp.validateReportLoad.calls.reset();
3129+
spyApp.validateDashboardLoad.calls.reset();
31293130
spyApp.reset();
31303131

31313132
const iframe1Loaded = new Promise<void>((resolve, reject) => {
@@ -3170,13 +3171,13 @@ describe('SDK-to-MockApp', function () {
31703171

31713172
iframeLoaded
31723173
.then(() => {
3173-
spyApp.validateLoad.and.returnValue(Promise.reject(testData.expectedErrors));
3174+
spyApp.validateReportLoad.and.returnValue(Promise.reject(testData.expectedErrors));
31743175
// Act
31753176
report.load(testData.loadConfig)
31763177
.catch(errors => {
31773178
// Assert
3178-
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.loadConfig);
3179-
expect(spyApp.load).not.toHaveBeenCalled();
3179+
expect(spyApp.validateReportLoad).toHaveBeenCalledWith(testData.loadConfig);
3180+
expect(spyApp.reportLoad).not.toHaveBeenCalled();
31803181
expect(errors).toEqual(jasmine.objectContaining(testData.expectedErrors));
31813182
done();
31823183
});
@@ -3194,14 +3195,14 @@ describe('SDK-to-MockApp', function () {
31943195

31953196
iframeLoaded
31963197
.then(() => {
3197-
spyApp.validateLoad.and.returnValue(Promise.resolve(null));
3198-
spyApp.load.and.returnValue(Promise.resolve(null));
3198+
spyApp.validateReportLoad.and.returnValue(Promise.resolve(null));
3199+
spyApp.reportLoad.and.returnValue(Promise.resolve(null));
31993200
// Act
32003201
report.load(testData.loadConfig)
32013202
.then(response => {
32023203
// Assert
3203-
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.loadConfig);
3204-
expect(spyApp.load).toHaveBeenCalledWith(testData.loadConfig);
3204+
expect(spyApp.validateReportLoad).toHaveBeenCalledWith(testData.loadConfig);
3205+
expect(spyApp.reportLoad).toHaveBeenCalledWith(testData.loadConfig);
32053206
expect(response).toEqual(undefined);
32063207
done();
32073208
});

0 commit comments

Comments
 (0)