Add tests for new default value types
This commit is contained in:
parent
c4a98832cb
commit
3e3fd20207
|
@ -695,6 +695,69 @@ describe.each([
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("options column", () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
table = await config.api.table.save(
|
||||||
|
saveTableRequest({
|
||||||
|
schema: {
|
||||||
|
status: {
|
||||||
|
name: "status",
|
||||||
|
type: FieldType.OPTIONS,
|
||||||
|
default: "requested",
|
||||||
|
constraints: {
|
||||||
|
inclusion: ["requested", "approved"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("creates a new row with a default value successfully", async () => {
|
||||||
|
const row = await config.api.row.save(table._id!, {})
|
||||||
|
expect(row.status).toEqual("requested")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("does not use default value if value specified", async () => {
|
||||||
|
const row = await config.api.row.save(table._id!, {
|
||||||
|
status: "approved",
|
||||||
|
})
|
||||||
|
expect(row.status).toEqual("approved")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("array column", () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
table = await config.api.table.save(
|
||||||
|
saveTableRequest({
|
||||||
|
schema: {
|
||||||
|
food: {
|
||||||
|
name: "food",
|
||||||
|
type: FieldType.ARRAY,
|
||||||
|
default: ["apple", "orange"],
|
||||||
|
constraints: {
|
||||||
|
type: JsonFieldSubType.ARRAY,
|
||||||
|
inclusion: ["apple", "orange", "banana"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("creates a new row with a default value successfully", async () => {
|
||||||
|
const row = await config.api.row.save(table._id!, {})
|
||||||
|
expect(row.food).toEqual(["apple", "orange"])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("does not use default value if value specified", async () => {
|
||||||
|
const row = await config.api.row.save(table._id!, {
|
||||||
|
food: ["orange"],
|
||||||
|
})
|
||||||
|
expect(row.food).toEqual(["orange"])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("bindings", () => {
|
describe("bindings", () => {
|
||||||
describe("string column", () => {
|
describe("string column", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
|
|
@ -161,6 +161,7 @@ export interface OptionsFieldMetadata extends BaseFieldSchema {
|
||||||
constraints: FieldConstraints & {
|
constraints: FieldConstraints & {
|
||||||
inclusion: string[]
|
inclusion: string[]
|
||||||
}
|
}
|
||||||
|
default?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ArrayFieldMetadata extends BaseFieldSchema {
|
export interface ArrayFieldMetadata extends BaseFieldSchema {
|
||||||
|
@ -169,6 +170,7 @@ export interface ArrayFieldMetadata extends BaseFieldSchema {
|
||||||
type: JsonFieldSubType.ARRAY
|
type: JsonFieldSubType.ARRAY
|
||||||
inclusion: string[]
|
inclusion: string[]
|
||||||
}
|
}
|
||||||
|
default?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BaseFieldSchema extends UIFieldMetadata {
|
interface BaseFieldSchema extends UIFieldMetadata {
|
||||||
|
|
Loading…
Reference in New Issue