Skip to content

Commit

Permalink
Merge pull request #163 from gisce/66704/color-picker
Browse files Browse the repository at this point in the history
Add new component colorPicker
  • Loading branch information
ecarreras authored Dec 24, 2024
2 parents e4ab1e5 + 67cd630 commit d9d8bbe
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
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);
});
});
});

0 comments on commit d9d8bbe

Please sign in to comment.