mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-12-06 06:46:23 +01:00
Print template strings in plain quotes unless they can't round-trip (#708)
This commit is contained in:
1 parent
6e7f23a778
commit
23d369d84e
6 files changed
+191
-19
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import type { HttpRequest } from "@yaakapp-internal/models";
|
||||
import { describe, expect, test, vi } from "vite-plus/test";
|
||||
|
||||
// resolvedModelName only reads plain model fields, but its module imports pull in the
|
||||
// platform singleton, which needs a browser. Stub them out to keep this a pure unit test.
|
||||
vi.mock("@yaakapp-internal/models", () => ({ foldersAtom: {} }));
|
||||
vi.mock("./jotai", () => ({ jotaiStore: { get: () => [] } }));
|
||||
|
||||
const { resolvedModelName } = await import("./resolvedModelName");
|
||||
|
||||
function httpRequest(url: string): HttpRequest {
|
||||
return { id: "rq_test", model: "http_request", name: "", url } as HttpRequest;
|
||||
}
|
||||
|
||||
describe("resolvedModelName", () => {
|
||||
test("returns the name when there is one", () => {
|
||||
expect(
|
||||
resolvedModelName({ ...httpRequest("https://example.com"), name: "My Request" }),
|
||||
).toEqual("My Request");
|
||||
});
|
||||
|
||||
test("replaces a simple tag with its contents", () => {
|
||||
expect(resolvedModelName(httpRequest("${[ base_url ]}/users"))).toEqual("base_url/users");
|
||||
});
|
||||
|
||||
test("replaces a tag containing a quoted argument with a space", () => {
|
||||
expect(resolvedModelName(httpRequest("${[ fn(arg='my key') ]}/users"))).toEqual(
|
||||
"fn(arg='my key')/users",
|
||||
);
|
||||
});
|
||||
|
||||
test("replaces each tag in a multi-tag string", () => {
|
||||
expect(
|
||||
resolvedModelName(httpRequest("${[ fn(arg='my key') ]}/a/${[ other(b='x y') ]}/b")),
|
||||
).toEqual("fn(arg='my key')/a/other(b='x y')/b");
|
||||
});
|
||||
|
||||
test("stops each tag at its first closing bracket", () => {
|
||||
expect(resolvedModelName(httpRequest("${[ a ]}${[ b ]}"))).toEqual("ab");
|
||||
});
|
||||
|
||||
test("strips the protocol", () => {
|
||||
expect(resolvedModelName(httpRequest("https://example.com/${[ path ]}"))).toEqual(
|
||||
"example.com/path",
|
||||
);
|
||||
});
|
||||
|
||||
test("falls back to a generic name when the url is empty", () => {
|
||||
expect(resolvedModelName(httpRequest(""))).toEqual("HTTP Request");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user