-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ICPlugin->InputControls, add tests for InputControls, fix import styl…
…es, fix jest config for TS files
- Loading branch information
1 parent
520ecf1
commit dc91632
Showing
8 changed files
with
104 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters