Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"dependencies": {
"http-post-message": "^0.2.3",
"powerbi-models": "^0.7.4",
"powerbi-models": "^0.9.1",
"powerbi-router": "^0.1.4",
"window-post-message-proxy": "^0.2.4"
},
Expand Down
8 changes: 8 additions & 0 deletions src/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class Dashboard extends embed.Embed implements IDashboardNode {
*/
constructor(service: service.Service, element: HTMLElement, config: embed.IEmbedConfiguration) {
super(service, element, config);
this.loadPath = "/dashboard/load";
Array.prototype.push.apply(this.allowedEvents, Dashboard.allowedEvents);
}

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

return dashboardId;
}

/**
* Validate load configuration.
*/
validate(config: models.IDashboardLoadConfiguration): models.IError[] {
return models.validateDashboardLoad(config);
}
}
40 changes: 22 additions & 18 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface IEmbedConfiguration {
filters?: models.IFilter[];
}

export interface IInternalEmbedConfiguration extends models.ILoadConfiguration {
export interface IInternalEmbedConfiguration extends models.IReportLoadConfiguration {
uniqueId: string;
type: string;
embedUrl: string;
Expand Down Expand Up @@ -107,6 +107,11 @@ export abstract class Embed {
*/
config: IInternalEmbedConfiguration;

/**
* Url used in the load request.
*/
loadPath: string;

@mattmazzola Matt Mazzola (mattmazzola) Sep 8, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typescript doesn't seem to support abstract properties. I think technically it would be better to use abstract method such as abstract getLoadPath(): string which allows proper compiler enforcement that the method is implemented in concrete classes but I thought the semantics of it being a method which returned hardcoded string were worse.


/**
* Creates an instance of Embed.
*
Expand Down Expand Up @@ -162,25 +167,20 @@ export abstract class Embed {
* @param {models.ILoadConfiguration} config
* @returns {Promise<void>}
*/
load(config: models.ILoadConfiguration): Promise<void> {
const errors = models.validateLoad(config);
load(config: models.IReportLoadConfiguration | models.IDashboardLoadConfiguration): Promise<void> {
const errors = this.validate(config);
if (errors) {
throw errors;
}

let loadPath = '/report/load';
if(this.config && this.config.type === 'dashboard') {
loadPath = '/dashboard/load';
}

return this.service.hpm.post<void>(loadPath, config, { uid: this.config.uniqueId }, this.iframe.contentWindow)
.then(response => {
utils.assign(this.config, config);
return response.body;
},
response => {
throw response.body;
});

return this.service.hpm.post<void>(this.loadPath, config, { uid: this.config.uniqueId }, this.iframe.contentWindow)
.then(response => {
utils.assign(this.config, config);
return response.body;
},
response => {
throw response.body;
});
}

/**
Expand Down Expand Up @@ -332,7 +332,6 @@ export abstract class Embed {
exitFullscreen.call(document);
}


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

return options.some(option => document[option] === iframe);
}

/**
* Validate load configuration.
*/
abstract validate(config: models.IReportLoadConfiguration | models.IDashboardLoadConfiguration): models.IError[];
}
8 changes: 8 additions & 0 deletions src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class Report extends embed.Embed implements IReportNode, IFilterable {
const configCopy = utils.assign({ settings }, config);

super(service, element, configCopy);
this.loadPath = "/report/load";
Array.prototype.push.apply(this.allowedEvents, Report.allowedEvents);
}

Expand Down Expand Up @@ -272,4 +273,11 @@ export class Report extends embed.Embed implements IReportNode, IFilterable {
throw response.body;
});
}

/**
* Validate load configuration.
*/
validate(config: models.IReportLoadConfiguration): models.IError[] {
return models.validateReportLoad(config);
}
}
10 changes: 9 additions & 1 deletion src/tile.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as models from 'powerbi-models';
import { Embed } from './embed';

/**
Expand All @@ -16,6 +17,13 @@ export class Tile extends Embed {
* @returns {string}
*/
getId(): string {
throw Error('Not implemented. Embedding tiles is not supported yet.');
throw new Error('Not implemented. Embedding tiles is not supported yet.');
}

