mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-11 16:24:11 +01:00
* Tests: convert all common tests from mocha to karma * Tests: refactor Vuetify setup in tests * Tests: update package-lock.json * Tests: convert all model test to vitest 1/2 * Tests: convert all model test to vitest 2/2 * Tests: fix broken test * Tests: time zone UTC * Tests: Add playwright screenshots folder to gitignore * Tests: Add timezone to vitest scripts * Tests: Add Vitest scripts to Makefile * Tests: delete unused timezone configs * Tests: Update some tests * Tests: Update vitest config * Tests: Delete usesless try-catch
131 lines
3.1 KiB
JavaScript
131 lines
3.1 KiB
JavaScript
import { describe, it, expect } from "vitest";
|
|
import "../fixtures";
|
|
import { Form, FormPropertyType } from "common/form";
|
|
|
|
describe("common/form", () => {
|
|
it("setting and getting definition", () => {
|
|
const def = { foo: { type: FormPropertyType.String, caption: "Foo" } };
|
|
const form = new Form();
|
|
|
|
form.setDefinition(def);
|
|
|
|
const result = form.getDefinition();
|
|
expect(result).toBe(def);
|
|
});
|
|
|
|
it("setting and getting a value according to type", () => {
|
|
const def = {
|
|
foo: { type: FormPropertyType.String, caption: "Foo" },
|
|
};
|
|
const form = new Form();
|
|
|
|
form.setDefinition(def);
|
|
form.setValue("foo", "test");
|
|
|
|
const result = form.getValue("foo");
|
|
expect(result).toBe("test");
|
|
});
|
|
|
|
it("setting a value not according to type", () => {
|
|
const def = {
|
|
foo: { type: FormPropertyType.String, caption: "Foo" },
|
|
};
|
|
const form = new Form();
|
|
|
|
form.setDefinition(def);
|
|
|
|
expect(() => {
|
|
form.setValue("foo", 3);
|
|
}).toThrow();
|
|
});
|
|
|
|
it("setting and getting a value for missing property throws exception", () => {
|
|
const def = {
|
|
foo: { type: FormPropertyType.String, caption: "Foo" },
|
|
};
|
|
const form = new Form();
|
|
|
|
form.setDefinition(def);
|
|
|
|
expect(() => {
|
|
form.setValue("bar", 3);
|
|
}).toThrow();
|
|
|
|
expect(() => {
|
|
form.getValue("bar");
|
|
}).toThrow();
|
|
});
|
|
|
|
it("setting and getting a complex value", () => {
|
|
const complexValue = {
|
|
something: "abc",
|
|
another: "def",
|
|
};
|
|
const def = {
|
|
foo: {
|
|
type: FormPropertyType.Object,
|
|
caption: "Foo",
|
|
},
|
|
};
|
|
const form = new Form();
|
|
|
|
form.setDefinition(def);
|
|
form.setValue("foo", complexValue);
|
|
|
|
const result = form.getValue("foo");
|
|
expect(result).toEqual(complexValue);
|
|
});
|
|
|
|
it("setting and getting more values at once", () => {
|
|
const def = {
|
|
foo: { type: FormPropertyType.String, caption: "Foo" },
|
|
baz: { type: FormPropertyType.String, caption: "XX" },
|
|
};
|
|
const form = new Form();
|
|
|
|
form.setDefinition(def);
|
|
form.setValues({ foo: "test", baz: "yyy" });
|
|
|
|
const result = form.getValues();
|
|
expect(result.foo).toBe("test");
|
|
expect(result.baz).toBe("yyy");
|
|
});
|
|
|
|
it("getting options of fieldname", () => {
|
|
const def = {
|
|
search: {
|
|
type: FormPropertyType.String,
|
|
caption: "Search",
|
|
label: { options: "tiles", text: "Tiles" },
|
|
options: [
|
|
{ value: "tiles", text: "Tiles" },
|
|
{ value: "mosaic", text: "Mosaic" },
|
|
],
|
|
},
|
|
};
|
|
const form = new Form();
|
|
|
|
form.setDefinition(def);
|
|
|
|
const result = form.getOptions("search");
|
|
expect(result[0].value).toBe("tiles");
|
|
expect(result[1].text).toBe("Mosaic");
|
|
});
|
|
|
|
it("getting not existing options returns empty object", () => {
|
|
const def = {
|
|
foo: {
|
|
type: FormPropertyType.Object,
|
|
caption: "Foo",
|
|
},
|
|
};
|
|
const form = new Form();
|
|
|
|
form.setDefinition(def);
|
|
|
|
const result = form.getOptions("foo");
|
|
expect(result[0].option).toBe("");
|
|
expect(result[0].label).toBe("");
|
|
});
|
|
});
|