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
4 changes: 4 additions & 0 deletions dist/dashboard.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ export declare class Dashboard extends embed.Embed implements IDashboardNode {
* Validate load configuration.
*/
validate(config: models.IDashboardLoadConfiguration): models.IError[];
/**
* Validate that pageView has a legal value: if page view is defined it must have one of the values defined in models.PageView
*/
private ValidatePageView(pageView);
}
1 change: 1 addition & 0 deletions dist/embed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IEmbedConfiguration {
settings?: models.ISettings;
pageName?: string;
filters?: models.IFilter[];
pageView?: models.PageView;
}
export interface IInternalEmbedConfiguration extends models.IReportLoadConfiguration {
uniqueId: string;
Expand Down
19 changes: 17 additions & 2 deletions dist/powerbi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/powerbi.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/powerbi.min.js

Large diffs are not rendered by default.

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.10.0",
"powerbi-models": "^0.10.1",
"powerbi-router": "^0.1.4",
"window-post-message-proxy": "^0.2.4"
},
Expand Down
12 changes: 11 additions & 1 deletion src/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ export class Dashboard extends embed.Embed implements IDashboardNode {
* Validate load configuration.
*/
validate(config: models.IDashboardLoadConfiguration): models.IError[] {
return models.validateDashboardLoad(config);
let error = models.validateDashboardLoad(config);
return error ? error : this.ValidatePageView(config.pageView);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

i think you can do
error || this.validate....

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.

I think it will return false or true like this - won't it? I want to return the error itself.

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.

the "error" variable isn't boolean...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why isn't ValidatePageView part of validateDashboardLoad?

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.

validateDashboardLoad is auto generated in the powerbi-models project...

}

/**
* Validate that pageView has a legal value: if page view is defined it must have one of the values defined in models.PageView
*/
private ValidatePageView(pageView: models.PageView): models.IError[] {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't there any utility class (in TS) existing or new one we can write for verifying whether a value is a valid among all the available values in an emun?

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.

from a short investigation - I am not familiar with such a class and don't know of a way to create one (this is a string enum, it is not a regular enum).
I will add this task to a "code improvements" task I have (that also include the reuse of loadConfiguration in embedConfiguration)

if (pageView && pageView !== "fitToWidth" && pageView !== "oneColumn" && pageView !== "actualSize") {
return [{message: "pageView must be one of the followings: fitToWidth, oneColumn, actualSize"}];
}
}
}
1 change: 1 addition & 0 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface IEmbedConfiguration {
settings?: models.ISettings;
pageName?: string;
filters?: models.IFilter[];
pageView?: models.PageView;
}

export interface IInternalEmbedConfiguration extends models.IReportLoadConfiguration {
Expand Down
48 changes: 48 additions & 0 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@ declare global {
}
}

function ValidateDashboardConfigurationWorksAsExpected(pageView: string, exceptionExpected: boolean, powerbi: service.Service) {
const embedUrl = `https://app.powerbi.com/dashboardEmbed`;
const component = $(`<div powerbi-embed-url="${embedUrl}" powerbi-type="report"></div>`)
.appendTo('#powerbi-fixture');

const dashboardEmbedConfig = {
type: "dashboard",
id: "fakeReportId",
accessToken: "fakeAccessToken",
embedUrl: "fakeEmbedUrl",
pageView: pageView
};

powerbi.embed(component[0], <any>dashboardEmbedConfig);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems redundant as you embed within try{} catch{}

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.

The validate is called only on "load" (not on "embed"). In "reality" - the constructor of embed class assigns "onLoad" to the iframe that calls the "load" function when the iframe is ready. That doesn't happen on tests, so we need to call the embed again - when embeding the second time the code flow doesn't wait for the iframe to be ready and calls the load function.


var exceptionThrown = false;
// Act
try {
powerbi.embed(component[0], <any>dashboardEmbedConfig);
}
catch(e) {
exceptionThrown = true;
}

// Assert
expect(exceptionThrown).toBe(exceptionExpected);
}

let logMessages = (window.__karma__.config.args[0] === 'logMessages');

describe('service', function () {
Expand Down Expand Up @@ -218,6 +246,26 @@ describe('service', function () {
expect(attemptToEmbed).toThrowError();
});

it('if attempting to embed a dashboard with an invalid pageView, throw error', function () {
ValidateDashboardConfigurationWorksAsExpected("notValid", true, powerbi);
});

it('if attempting to embed a dashboard with a pageView equals fitToWidth, don\'t throw error', function () {
ValidateDashboardConfigurationWorksAsExpected("fitToWidth", false, powerbi);
});

it('if attempting to embed a dashboard with a pageView equals oneColumn, don\'t throw error', function () {
ValidateDashboardConfigurationWorksAsExpected("oneColumn", false, powerbi);
});

it('if attempting to embed a dashboard with a pageView equals actualSize, don\'t throw error', function () {
ValidateDashboardConfigurationWorksAsExpected("actualSize", false, powerbi);
});

it('if attempting to embed a dashboard with an undefined pageView, don\'t throw error', function () {
ValidateDashboardConfigurationWorksAsExpected(undefined, false, powerbi);
});

it('should get uqiqueId from config first', function () {
// Arrange
const testUniqueId = 'fakeUniqueId';
Expand Down