Skip to content
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

Uuid issue #92

Merged
merged 2 commits into from
Feb 15, 2022
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
8,697 changes: 7,058 additions & 1,639 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powerbi-visuals-utils-testutils",
"version": "2.4.4",
"version": "2.4.5",
"description": "powerbi-visuals-utils-testutils",
"main": "lib/index.js",
"module": "lib/index.js",
Expand Down Expand Up @@ -50,8 +50,7 @@
"karma-typescript": "5.5.2",
"karma-typescript-preprocessor": "0.4.0",
"karma-webpack": "5.0.0",
"powerbi-visuals-api": "~3.8.0",
"puppeteer": "^13.0.0",
"puppeteer": "^13.2.0",
"snyk": "^1.790.0",
"ts-loader": "9.2.6",
"ts-node": "^10.4.0",
Expand All @@ -64,10 +63,10 @@
"dependencies": {
"d3-array": "3.1.1",
"d3-timer": "3.0.1",
"istanbul-instrumenter-loader": "3.0.1",
"istanbul-instrumenter-loader": "^2.0.0",
"lodash-es": "4.17.21",
"powerbi-visuals-utils-typeutils": "^2.3.1",
"uuidv4": "^6.2.12"
"powerbi-visuals-api": "^4.2.0",
"powerbi-visuals-utils-typeutils": "^2.3.1"
},
"snyk": true
}
7 changes: 6 additions & 1 deletion src/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* THE SOFTWARE.
*/
import { timerFlush } from "d3-timer";
import { uuid } from "uuidv4";

import range from "lodash-es/range";
import includes from "lodash-es/includes";
Expand All @@ -37,6 +36,12 @@ function each(element: JQuery | HTMLElement, fn: (i: number, el: HTMLElement) =>
}
}

function uuid() {
const buf = new Uint8Array(1);
window.crypto.getRandomValues(buf);
return buf[0];
}


export function testDom(height: number | string, width: number | string): HTMLElement {
let element: HTMLElement = document.createElement("div"),
Expand Down
40 changes: 40 additions & 0 deletions src/mocks/mockDownloadService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Power BI Visualizations
*
* Copyright (c) Microsoft Corporation
* All rights reserved.
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the ""Software""), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

// powerbi
import powerbi from "powerbi-visuals-api";
import IPromise = powerbi.IPromise;

// powerbi.extensibility
import IDownloadService = powerbi.extensibility.IDownloadService;

export class MockDownloadService implements IDownloadService {
public exportVisualsContent(content: string, fileName: string, fileType: string, fileDescription: string): IPromise<boolean> {
return new Promise<void>((resolve, reject) => {
resolve();
}) as any;
}
}
6 changes: 6 additions & 0 deletions src/mocks/mockISelectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export class MockISelectionManager implements ISelectionManager {

private callback: (ids: ISelectionId[]) => void;

public toggleExpandCollapse(selectionId: ISelectionId): IPromise<{}> {
return new Promise<void>((resolve, reject) => {
resolve();
}) as any;
}

public showContextMenu(selectionId: ISelectionId, position: IPoint): IPromise<{}> {
return new Promise<void>((resolve, reject) => {
resolve();
Expand Down
21 changes: 21 additions & 0 deletions src/mocks/mockIStorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,34 @@ import powerbi from "powerbi-visuals-api";
import IPromise = powerbi.IPromise;

export interface ILocalVisualStorageService {
enabled(): IPromise<boolean>;
get(key: string): IPromise<string>;
set(key: string, data: string): IPromise<number>;
remove(key: string): void;
}

function localStorageEnabled() {
try {
const testVar = "test";
localStorage.setItem(testVar, testVar);
localStorage.removeItem(testVar);
return true;
}
catch (e) {
return false;
}
}

export class MockIStorageService implements ILocalVisualStorageService {

public enabled(): IPromise<boolean> {
const enabled: boolean = localStorageEnabled();

return new Promise((resolve, reject) => {
resolve(enabled);
}) as any;
}

public get(key: string): IPromise<string> {
const data: string = localStorage.getItem(key);

Expand Down
6 changes: 5 additions & 1 deletion src/mocks/mockVisualHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import ISelectionIdBuilder = powerbi.visuals.ISelectionIdBuilder;
import ISelectionManager = powerbi.extensibility.ISelectionManager;
import IColorPalette = powerbi.extensibility.ISandboxExtendedColorPalette;
import IVisualEventService = powerbi.extensibility.IVisualEventService;
import IDownloadService = powerbi.extensibility.IDownloadService;
import HostCapabilities = powerbi.extensibility.HostCapabilities;

// powerbi.extensibility.visual
Expand All @@ -56,6 +57,7 @@ export class MockIVisualHost implements IVisualHost {
private localStorageService: ILocalVisualStorageService;
private visualEventService: IVisualEventService;
public hostCapabilities: HostCapabilities;
public downloadService: IDownloadService;

constructor(
colorPalette?: IColorPalette,
Expand All @@ -67,7 +69,8 @@ export class MockIVisualHost implements IVisualHost {
authService?: powerbi.extensibility.IAuthenticationService,
storageService?: ILocalVisualStorageService,
eventService?: IVisualEventService,
hostCapabilities?: HostCapabilities) {
hostCapabilities?: HostCapabilities,
downloadService?: IDownloadService) {

this.colorPaletteInstance = colorPalette;
this.selectionManager = selectionManager;
Expand All @@ -79,6 +82,7 @@ export class MockIVisualHost implements IVisualHost {
this.localStorageService = storageService;
this.visualEventService = eventService;
this.hostCapabilities = hostCapabilities;
this.downloadService = downloadService;
}

public createSelectionIdBuilder(): ISelectionIdBuilder {
Expand Down
6 changes: 6 additions & 0 deletions src/mocks/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { MockIVisualHost } from "./mockVisualHost";
import { MockIEventService } from "./mockIEventService";
import { MockIStorageService, ILocalVisualStorageService } from "./mockIStorageService";
import { MockHostCapabilities } from "./mockHostCapabilities";
import { MockDownloadService } from "./mockDownloadService";
// powerbi
import IColorInfo = powerbi.IColorInfo;

Expand All @@ -51,6 +52,7 @@ import ISelectionId = powerbi.visuals.ISelectionId;
import IColorPalette = powerbi.extensibility.ISandboxExtendedColorPalette;
import ISelectionManager = powerbi.extensibility.ISelectionManager;
import IVisualHost = powerbi.extensibility.visual.IVisualHost;
import IDownloadService = powerbi.extensibility.IDownloadService;
import HostCapabilities = powerbi.extensibility.HostCapabilities;

export function createVisualHost(locale?: Object, allowInteractions?: boolean, colors?: IColorInfo[], isEnabled?: boolean, displayNames?: any, token?: string): IVisualHost {
Expand Down Expand Up @@ -113,4 +115,8 @@ export function createEventService(): IVisualEventService {

export function createHostCapabilities(): HostCapabilities {
return new MockHostCapabilities();
}

export function createDownloadService(): IDownloadService {
return new MockDownloadService();
}