UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

322 lines (321 loc) • 10.9 kB
/** * DevExtreme (cjs/__internal/grids/grid_core/ai_column/utils.test.js) * Version: 25.2.5 * Build date: Fri Feb 20 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; var _globals = require("@jest/globals"); var _utils = require("./utils"); (0, _globals.describe)("reduceDataCachedKeys", (() => { (0, _globals.it)("should remove keys from data that are present in cachedKeys", (() => { const result = (0, _utils.reduceDataCachedKeys)([{ key: "a", value: "1" }, { key: "b", value: "2" }, { key: "c", value: "3" }], { b: "test b", c: "test c" }, "key"); (0, _globals.expect)(result).toEqual({ a: { key: "a", value: "1" } }) })); (0, _globals.it)("should return the original data if no keys are cached", (() => { const result = (0, _utils.reduceDataCachedKeys)([{ key: "a", value: "1" }, { key: "b", value: "2" }, { key: "c", value: "3" }], {}, "key"); (0, _globals.expect)(result).toEqual({ a: { key: "a", value: "1" }, b: { key: "b", value: "2" }, c: { key: "c", value: "3" } }) })); (0, _globals.it)("should return empty object if all keys are cached", (() => { const result = (0, _utils.reduceDataCachedKeys)([{ key: "a", value: "1" }, { key: "b", value: "2" }, { key: "c", value: "3" }], { a: "test a", b: "test b", c: "test c" }, "key"); (0, _globals.expect)(result).toEqual({}) })); (0, _globals.it)("should handle number keys", (() => { const result = (0, _utils.reduceDataCachedKeys)([{ key: 1, value: "1" }, { key: 2, value: "2" }, { key: 3, value: "3" }], { 2: "two", 3: "three" }, "key"); (0, _globals.expect)(result).toEqual({ 1: { key: 1, value: "1" } }) })) })); (0, _globals.describe)("getDataFromRowItems", (() => { (0, _globals.it)("should extract data rows correctly", (() => { const result = (0, _utils.getDataFromRowItems)([{ data: { id: 1, value: "one" }, key: "id", rowType: "data" }, { data: { id: 2, value: "two" }, key: "id", rowType: "data" }, { data: { id: 3, value: "three" }, key: "id", rowType: "data" }]); (0, _globals.expect)(result).toEqual([{ id: 1, value: "one" }, { id: 2, value: "two" }, { id: 3, value: "three" }]) })); (0, _globals.it)("should ignore non-data rows", (() => { const result = (0, _utils.getDataFromRowItems)([{ data: { id: 1, value: "one" }, key: "id", rowType: "data" }, { data: { id: 4, value: "four" }, key: "id", rowType: "group" }]); (0, _globals.expect)(result).toEqual([{ id: 1, value: "one" }]) })) })); (0, _globals.describe)("isAIColumnAutoMode", (() => { (0, _globals.it)("should return true for AI columns in auto mode", (() => { const result = (0, _utils.isAIColumnAutoMode)({ type: "ai", ai: { mode: "auto" } }); (0, _globals.expect)(result).toBe(true) })); (0, _globals.it)("should return false for AI columns in manual mode", (() => { const result = (0, _utils.isAIColumnAutoMode)({ type: "ai", ai: { mode: "manual" } }); (0, _globals.expect)(result).toBe(false) })); (0, _globals.it)("should return false for non-AI columns", (() => { const result = (0, _utils.isAIColumnAutoMode)({ type: "buttons" }); (0, _globals.expect)(result).toBe(false) })); (0, _globals.it)("should return true by default", (() => { const result = (0, _utils.isAIColumnAutoMode)({ type: "ai" }); (0, _globals.expect)(result).toBe(true) })) })); (0, _globals.describe)("isPopupOptions", (() => { (0, _globals.it)("should return true for popup option names", (() => { (0, _globals.expect)((0, _utils.isPopupOptions)("ai.popup.width", 200)).toBe(true); (0, _globals.expect)((0, _utils.isPopupOptions)("ai.popup", { width: 200 })).toBe(true); (0, _globals.expect)((0, _utils.isPopupOptions)("ai", { popup: { width: 300 } })).toBe(true); (0, _globals.expect)((0, _utils.isPopupOptions)("ai", { popup: { width: 300 }, prompt: "Test" })).toBe(true) })); (0, _globals.it)("should return false for non-popup option names", (() => { (0, _globals.expect)((0, _utils.isPopupOptions)("ai.editorOptions.width", {})).toBe(false); (0, _globals.expect)((0, _utils.isPopupOptions)("ai.prompt", {})).toBe(false); (0, _globals.expect)((0, _utils.isPopupOptions)("ai", { editorOptions: { width: 300 } })).toBe(false); (0, _globals.expect)((0, _utils.isPopupOptions)("ai", { editorOptions: { width: 300 }, prompt: "Test" })).toBe(false) })) })); (0, _globals.describe)("isEditorOptions", (() => { (0, _globals.it)("should return true for editorOptions option names", (() => { (0, _globals.expect)((0, _utils.isEditorOptions)("ai.editorOptions.width", 200)).toBe(true); (0, _globals.expect)((0, _utils.isEditorOptions)("ai.editorOptions", { width: 200 })).toBe(true); (0, _globals.expect)((0, _utils.isEditorOptions)("ai", { editorOptions: { width: 300 } })).toBe(true); (0, _globals.expect)((0, _utils.isEditorOptions)("ai", { editorOptions: { width: 300 }, prompt: "Test" })).toBe(true) })); (0, _globals.it)("should return false for non-editorOptions option names", (() => { (0, _globals.expect)((0, _utils.isEditorOptions)("ai.popup.width", {})).toBe(false); (0, _globals.expect)((0, _utils.isEditorOptions)("ai.prompt", {})).toBe(false); (0, _globals.expect)((0, _utils.isEditorOptions)("ai", { popup: { width: 300 } })).toBe(false); (0, _globals.expect)((0, _utils.isEditorOptions)("ai", { popup: { width: 300 }, prompt: "Test" })).toBe(false) })) })); (0, _globals.describe)("isPromptOption", (() => { (0, _globals.it)("should return true for prompt option names", (() => { (0, _globals.expect)((0, _utils.isPromptOption)("ai.prompt", "Test prompt")).toBe(true); (0, _globals.expect)((0, _utils.isPromptOption)("ai", { prompt: "Test prompt" })).toBe(true); (0, _globals.expect)((0, _utils.isPromptOption)("ai", { prompt: "Test prompt", popup: { width: 300 } })).toBe(true) })); (0, _globals.it)("should return false for non-prompt option names", (() => { (0, _globals.expect)((0, _utils.isPromptOption)("ai.popup.width", {})).toBe(false); (0, _globals.expect)((0, _utils.isPromptOption)("ai.editorOptions", {})).toBe(false); (0, _globals.expect)((0, _utils.isPromptOption)("ai", { editorOptions: { width: 300 } })).toBe(false); (0, _globals.expect)((0, _utils.isPromptOption)("ai", { popup: { width: 300 } })).toBe(false) })) })); (0, _globals.describe)("isRefreshOption", (() => { (0, _globals.it)("should return true for refresh option names", (() => { (0, _globals.expect)((0, _utils.isRefreshOption)("ai.showHeaderMenu", true)).toBe(true); (0, _globals.expect)((0, _utils.isRefreshOption)("ai.noDataText", "No data")).toBe(true); (0, _globals.expect)((0, _utils.isRefreshOption)("ai.emptyText", "Empty")).toBe(true); (0, _globals.expect)((0, _utils.isRefreshOption)("ai", { showHeaderMenu: true })).toBe(true); (0, _globals.expect)((0, _utils.isRefreshOption)("ai", { noDataText: "No data" })).toBe(true); (0, _globals.expect)((0, _utils.isRefreshOption)("ai", { emptyText: "Empty" })).toBe(true); (0, _globals.expect)((0, _utils.isRefreshOption)("ai", { showHeaderMenu: true, prompt: "Test" })).toBe(true) })); (0, _globals.it)("should return false for non-refresh option names", (() => { (0, _globals.expect)((0, _utils.isRefreshOption)("ai.popup.width", {})).toBe(false); (0, _globals.expect)((0, _utils.isRefreshOption)("ai.prompt", {})).toBe(false); (0, _globals.expect)((0, _utils.isRefreshOption)("ai.editorOptions", {})).toBe(false); (0, _globals.expect)((0, _utils.isRefreshOption)("ai", { popup: { width: 300 } })).toBe(false); (0, _globals.expect)((0, _utils.isRefreshOption)("ai", { editorOptions: { width: 300 } })).toBe(false); (0, _globals.expect)((0, _utils.isRefreshOption)("ai", { prompt: "Test" })).toBe(false) })) }));