Skip to content

Commit

Permalink
ICPlugin->InputControls, add tests for InputControls, fix import styl…
Browse files Browse the repository at this point in the history
…es, fix jest config for TS files
  • Loading branch information
grantbacon-jaspersoft committed May 30, 2024
1 parent 520ecf1 commit dc91632
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 67 deletions.
66 changes: 2 additions & 64 deletions packages/input-controls/index.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,3 @@
import { FC } from 'react';
import { InputControls } from "./src/InputControls";

interface BooleanICConfig {
style?: string | FC,
}

export interface InputControlConfig {
hostname?: string,
username: string,
password: string,
tenant: string,
// customize control look & feel
boolean?: BooleanICConfig,
};

const defaultInputControlConfig: InputControlConfig = {
username: 'joeuser',
password: 'joeuser',
tenant: 'organization_1',

boolean: { style: 'switch' },
};

export class ICPlugin {
private viz: any;
private config: InputControlConfig;
protected controlStructure: object = {};

constructor(vizjs: any, config?: InputControlConfig) {
this.viz = vizjs;
this.config = config || defaultInputControlConfig;
}

public fillControlStructure = (uri: string, callbackFn?: Function) => {
this.viz({
auth: {
name: this.config.username || "joeuser",
password: this.config.password || "joeuser",
organization: this.config.tenant || "organization_1",
},
}, (v: any) => {
v.inputControls({
resource: uri,
success: (data: string) => {
this.controlStructure = {...this.controlStructure, data};
if (callbackFn) {
callbackFn(this.controlStructure);
}
},
error: (e: object) => {
console.log(e);
},
});
});
}

public getControls = () => {
return this.controlStructure;
}

public makeControlsForReport = (resourceUri: string, container: any) => {
this.fillControlStructure(resourceUri);
container = JSON.stringify(this.controlStructure);
};
}
export default InputControls;
3 changes: 3 additions & 0 deletions packages/input-controls/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const conf: Config = {
'build',
],
testEnvironment: 'jsdom',
transform: {
'^.+\\.([tj]s|[tj]sx)$': 'babel-jest',
},
};

export default conf;
65 changes: 65 additions & 0 deletions packages/input-controls/src/InputControls.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { FC } from 'react';

interface BooleanICConfig {
style?: string | FC,
}

export interface InputControlConfig {
hostname?: string,
username: string,
password: string,
tenant: string,
// customize control look & feel
boolean?: BooleanICConfig,
};

const defaultInputControlConfig: InputControlConfig = {
username: 'joeuser',
password: 'joeuser',
tenant: 'organization_1',

boolean: { style: 'switch' },
};

export class InputControls {
private viz: any;
private config: InputControlConfig;
protected controlStructure: object = {};

constructor(vizjs: any, config?: InputControlConfig) {
this.viz = vizjs;
this.config = config || defaultInputControlConfig;
}

public fillControlStructure = (uri: string, callbackFn?: Function) => {
this.viz({
auth: {
name: this.config.username || "joeuser",
password: this.config.password || "joeuser",
organization: this.config.tenant || "organization_1",
},
}, (v: any) => {
v.inputControls({
resource: uri,
success: (data: string) => {
this.controlStructure = {...this.controlStructure, data};
if (callbackFn) {
callbackFn(this.controlStructure);
}
},
error: (e: object) => {
console.log(e);
},
});
});
}

public getControls = () => {
return this.controlStructure;
}

public makeControlsForReport = (resourceUri: string, container: any) => {
this.fillControlStructure(resourceUri);
container = JSON.stringify(this.controlStructure);
};
}
12 changes: 12 additions & 0 deletions packages/input-controls/test/src/InputControls.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { InputControls } from "../../src/InputControls"

describe("InputControls plugin", () => {

it("should allow instantiation", () => {
let ic = new InputControls({});
expect(ic).toBeDefined();
expect(ic.getControls()).toEqual({});
expect(ic.config.username).toBe('joeuser');
});

})
3 changes: 2 additions & 1 deletion packages/input-controls/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"skipLibCheck": true,
"outDir": "dist",
"moduleResolution": "NodeNext",
"module": "NodeNext"
},
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", "dist"],
"exclude": ["node_modules", "dist"]
}
17 changes: 17 additions & 0 deletions packages/test-app/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {Config} from 'jest'

const conf: Config = {
verbose: true,
watchPathIgnorePatterns: [
'node_modules',
'dist',
'coverage',
'build',
],
testEnvironment: 'jsdom',
transform: {
'^.+\\.([tj]s|[tj]sx)$': 'babel-jest',
},
};

export default conf;
4 changes: 2 additions & 2 deletions packages/test-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICPlugin } from 'input-controls-plugin';
import InputControls from 'input-controls-plugin';
import { useEffect, useState } from 'react';

export interface AppConfig {
Expand All @@ -8,7 +8,7 @@ export interface AppConfig {
export default function App(props: AppConfig) {

const [controlStruct, setControlStruct] = useState({});
const plugin = new ICPlugin((window as any).visualize);
const plugin = new InputControls((window as any).visualize);

useEffect(() => {
plugin.fillControlStructure('/public/viz/Adhoc/Ad_Hoc_View_All_filters_Report', (controls: object) => {
Expand Down
1 change: 1 addition & 0 deletions packages/test-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"skipLibCheck": true,
"outDir": "dist",
"moduleResolution": "NodeNext",
"module": "NodeNext"
},
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", "dist"],
Expand Down

0 comments on commit dc91632

Please sign in to comment.