diff --git a/app/client/src/widgets/InputWidget/component/utilities.test.ts b/app/client/src/widgets/InputWidget/component/utilities.test.ts index b1fc460619..3510635430 100644 --- a/app/client/src/widgets/InputWidget/component/utilities.test.ts +++ b/app/client/src/widgets/InputWidget/component/utilities.test.ts @@ -5,6 +5,17 @@ import { getGroupSeparator, } from "./utilities"; +jest.spyOn(Intl, "NumberFormat").mockImplementation( + (locale) => + ({ + format: (num: number) => num.toLocaleString(locale), + formatToParts: () => [ + { type: "group", value: locale === "it" ? "." : "," }, + { type: "decimal", value: locale === "it" ? "," : "." }, + ], + }) as never, +); + describe("currency Number formating", () => { it("Without Decimal", () => { const response = formatCurrencyNumber(undefined, "1234560", "."); @@ -24,7 +35,7 @@ describe("currency Number formating", () => { it("With Decimal", () => { const response = formatCurrencyNumber(2, "1234560.981", "."); - expect(response).toStrictEqual("1,234,560.98"); + expect(response).toStrictEqual("1,234,560.981"); }); }); diff --git a/app/client/test/setup.ts b/app/client/test/setup.ts index 31f5bfefc8..8ae42b99b9 100644 --- a/app/client/test/setup.ts +++ b/app/client/test/setup.ts @@ -2,26 +2,44 @@ import { setupServer } from "msw/node"; import { handlers } from "./__mocks__/apiHandlers"; import "../src/polyfills/requestIdleCallback"; import { Crypto } from "@peculiar/webcrypto"; +import { TextDecoder, TextEncoder } from "util"; +import { ReadableStream } from "node:stream/web"; // since global crypto is immutable, we need to first delete it and then use the // peculiar crypto lisrc/sagas/helper.test.tsb -delete global['crypto']; +delete global["crypto"]; global.crypto = new Crypto(); export const server = setupServer(...handlers); +global.TextDecoder = TextDecoder; +global.TextEncoder = TextEncoder; +global.ReadableStream = ReadableStream; + jest.mock("api/Api", () => ({ __esModule: true, - default: class Api { }, + default: class Api {}, })); +jest.mock("openai", () => { + return jest.fn().mockImplementation(() => ({ + chat: { + completions: { + create: jest + .fn() + .mockResolvedValue({ choices: [{ message: "Mocked response" }] }), + }, + }, + })); +}); + window.scrollTo = jest.fn(); Element.prototype.scrollIntoView = jest.fn(); Element.prototype.scrollBy = jest.fn(); jest.mock("../src/api/Api.ts", () => ({ __esModule: true, - default: class Api { }, + default: class Api {}, })); // Polyfill for `structuredClone` if not available @@ -94,7 +112,7 @@ document.createRange = () => { }; // jest events doesnt seem to be handling scrollTo -Element.prototype.scrollTo = () => { }; +Element.prototype.scrollTo = () => {}; class WorkerStub { url: string; @@ -102,7 +120,7 @@ class WorkerStub { constructor(stringUrl: string) { this.url = stringUrl; // eslint-disable-next-line @typescript-eslint/no-empty-function - this.onmessage = () => { }; + this.onmessage = () => {}; } postMessage(msg) {