/**
* Validate load configuration.
*/
validate(config: any): models.IError[] {
throw new Error('Not implemented. Embedding tiles is not supported yet.');
}
}
81 changes: 41 additions & 40 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,22 +750,22 @@ describe('Protocol', function () {

iframeLoaded
.then(() => {
spyApp.validateLoad.and.returnValue(Promise.reject(null));
spyApp.validateReportLoad.and.returnValue(Promise.reject(null));

// Act
hpm.post<models.IError>('/report/load', testData.load, { uid: testData.uniqueId })
.then(() => {
expect(false).toBe(true);
spyApp.validateLoad.calls.reset();
spyApp.validateReportLoad.calls.reset();
done();
})
.catch(response => {
// Assert
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.load);
expect(spyApp.load).not.toHaveBeenCalledWith(testData.load);
expect(spyApp.validateReportLoad).toHaveBeenCalledWith(testData.load);
expect(spyApp.reportLoad).not.toHaveBeenCalledWith(testData.load);
expect(response.statusCode).toEqual(400);
// Cleanup
spyApp.validateLoad.calls.reset();
spyApp.validateReportLoad.calls.reset();
done();
});
});
Expand All @@ -784,17 +784,17 @@ describe('Protocol', function () {

iframeLoaded
.then(() => {
spyApp.validateLoad.and.returnValue(Promise.resolve(null));
spyApp.validateReportLoad.and.returnValue(Promise.resolve(null));
// Act
hpm.post<void>('/report/load', testData.load)
.then(response => {
// Assert
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.load);
expect(spyApp.load).toHaveBeenCalledWith(testData.load);
expect(spyApp.validateReportLoad).toHaveBeenCalledWith(testData.load);
expect(spyApp.reportLoad).toHaveBeenCalledWith(testData.load);
expect(response.statusCode).toEqual(202);
// Cleanup
spyApp.validateLoad.calls.reset();
spyApp.load.calls.reset();
spyApp.validateReportLoad.calls.reset();
spyApp.reportLoad.calls.reset();
done();
});
});
Expand Down Expand Up @@ -822,19 +822,19 @@ describe('Protocol', function () {

iframeLoaded
.then(() => {
spyApp.load.and.returnValue(Promise.resolve(testData.load));
spyApp.reportLoad.and.returnValue(Promise.resolve(testData.load));

// Act
hpm.post<void>('/report/load', testData.load, { uid: testData.uniqueId })
.then(response => {
setTimeout(() => {
// Assert
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.load);
expect(spyApp.load).toHaveBeenCalledWith(testData.load);
expect(spyApp.validateReportLoad).toHaveBeenCalledWith(testData.load);
expect(spyApp.reportLoad).toHaveBeenCalledWith(testData.load);
expect(spyHandler.handle).toHaveBeenCalledWith(jasmine.objectContaining(testExpectedEvent));
// Cleanup
spyApp.validateLoad.calls.reset();
spyApp.load.calls.reset();
spyApp.validateReportLoad.calls.reset();
spyApp.reportLoad.calls.reset();
done();
});
});
Expand Down Expand Up @@ -864,19 +864,19 @@ describe('Protocol', function () {

iframeLoaded
.then(() => {
spyApp.load.and.returnValue(Promise.reject(testData.error));
spyApp.reportLoad.and.returnValue(Promise.reject(testData.error));

// Act
hpm.post<void>('/report/load', testData.load, { uid: testData.uniqueId })
.then(response => {
setTimeout(() => {
// Assert
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.load);
expect(spyApp.load).toHaveBeenCalledWith(testData.load);
expect(spyApp.validateReportLoad).toHaveBeenCalledWith(testData.load);
expect(spyApp.reportLoad).toHaveBeenCalledWith(testData.load);
expect(spyHandler.handle).toHaveBeenCalledWith(jasmine.objectContaining(testExpectedEvent));
// Cleanup
spyApp.validateLoad.calls.reset();
spyApp.load.calls.reset();
spyApp.validateReportLoad.calls.reset();
spyApp.reportLoad.calls.reset();
done();
});
});
Expand All @@ -899,17 +899,17 @@ describe('Protocol', function () {

iframeLoaded
.then(() => {
spyApp.validateLoad.and.returnValue(Promise.resolve(null));
spyApp.validateDashboardLoad.and.returnValue(Promise.resolve(null));
// Act
hpm.post<void>('/dashboard/load', testData.load)
.then(response => {
// Assert
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.load);
expect(spyApp.load).toHaveBeenCalledWith(testData.load);
expect(spyApp.validateDashboardLoad).toHaveBeenCalledWith(testData.load);
expect(spyApp.dashboardLoad).toHaveBeenCalledWith(testData.load);
expect(response.statusCode).toEqual(202);
// Cleanup
spyApp.validateLoad.calls.reset();
spyApp.load.calls.reset();
spyApp.validateDashboardLoad.calls.reset();
spyApp.dashboardLoad.calls.reset();
done();
});
});
Expand All @@ -930,22 +930,22 @@ describe('Protocol', function () {

iframeLoaded
.then(() => {
spyApp.validateLoad.and.returnValue(Promise.reject(null));
spyApp.validateDashboardLoad.and.returnValue(Promise.reject(null));

// Act
hpm.post<models.IError>('/dashboard/load', testData.load, { uid: testData.uniqueId })
.then(() => {
expect(false).toBe(true);
spyApp.validateLoad.calls.reset();
spyApp.validateDashboardLoad.calls.reset();
done();
})
.catch(response => {
// Assert
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.load);
expect(spyApp.load).not.toHaveBeenCalledWith(testData.load);
expect(spyApp.validateDashboardLoad).toHaveBeenCalledWith(testData.load);
expect(spyApp.dashboardLoad).not.toHaveBeenCalledWith(testData.load);
expect(response.statusCode).toEqual(400);
// Cleanup
spyApp.validateLoad.calls.reset();
spyApp.validateDashboardLoad.calls.reset();
done();
});
});
Expand Down Expand Up @@ -1093,7 +1093,7 @@ describe('Protocol', function () {
expect(response.statusCode).toEqual(202);
expect(spyHandler.handle).toHaveBeenCalledWith(jasmine.objectContaining(expectedEvent));
// Cleanup
spyApp.validateLoad.calls.reset();
spyApp.validateReportLoad.calls.reset();
spyApp.setPage.calls.reset();
done();
});
Expand Down Expand Up @@ -1132,7 +1132,7 @@ describe('Protocol', function () {
expect(response.statusCode).toEqual(202);
expect(spyHandler.handle).toHaveBeenCalledWith(jasmine.objectContaining(expectedEvent));
// Cleanup
spyApp.validateLoad.calls.reset();
spyApp.validateReportLoad.calls.reset();
spyApp.setPage.calls.reset();
done();
});
Expand Down Expand Up @@ -3125,7 +3125,8 @@ describe('SDK-to-MockApp', function () {
iframeHpm2 = setupEmbedMockApp(iframe2.contentWindow, window, logMessages, 'SDK-to-MockApp IframeWpmp2');

// Reset load handler
spyApp.validateLoad.calls.reset();
spyApp.validateReportLoad.calls.reset();
spyApp.validateDashboardLoad.calls.reset();
spyApp.reset();

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

iframeLoaded
.then(() => {
spyApp.validateLoad.and.returnValue(Promise.reject(testData.expectedErrors));
spyApp.validateReportLoad.and.returnValue(Promise.reject(testData.expectedErrors));
// Act
report.load(testData.loadConfig)
.catch(errors => {
// Assert
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.loadConfig);
expect(spyApp.load).not.toHaveBeenCalled();
expect(spyApp.validateReportLoad).toHaveBeenCalledWith(testData.loadConfig);
expect(spyApp.reportLoad).not.toHaveBeenCalled();
expect(errors).toEqual(jasmine.objectContaining(testData.expectedErrors));
done();
});
Expand All @@ -3194,14 +3195,14 @@ describe('SDK-to-MockApp', function () {

iframeLoaded
.then(() => {
spyApp.validateLoad.and.returnValue(Promise.resolve(null));
spyApp.load.and.returnValue(Promise.resolve(null));
spyApp.validateReportLoad.and.returnValue(Promise.resolve(null));
spyApp.reportLoad.and.returnValue(Promise.resolve(null));
// Act
report.load(testData.loadConfig)
.then(response => {
// Assert
expect(spyApp.validateLoad).toHaveBeenCalledWith(testData.loadConfig);
expect(spyApp.load).toHaveBeenCalledWith(testData.loadConfig);
expect(spyApp.validateReportLoad).toHaveBeenCalledWith(testData.loadConfig);
expect(spyApp.reportLoad).toHaveBeenCalledWith(testData.loadConfig);
expect(response).toEqual(undefined);
done();
});
Expand Down
Loading