Merged PR 47903: [Embed Models] Release new version

This commit is contained in:
Liav Zayde 2019-09-25 07:15:31 +00:00
Родитель e0e5f27528
Коммит bbff2405a4
6 изменённых файлов: 126 добавлений и 2 удалений

Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "powerbi-models",
"version": "1.2.1",
"version": "1.3.0",
"description": "Contains JavaScript & TypeScript object models for Microsoft Power BI JavaScript SDK. For each model there is a TypeScript interface, and a validation function to ensure and object is valid.",
"main": "dist/models.js",
"typings": "dist/models.d.ts",

Просмотреть файл

@ -140,6 +140,10 @@ export interface IVisual {
layout?: IVisualLayout;
}
export interface IDatasetBinding {
datasetId: string;
}
export enum Permissions {
Read = 0,
ReadWrite = 1,
@ -801,6 +805,7 @@ export interface IReportLoadConfiguration {
bookmark?: IApplyBookmarkRequest;
theme?: IReportTheme;
embedUrl?: string;
datasetBinding?: IDatasetBinding;
}
export interface IReportCreateConfiguration {

Просмотреть файл

@ -33,6 +33,7 @@ import { SlicerValidator, SlicerStateValidator } from '../models/slicersValidato
import { VisualHeaderSettingsValidator, VisualHeaderValidator, VisualSettingsValidator } from '../models/visualSettingsValidator';
import { SingleCommandSettingsValidator, CommandsSettingsValidator } from '../models/commandsSettingsValidator';
import { CustomThemeValidator } from '../models/customThemeValidator';
import { DatasetBindingValidator } from '../models/datasetBindingValidator';
export interface IValidationError {
path?: string;
@ -70,6 +71,7 @@ export const Validators = {
customPageSizeValidator: new CustomPageSizeValidator(),
customThemeValidator: new CustomThemeValidator(),
dashboardLoadValidator: new DashboardLoadValidator(),
datasetBindingValidator: new DatasetBindingValidator(),
displayStateModeValidator: new EnumValidator([0, 1]),
displayStateValidator: new DisplayStateValidator(),
exportDataRequestValidator: new ExportDataRequestValidator(),

Просмотреть файл

@ -0,0 +1,26 @@
import { IValidationError, Validators } from '../core/validator';
import { MultipleFieldsValidator, IFieldValidatorsPair } from '../core/multipleFieldsValidator';
import { ObjectValidator } from '../core/typeValidator';
export class DatasetBindingValidator extends ObjectValidator {
public validate(input: any, path?: string, field?: string): IValidationError[] {
if (input == null) {
return null;
}
const errors = super.validate(input, path, field);
if (errors) {
return errors;
}
const fields: IFieldValidatorsPair[] = [
{
field: "datasetId",
validators: [Validators.fieldRequiredValidator, Validators.stringValidator]
}
];
const multipleFieldsValidator = new MultipleFieldsValidator(fields);
return multipleFieldsValidator.validate(input, path, field);
}
}

Просмотреть файл

@ -60,7 +60,11 @@ export class ReportLoadValidator extends ObjectValidator {
{
field: "embedUrl",
validators: [Validators.stringValidator]
}
},
{
field: "datasetBinding",
validators: [Validators.datasetBindingValidator]
},
];
const multipleFieldsValidator = new MultipleFieldsValidator(fields);

Просмотреть файл

@ -13,6 +13,8 @@ describe('Unit | Models', function () {
describe('validateReportLoad', function () {
const accessTokenRequiredMessage = "accessToken is required";
const accessTokenInvalidTypeMessage = "accessToken must be a string";
const datasetIdInvalidTypeMessage = "datasetId must be a string";
const datasetIdRequiredMessage = "datasetId is required";
const idRequiredMessage = "id is required";
const idInvalidTypeMessage = "id must be a string";
const filtersInvalidMessage = "filters property is invalid";
@ -259,6 +261,59 @@ describe('Unit | Models', function () {
// Assert
testForExpectedMessage(errors, viewModeInvalidMessage);
});
it(`should return undefined if id, accessToken and datasetBinding are valid`, function () {
// Arrange
const testData = {
load: {
id: 'fakeId',
accessToken: 'fakeAccessToken',
datasetBinding: {
datasetId: "fakeDatasetId"
}
}
};
// Act
const errors = models.validateReportLoad(testData.load);
// Assert
expect(errors).toBeUndefined();
});
it(`should return errors with one containing message '${datasetIdRequiredMessage}' if datasetId doesn't exists`, function () {
// Arrange
const testData = {
load: {
id: 'fakeId',
accessToken: 'fakeAccessToken',
datasetBinding: {
}
}
};
// Act
const errors = models.validateReportLoad(testData.load);
// Assert
testForExpectedMessage(errors, datasetIdRequiredMessage);
});
it(`should return errors with one containing message '${datasetIdInvalidTypeMessage}' if datasetId is not a string`, function () {
// Arrange
const testData = {
load: {
id: 'fakeId',
accessToken: 'fakeAccessToken',
datasetBinding: {
datasetId: 1
}
}
};
// Act
const errors = models.validateReportLoad(testData.load);
// Assert
testForExpectedMessage(errors, datasetIdInvalidTypeMessage);
});
});
describe('validateCreateReport', function () {
@ -489,8 +544,10 @@ describe('Unit | Models', function () {
embedUrl: 1,
}
};
// Act
const errors = models.validateDashboardLoad(testData.load);
// Assert
testForExpectedMessage(errors, embedUrlInvalidTypeMessage);
});
@ -1043,6 +1100,36 @@ describe('Unit | Models', function () {
testForExpectedMessage(errors, layoutTypeInvalidMessage);
});
it(`should return errors with one containing message '${hyperlinkClickBehaviorInvalidTypeMessage}' if hyperlinkClickBehavior is not a number`, function () {
// Arrange
const testData = {
settings: {
hyperlinkClickBehavior: true
}
};
// Act
const errors = models.validateSettings(testData.settings);
// Assert
testForExpectedMessage(errors, hyperlinkClickBehaviorInvalidTypeMessage);
});
it(`should return errors with one containing message '${hyperlinkClickBehaviorInvalidMessage}' if hyperlinkClickBehavior is not valid`, function () {
// Arrange
const testData = {
settings: {
hyperlinkClickBehavior: 3
}
};
// Act
const errors = models.validateSettings(testData.settings);
// Assert
testForExpectedMessage(errors, hyperlinkClickBehaviorInvalidMessage);
});
it(`should return errors with one containing message '${customLayoutInvalidMessage}' if customLayout type is not valid`, function () {
// Arrange
const testData = {