Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

test: cover profile auto-naming helper

Ilia Avdeevd6f51c357c51
diff --git a/web/tests/profile-naming.test.ts b/web/tests/profile-naming.test.ts
new file mode 100644
index 000000000..dd1646e68
--- /dev/null
+++ b/web/tests/profile-naming.test.ts
@@ -0,0 +1,32 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+
+import { nextProfileName } from "../components/settings/profile-naming";
+
+test("an auto name (matching the previous provider) tracks the new provider", () => {
+ assert.equal(nextProfileName("Brave", "Brave", "Jina"), "Jina");
+});
+
+test("an empty name is filled from the new provider", () => {
+ assert.equal(nextProfileName("", "Brave", "Jina"), "Jina");
+ assert.equal(nextProfileName(" ", "Brave", "Jina"), "Jina");
+});
+
+test("a user-customized name is never overwritten", () => {
+ assert.equal(nextProfileName("My search", "Brave", "Jina"), "My search");
+});
+
+test("never overwrites with an empty provider label (e.g. deselected)", () => {
+ assert.equal(nextProfileName("Brave", "Brave", ""), "Brave");
+ assert.equal(nextProfileName("My search", "Brave", ""), "My search");
+});
+
+test("matching against the previous label ignores surrounding whitespace", () => {
+ assert.equal(nextProfileName(" Brave ", "Brave", "Jina"), "Jina");
+ assert.equal(nextProfileName("Brave", " Brave ", "Jina"), "Jina");
+});
+
+test("a name equal to the new provider is effectively unchanged", () => {
+ // Re-selecting the same provider must not corrupt the name.
+ assert.equal(nextProfileName("Jina", "Jina", "Jina"), "Jina");
+});