fixed lint errors

This commit is contained in:
Srinath Narayanan 2021-01-13 05:26:47 -08:00
parent 318842624f
commit c9cea86225
4 changed files with 25 additions and 19 deletions

View File

@ -107,17 +107,15 @@ describe("SmartUiComponent", () => {
} }
}; };
it("should render", done => { it("should render", async () => {
const wrapper = shallow(<SmartUiComponent descriptor={exampleData} />); const wrapper = shallow(<SmartUiComponent descriptor={exampleData} />);
setImmediate(() => { await new Promise(resolve => setTimeout(resolve, 0));
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
expect(initializeCalled).toBeTruthy(); expect(initializeCalled).toBeTruthy();
expect(fetchMaxCalled).toBeTruthy(); expect(fetchMaxCalled).toBeTruthy();
wrapper.setState({ isRefreshing: true }); wrapper.setState({ isRefreshing: true });
wrapper.update(); wrapper.update();
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
done();
});
}); });
}); });

View File

@ -27,6 +27,11 @@ export enum UiType {
Slider = "Slider" Slider = "Slider"
} }
type numberPromise = () => Promise<number>;
type stringPromise = () => Promise<string>;
type dropdownItemPromise = () => Promise<DropdownItem[]>;
type infoPromise = () => Promise<Info>;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
export type DropdownItem = { label: string; key: string }; export type DropdownItem = { label: string; key: string };
@ -159,7 +164,7 @@ export class SmartUiComponent extends React.Component<SmartUiComponentProps, Sma
private setDefaults = async (currentNode: Node): Promise<void> => { private setDefaults = async (currentNode: Node): Promise<void> => {
if (currentNode.info && currentNode.info instanceof Function) { if (currentNode.info && currentNode.info instanceof Function) {
currentNode.info = await (currentNode.info as Function)(); currentNode.info = await (currentNode.info as infoPromise)();
} }
if (currentNode.input) { if (currentNode.input) {
@ -173,11 +178,11 @@ export class SmartUiComponent extends React.Component<SmartUiComponentProps, Sma
private getModifiedInput = async (input: AnyInput): Promise<AnyInput> => { private getModifiedInput = async (input: AnyInput): Promise<AnyInput> => {
if (input.label instanceof Function) { if (input.label instanceof Function) {
input.label = await (input.label as Function)(); input.label = await (input.label as stringPromise)();
} }
if (input.placeholder instanceof Function) { if (input.placeholder instanceof Function) {
input.placeholder = await (input.placeholder as Function)(); input.placeholder = await (input.placeholder as stringPromise)();
} }
switch (input.type) { switch (input.type) {
@ -187,30 +192,30 @@ export class SmartUiComponent extends React.Component<SmartUiComponentProps, Sma
case "number": { case "number": {
const numberInput = input as NumberInput; const numberInput = input as NumberInput;
if (numberInput.min instanceof Function) { if (numberInput.min instanceof Function) {
numberInput.min = await (numberInput.min as Function)(); numberInput.min = await (numberInput.min as numberPromise)();
} }
if (numberInput.max instanceof Function) { if (numberInput.max instanceof Function) {
numberInput.max = await (numberInput.max as Function)(); numberInput.max = await (numberInput.max as numberPromise)();
} }
if (numberInput.step instanceof Function) { if (numberInput.step instanceof Function) {
numberInput.step = await (numberInput.step as Function)(); numberInput.step = await (numberInput.step as numberPromise)();
} }
return numberInput; return numberInput;
} }
case "boolean": { case "boolean": {
const booleanInput = input as BooleanInput; const booleanInput = input as BooleanInput;
if (booleanInput.trueLabel instanceof Function) { if (booleanInput.trueLabel instanceof Function) {
booleanInput.trueLabel = await (booleanInput.trueLabel as Function)(); booleanInput.trueLabel = await (booleanInput.trueLabel as stringPromise)();
} }
if (booleanInput.falseLabel instanceof Function) { if (booleanInput.falseLabel instanceof Function) {
booleanInput.falseLabel = await (booleanInput.falseLabel as Function)(); booleanInput.falseLabel = await (booleanInput.falseLabel as stringPromise)();
} }
return booleanInput; return booleanInput;
} }
default: { default: {
const enumInput = input as DropdownInput; const enumInput = input as DropdownInput;
if (enumInput.choices instanceof Function) { if (enumInput.choices instanceof Function) {
enumInput.choices = await (enumInput.choices as Function)(); enumInput.choices = await (enumInput.choices as dropdownItemPromise)();
} }
return enumInput; return enumInput;
} }

View File

@ -2,12 +2,14 @@ import { Info } from "../Explorer/Controls/SmartUi/SmartUiComponent";
import { addPropertyToMap, buildSmartUiDescriptor } from "./SelfServeUtils"; import { addPropertyToMap, buildSmartUiDescriptor } from "./SelfServeUtils";
export const IsDisplayable = (): ClassDecorator => { export const IsDisplayable = (): ClassDecorator => {
//eslint-disable-next-line @typescript-eslint/ban-types
return (target: Function) => { return (target: Function) => {
buildSmartUiDescriptor(target.name, target.prototype); buildSmartUiDescriptor(target.name, target.prototype);
}; };
}; };
export const ClassInfo = (info: (() => Promise<Info>) | Info): ClassDecorator => { export const ClassInfo = (info: (() => Promise<Info>) | Info): ClassDecorator => {
//eslint-disable-next-line @typescript-eslint/ban-types
return (target: Function) => { return (target: Function) => {
addPropertyToMap(target.prototype, "root", target.name, "info", info); addPropertyToMap(target.prototype, "root", target.name, "info", info);
}; };

View File

@ -50,6 +50,7 @@ const addToMap = (...decorators: Decorator[]): PropertyDecorator => {
let className = target.constructor.name; let className = target.constructor.name;
const propertyName = property.toString(); const propertyName = property.toString();
if (className === "Function") { if (className === "Function") {
//eslint-disable-next-line @typescript-eslint/ban-types
className = (target as Function).name; className = (target as Function).name;
throw new Error(`Property '${propertyName}' in class '${className}'should be not be static.`); throw new Error(`Property '${propertyName}' in class '${className}'should be not be static.`);
} }