Repository navigation
Add pageView to loadDashboardConfiguration #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isn't ValidatePageView part of validateDashboardLoad?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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[] { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
| if (pageView && pageView !== "fitToWidth" && pageView !== "oneColumn" && pageView !== "actualSize") { | ||
| return [{message: "pageView must be one of the followings: fitToWidth, oneColumn, actualSize"}]; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems redundant as you embed within try{} catch{}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 () { | ||
|
|
@@ -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'; | ||
|
|
||
There was a problem hiding this comment.
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....
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...