feat(grid): enhance field search and filter interaction
This commit is contained in:
26 files changed
+491
-35
No files matched your search
@@ -43,6 +43,59 @@ describe("useDataGridConditionEditor", () => {
|
||||
expect(value.value).toBe("status = customer_name");
|
||||
});
|
||||
|
||||
it.each(["where", "orderBy"] as const)("searches %s fields by camel-case initials and any-position text", async (kind) => {
|
||||
const value = ref("");
|
||||
const editor = useDataGridConditionEditor({ kind, value, columns: ["userProfile", "order_id", "created_at"], historyScope: {} });
|
||||
|
||||
value.value = "up";
|
||||
await nextTick();
|
||||
await vi.waitFor(() => expect(editor.suggestions.value.map((item) => item.value)).toEqual(["userProfile"]));
|
||||
|
||||
value.value = "id";
|
||||
await nextTick();
|
||||
await vi.waitFor(() => expect(editor.suggestions.value.map((item) => item.value)).toEqual(["order_id"]));
|
||||
});
|
||||
|
||||
it.each(["where", "orderBy"] as const)("hides weaker %s matches when the input exactly matches a field", async (kind) => {
|
||||
const value = ref("");
|
||||
const editor = useDataGridConditionEditor({ kind, value, columns: ["id", "Is_Di", "Did"], historyScope: {} });
|
||||
|
||||
value.value = "id";
|
||||
await nextTick();
|
||||
await vi.waitFor(() => expect(editor.suggestions.value).toEqual([]));
|
||||
});
|
||||
|
||||
it("keeps suggestions dismissed after accepting until the text changes again", async () => {
|
||||
const value = ref("");
|
||||
const selectionStart = ref(0);
|
||||
const selectionEnd = ref(0);
|
||||
const editor = useDataGridConditionEditor({ kind: "orderBy", value, selectionStart, selectionEnd, columns: ["name", "namespace"], historyScope: {} });
|
||||
|
||||
value.value = "na";
|
||||
selectionStart.value = 2;
|
||||
selectionEnd.value = 2;
|
||||
await nextTick();
|
||||
await vi.waitFor(() => expect(editor.suggestions.value).toHaveLength(2));
|
||||
editor.navigate(1);
|
||||
expect(editor.handleKeydown(keyboardEvent("Enter"))).toBe("accept");
|
||||
expect(value.value).toBe("name");
|
||||
expect(editor.suggestions.value).toEqual([]);
|
||||
|
||||
selectionStart.value = 2;
|
||||
selectionEnd.value = 2;
|
||||
await nextTick();
|
||||
selectionStart.value = 4;
|
||||
selectionEnd.value = 4;
|
||||
await nextTick();
|
||||
expect(editor.suggestions.value).toEqual([]);
|
||||
|
||||
value.value = "nam";
|
||||
selectionStart.value = 3;
|
||||
selectionEnd.value = 3;
|
||||
await nextTick();
|
||||
await vi.waitFor(() => expect(editor.suggestions.value.map((item) => item.value)).toEqual(["name", "namespace"]));
|
||||
});
|
||||
|
||||
it("builds and applies suggestions at the current caret instead of the value end", async () => {
|
||||
const value = ref("");
|
||||
const selectionStart = ref(0);
|
||||
@@ -393,6 +446,11 @@ describe("useDataGridConditionEditor", () => {
|
||||
expect(editor.handleKeydown(initialEnter)).toBe("apply");
|
||||
expect(initialEnter.preventDefault).toHaveBeenCalledOnce();
|
||||
expect(value.value).toBe("na");
|
||||
expect(editor.suggestions.value).toEqual([]);
|
||||
|
||||
value.value = "nam";
|
||||
await nextTick();
|
||||
await vi.waitFor(() => expect(editor.suggestions.value).toHaveLength(2));
|
||||
|
||||
const down = keyboardEvent("ArrowDown");
|
||||
expect(editor.handleKeydown(down)).toBe("navigate");
|
||||
|
||||
@@ -2,6 +2,16 @@ import { describe, expect, it } from "vitest";
|
||||
import { buildDataGridStructuredWhere, useDataGridFilterBuilder, type DataGridStructuredFilterRule } from "@/composables/useDataGridFilterBuilder";
|
||||
|
||||
describe("useDataGridFilterBuilder", () => {
|
||||
it("searches columns by camel-case initials and any-position text", () => {
|
||||
const builder = useDataGridFilterBuilder({ columns: ["userProfile", "order_id", "created_at"], createId: () => "rule-1", isComplete: () => true, buildCondition: async () => "" });
|
||||
|
||||
builder.columnSearch.value = "up";
|
||||
expect(builder.filteredColumns.value).toEqual(["userProfile"]);
|
||||
|
||||
builder.columnSearch.value = "id";
|
||||
expect(builder.filteredColumns.value).toEqual(["order_id"]);
|
||||
});
|
||||
|
||||
it("normalizes values when modes change", () => {
|
||||
const builder = useDataGridFilterBuilder({ columns: ["id"], createId: () => "rule-1", isComplete: () => true, buildCondition: async () => "id = 1" });
|
||||
builder.ensureRule();
|
||||
@@ -9,6 +19,14 @@ describe("useDataGridFilterBuilder", () => {
|
||||
expect(builder.rules.value[0]).toMatchObject({ rawValue: "", rawEndValue: "" });
|
||||
});
|
||||
|
||||
it("starts new filter rules without preselecting a column", () => {
|
||||
const builder = useDataGridFilterBuilder({ columns: ["id", "name"], createId: () => "rule-1", isComplete: () => true, buildCondition: async () => "" });
|
||||
|
||||
builder.ensureRule();
|
||||
|
||||
expect(builder.rules.value[0]?.columnName).toBe("");
|
||||
});
|
||||
|
||||
it("skips disabled rules and applies conjunctions", async () => {
|
||||
let nextId = 0;
|
||||
const builder = useDataGridFilterBuilder({
|
||||
@@ -18,7 +36,7 @@ describe("useDataGridFilterBuilder", () => {
|
||||
buildCondition: async (rule) => `${rule.columnName} = '${rule.rawValue}'`,
|
||||
});
|
||||
builder.ensureRule();
|
||||
builder.updateRule("rule-1", { rawValue: "1" });
|
||||
builder.updateRule("rule-1", { columnName: "id", rawValue: "1" });
|
||||
builder.addRule();
|
||||
builder.updateRule("rule-2", { columnName: "name", rawValue: "Alice", conjunction: "OR" });
|
||||
expect(await builder.apply()).toBe("(id = '1') OR (name = 'Alice')");
|
||||
|
||||
Reference in new issue
Block a user