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

Add new component colorPicker #163

Merged
merged 1 commit into from
Dec 24, 2024
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
9 changes: 9 additions & 0 deletions src/ColorPicker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Char from "./Char";

class ColorPicker extends Char {
get showText(): boolean {
return this.parsedWidgetProps.show_text ?? true;
}
}

export default ColorPicker;
4 changes: 4 additions & 0 deletions src/WidgetFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import JSONField from "./JSONField";
import Email from "./Email";
import Spinner from "./Spinner";
import Carousel from "./Carousel";
import ColorPicker from "./ColorPicker";

class WidgetFactory {
/**
Expand Down Expand Up @@ -188,6 +189,9 @@ class WidgetFactory {
case "carousel":
this._widgetClass = Carousel;
break;
case "colorPicker":
this._widgetClass = ColorPicker;
break;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import Comments from "./Comments";
import Email from "./Email";
import Spinner from "./Spinner";
import Carousel from "./Carousel";
import ColorPicker from "./ColorPicker";

import {
Graph,
Expand Down Expand Up @@ -144,4 +145,5 @@ export {
Email,
Spinner,
Carousel,
ColorPicker,
};
64 changes: 64 additions & 0 deletions src/spec/ColorPicker.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// src/spec/ColorPicker.spec.ts
import WidgetFactory from "../WidgetFactory";
import ColorPicker from "../ColorPicker";
import { it, expect, describe } from "vitest";

describe("A ColorPicker", () => {
it("should have an id corresponding to field name", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "colorPicker",
};

const widget = widgetFactory.createWidget("colorPicker", props);
expect(widget).toBeInstanceOf(ColorPicker);
});

it("should properly set label", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "colorPicker",
string: "colorPicker caption",
};
const widget = widgetFactory.createWidget("colorPicker", props);

expect(widget.label).toBe("colorPicker caption");
});

describe("showText property", () => {
it("should show text by default", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "colorPicker",
};
const widget = widgetFactory.createWidget("colorPicker", props);

expect(widget.showText).toBe(true);
});
it("should show text when widget_props.showText is true", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "colorPicker",
widget_props: {
show_text: true,
},
};
const widget = widgetFactory.createWidget("colorPicker", props);

expect(widget.showText).toBe(true);
});

it("should not show text when widget_props.showText is false", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "colorPicker",
widget_props: {
show_text: false,
},
};
const widget = widgetFactory.createWidget("colorPicker", props);

expect(widget.showText).toBe(false);
});
});
});
Loading