@xynogen/pix-core 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,17 +7,21 @@
7
7
 
8
8
  import { describe, expect, test } from "bun:test";
9
9
  import {
10
- type OptionData,
11
- type QuestionData,
12
10
  buildResponseText,
13
11
  formatAnswerScalar,
14
12
  hasAnyPreview,
13
+ type OptionData,
14
+ type QuestionData,
15
15
  sentinelsFor,
16
16
  } from "./ask.ts";
17
17
 
18
18
  // ── Fixtures ──────────────────────────────────────────────────────────
19
19
 
20
- const opt = (label: string, description = "Test option", preview?: string): OptionData => ({
20
+ const opt = (
21
+ label: string,
22
+ description = "Test option",
23
+ preview?: string,
24
+ ): OptionData => ({
21
25
  label,
22
26
  description,
23
27
  ...(preview ? { preview } : {}),
@@ -55,10 +59,7 @@ const qWithPreview: QuestionData = {
55
59
  const qSingleNoPreview: QuestionData = {
56
60
  question: "Color?",
57
61
  header: "Color",
58
- options: [
59
- opt("Red", "Ruby red"),
60
- opt("Blue", "Ocean blue"),
61
- ],
62
+ options: [opt("Red", "Ruby red"), opt("Blue", "Ocean blue")],
62
63
  };
63
64
 
64
65
  // ── hasAnyPreview ─────────────────────────────────────────────────────
@@ -85,8 +86,8 @@ describe("sentinelsFor", () => {
85
86
  test('single-select without preview appends "Type something."', () => {
86
87
  const r = sentinelsFor(qSingleNoPreview);
87
88
  expect(r).toHaveLength(1);
88
- expect(r[0]!.kind).toBe("other");
89
- expect(r[0]!.label).toBe("Type something.");
89
+ expect(r[0]?.kind).toBe("other");
90
+ expect(r[0]?.label).toBe("Type something.");
90
91
  });
91
92
 
92
93
  test('single-select with preview appends nothing (only "Chat about this" is separate)', () => {
@@ -97,8 +98,8 @@ describe("sentinelsFor", () => {
97
98
  test('multi-select appends "Next"', () => {
98
99
  const r = sentinelsFor(qMulti);
99
100
  expect(r).toHaveLength(1);
100
- expect(r[0]!.kind).toBe("next");
101
- expect(r[0]!.label).toBe("Next");
101
+ expect(r[0]?.kind).toBe("next");
102
+ expect(r[0]?.label).toBe("Next");
102
103
  });
103
104
 
104
105
  test("multi-select never appends Type something.", () => {
@@ -109,14 +110,14 @@ describe("sentinelsFor", () => {
109
110
  test("empty options still gets freeform sentinel (no preview = single-select)", () => {
110
111
  const r = sentinelsFor({ question: "?", header: "X", options: [] });
111
112
  expect(r).toHaveLength(1);
112
- expect(r[0]!.kind).toBe("other");
113
+ expect(r[0]?.kind).toBe("other");
113
114
  });
114
115
  });
115
116
 
116
117
  // ── formatAnswerScalar ────────────────────────────────────────────────
117
118
 
118
119
  describe("formatAnswerScalar", () => {
119
- test('option kind returns the answer string', () => {
120
+ test("option kind returns the answer string", () => {
120
121
  const a = {
121
122
  questionIndex: 0,
122
123
  question: "Q",
@@ -126,7 +127,7 @@ describe("formatAnswerScalar", () => {
126
127
  expect(formatAnswerScalar(a)).toBe("REST");
127
128
  });
128
129
 
129
- test('multi kind joins selected with comma', () => {
130
+ test("multi kind joins selected with comma", () => {
130
131
  const a = {
131
132
  questionIndex: 0,
132
133
  question: "Q",
@@ -137,7 +138,7 @@ describe("formatAnswerScalar", () => {
137
138
  expect(formatAnswerScalar(a)).toBe("Auth, Search");
138
139
  });
139
140
 
140
- test('custom kind returns the typed text', () => {
141
+ test("custom kind returns the typed text", () => {
141
142
  const a = {
142
143
  questionIndex: 0,
143
144
  question: "Q",
@@ -147,7 +148,7 @@ describe("formatAnswerScalar", () => {
147
148
  expect(formatAnswerScalar(a)).toBe("my custom answer");
148
149
  });
149
150
 
150
- test('chat kind returns (chat)', () => {
151
+ test("chat kind returns (chat)", () => {
151
152
  const a = {
152
153
  questionIndex: 0,
153
154
  question: "Q",
@@ -163,7 +164,12 @@ describe("formatAnswerScalar", () => {
163
164
  describe("buildResponseText", () => {
164
165
  test("formats single answer", () => {
165
166
  const answers = [
166
- { questionIndex: 0, question: "Which approach?", kind: "option" as const, answer: "REST" },
167
+ {
168
+ questionIndex: 0,
169
+ question: "Which approach?",
170
+ kind: "option" as const,
171
+ answer: "REST",
172
+ },
167
173
  ];
168
174
  const text = buildResponseText(answers, [qSingle]);
169
175
  expect(text).toContain("REST");
@@ -202,7 +208,12 @@ describe("buildResponseText", () => {
202
208
  test("formats multiple answers", () => {
203
209
  const qs = [qSingle, qMulti];
204
210
  const answers = [
205
- { questionIndex: 0, question: "Which approach?", kind: "option" as const, answer: "GraphQL" },
211
+ {
212
+ questionIndex: 0,
213
+ question: "Which approach?",
214
+ kind: "option" as const,
215
+ answer: "GraphQL",
216
+ },
206
217
  {
207
218
  questionIndex: 1,
208
219
  question: "Which features?",