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} />);
setImmediate(() => {
expect(wrapper).toMatchSnapshot();
expect(initializeCalled).toBeTruthy();
expect(fetchMaxCalled).toBeTruthy();
await new Promise(resolve => setTimeout(resolve, 0));
expect(wrapper).toMatchSnapshot();
expect(initializeCalled).toBeTruthy();
expect(fetchMaxCalled).toBeTruthy();
wrapper.setState({ isRefreshing: true });
wrapper.update();
expect(wrapper).toMatchSnapshot();
done();
});
wrapper.setState({ isRefreshing: true });
wrapper.update();
expect(wrapper).toMatchSnapshot();
});
});

View File

@ -27,6 +27,11 @@ export enum UiType {
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 */
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> => {
if (currentNode.info && currentNode.info instanceof Function) {
currentNode.info = await (currentNode.info as Function)();
currentNode.info = await (currentNode.info as infoPromise)();
}
if (currentNode.input) {
@ -173,11 +178,11 @@ export class SmartUiComponent extends React.Component<SmartUiComponentProps, Sma
private getModifiedInput = async (input: AnyInput): Promise<AnyInput> => {
if (input.label instanceof Function) {
input.label = await (input.label as Function)();
input.label = await (input.label as stringPromise)();
}
if (input.placeholder instanceof Function) {
input.placeholder = await (input.placeholder as Function)();
input.placeholder = await (input.placeholder as stringPromise)();
}
switch (input.type) {
@ -187,30 +192,30 @@ export class SmartUiComponent extends React.Component<SmartUiComponentProps, Sma
case "number": {
const numberInput = input as NumberInput;
if (numberInput.min instanceof Function) {
numberInput.min = await (numberInput.min as Function)();
numberInput.min = await (numberInput.min as numberPromise)();
}
if (numberInput.max instanceof Function) {
numberInput.max = await (numberInput.max as Function)();
numberInput.max = await (numberInput.max as numberPromise)();
}
if (numberInput.step instanceof Function) {
numberInput.step = await (numberInput.step as Function)();
numberInput.step = await (numberInput.step as numberPromise)();
}
return numberInput;
}
case "boolean": {
const booleanInput = input as BooleanInput;
if (booleanInput.trueLabel instanceof Function) {
booleanInput.trueLabel = await (booleanInput.trueLabel as Function)();
booleanInput.trueLabel = await (booleanInput.trueLabel as stringPromise)();
}
if (booleanInput.falseLabel instanceof Function) {
booleanInput.falseLabel = await (booleanInput.falseLabel as Function)();
booleanInput.falseLabel = await (booleanInput.falseLabel as stringPromise)();
}
return booleanInput;
}
default: {
const enumInput = input as DropdownInput;
if (enumInput.choices instanceof Function) {
enumInput.choices = await (enumInput.choices as Function)();
enumInput.choices = await (enumInput.choices as dropdownItemPromise)();
}
return enumInput;
}

View File

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

View File

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