devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
100 lines (99 loc) • 3.92 kB
JavaScript
/**
* DevExtreme (esm/__internal/core/ai_integration/commands/changeStyle.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/
*/
import {
beforeEach,
describe,
expect,
it,
jest
} from "@jest/globals";
import {
ChangeStyleCommand
} from "../../../core/ai_integration/commands";
import {
PromptManager
} from "../../../core/ai_integration/core/prompt_manager";
import {
RequestManager
} from "../../../core/ai_integration/core/request_manager";
import {
Provider
} from "../../../core/ai_integration/test_utils/provider_mock";
describe("ChangeStyleCommand", (() => {
const params = {
text: "text to style change",
writingStyle: "creative"
};
let promptManager = null;
let requestManager = null;
let command = null;
beforeEach((() => {
const provider = new Provider;
requestManager = new RequestManager(provider);
promptManager = new PromptManager;
command = new ChangeStyleCommand(promptManager, requestManager)
}));
describe("getTemplateName", (() => {
it("should return the name of the corresponding template", (() => {
const templateName = command.getTemplateName();
expect(templateName).toBe("changeStyle")
}))
}));
describe("buildPromptData", (() => {
it("should form PromptData with empty object", (() => {
const promptData = command.buildPromptData(params);
expect(promptData).toEqual({
system: {
writingStyle: params.writingStyle
},
user: {
text: params.text
}
})
}))
}));
describe("parseResult", (() => {
it("should return the string without changes", (() => {
const result = command.parseResult("Shorten text");
expect(result).toBe("Shorten text")
}))
}));
describe("execute", (() => {
const callbacks = {
onComplete: () => {}
};
it("promptManager.buildPrompt should be called with parameters containing the passed values", (() => {
const buildPromptSpy = jest.spyOn(promptManager, "buildPrompt");
command.execute(params, callbacks);
expect(buildPromptSpy).toHaveBeenCalledTimes(1);
expect(promptManager.buildPrompt).toHaveBeenCalledWith("changeStyle", {
system: {
writingStyle: params.writingStyle
},
user: {
text: params.text
}
})
}));
it("promptManager.buildPrompt should should return prompt with passed values", (() => {
jest.spyOn(promptManager, "buildPrompt");
command.execute(params, callbacks);
expect(promptManager.buildPrompt).toHaveReturnedWith({
system: "Rewrite the text provided to match the creative writing style. Ensure the rewritten text follows the grammatical rules and stylistic conventions of the specified style. Preserve the original meaning and context. Use complete sentences and a professional tone. Return answer with no markdown formatting.",
user: params.text
})
}));
it("should call provider.sendRequest once and return the abort function", (() => {
const sendRequestSpy = jest.spyOn(requestManager, "sendRequest");
const abort = command.execute(params, callbacks);
expect(typeof abort).toBe("function");
expect(sendRequestSpy).toHaveBeenCalledTimes(1)
}))
}))
}));