-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslice-view.test.ts
More file actions
68 lines (61 loc) · 2.14 KB
/
slice-view.test.ts
File metadata and controls
68 lines (61 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { buildSlice, it } from "./it";
import { insertSlice } from "./prismic";
it("supports --help", async ({ expect, prismic }) => {
const { stdout, exitCode } = await prismic("slice", ["view", "--help"]);
expect(exitCode).toBe(0);
expect(stdout).toContain("prismic slice view <name> [options]");
});
it("views a slice", async ({ expect, prismic, repo, token, host }) => {
const slice = buildSlice();
await insertSlice(slice, { repo, token, host });
const { stdout, exitCode } = await prismic("slice", ["view", slice.name]);
expect(exitCode).toBe(0);
expect(stdout).toContain(`ID: ${slice.id}`);
expect(stdout).toContain(`Name: ${slice.name}`);
expect(stdout).toContain("default:");
});
it("shows fields per variation", async ({ expect, prismic, repo, token, host }) => {
const slice = buildSlice({
variations: [
{
id: "default",
name: "Default",
docURL: "",
version: "initial",
description: "Default",
imageUrl: "",
primary: {
title: { type: "StructuredText", config: { label: "Title", placeholder: "Enter title" } },
is_active: { type: "Boolean", config: { label: "Is Active" } },
},
},
{
id: "withImage",
name: "With Image",
docURL: "",
version: "initial",
description: "With Image",
imageUrl: "",
primary: {
image: { type: "Image", config: { label: "Image" } },
},
},
],
});
await insertSlice(slice, { repo, token, host });
const { stdout, exitCode } = await prismic("slice", ["view", slice.name]);
expect(exitCode).toBe(0);
expect(stdout).toContain("default:");
expect(stdout).toMatch(/title\s+StructuredText\s+Title\s+"Enter title"/);
expect(stdout).toMatch(/is_active\s+Boolean\s+Is Active/);
expect(stdout).toContain("withImage:");
expect(stdout).toMatch(/image\s+Image\s+Image/);
});
it("views a slice as JSON", async ({ expect, prismic, repo, token, host }) => {
const slice = buildSlice();
await insertSlice(slice, { repo, token, host });
const { stdout, exitCode } = await prismic("slice", ["view", slice.name, "--json"]);
expect(exitCode).toBe(0);
const parsed = JSON.parse(stdout);
expect(parsed).toMatchObject({ id: slice.id, name: slice.name });
});