onboarding-wizard.test.mjs
96 lines 3.9 KB
Raw
sha256:fd47ab66017e55331b88ba3a59c34c23e4e05c5aec424251d3a404c5a7998c8e feat(hub): restore integration tile detail modals; add Herm… Human minor ⚠ breaking 16 days ago
1 import { describe, it } from 'node:test';
2 import assert from 'node:assert';
3 import {
4 ONBOARDING_LS_KEY,
5 DOCS_BASE,
6 LLM_SELF_HELP_EXPORT_PROMPT,
7 parseOnboardingState,
8 serializeOnboardingState,
9 createFreshState,
10 getStepCount,
11 shouldAutoOpenWizard,
12 getStepContent,
13 getStepSecondaryActions,
14 } from '../web/hub/onboarding-wizard.mjs';
15
16 describe('onboarding-wizard.mjs', () => {
17 it('exports a stable localStorage key', () => {
18 assert.equal(ONBOARDING_LS_KEY, 'knowtation_onboarding_v1');
19 });
20
21 it('parseOnboardingState rejects invalid JSON and wrong shape', () => {
22 assert.equal(parseOnboardingState(null), null);
23 assert.equal(parseOnboardingState(''), null);
24 assert.equal(parseOnboardingState('not json'), null);
25 assert.equal(parseOnboardingState('{}'), null);
26 assert.equal(parseOnboardingState(JSON.stringify({ v: 2, userKey: 'x', hostingPath: 'hosted', status: 'in_progress', stepIndex: 0 })), null);
27 });
28
29 it('round-trips a valid state', () => {
30 const s = createFreshState('google:abc', 'hosted');
31 s.stepIndex = 2;
32 const raw = serializeOnboardingState(s);
33 const back = parseOnboardingState(raw);
34 assert.ok(back);
35 assert.equal(back.userKey, 'google:abc');
36 assert.equal(back.hostingPath, 'hosted');
37 assert.equal(back.stepIndex, 2);
38 assert.equal(back.status, 'in_progress');
39 });
40
41 it('getStepCount matches hosted vs self-hosted flows', () => {
42 assert.equal(getStepCount(true), 9);
43 assert.equal(getStepCount(false), 5);
44 });
45
46 it('exports docs base and a non-trivial LLM export helper prompt', () => {
47 assert.ok(DOCS_BASE.includes('github.com'));
48 assert.ok(LLM_SELF_HELP_EXPORT_PROMPT.includes('Knowtation'));
49 assert.ok(LLM_SELF_HELP_EXPORT_PROMPT.length > 120);
50 });
51
52 it('shouldAutoOpenWizard: null state opens; dismissed/completed do not; in_progress opens', () => {
53 assert.equal(shouldAutoOpenWizard(null, 'u1', 'hosted'), true);
54 const dismissed = createFreshState('u1', 'hosted');
55 dismissed.status = 'dismissed';
56 assert.equal(shouldAutoOpenWizard(dismissed, 'u1', 'hosted'), false);
57 const done = createFreshState('u1', 'hosted');
58 done.status = 'completed';
59 assert.equal(shouldAutoOpenWizard(done, 'u1', 'hosted'), false);
60 const prog = createFreshState('u1', 'hosted');
61 prog.stepIndex = 2;
62 assert.equal(shouldAutoOpenWizard(prog, 'u1', 'hosted'), true);
63 });
64
65 it('shouldAutoOpenWizard: user or hosting change forces reopen', () => {
66 const st = createFreshState('u1', 'hosted');
67 st.status = 'dismissed';
68 assert.equal(shouldAutoOpenWizard(st, 'u2', 'hosted'), true);
69 const st2 = createFreshState('u1', 'hosted');
70 st2.status = 'completed';
71 assert.equal(shouldAutoOpenWizard(st2, 'u1', 'selfhosted'), true);
72 });
73
74 it('getStepContent returns plain-language blocks for each hosted step', () => {
75 for (let i = 0; i < 9; i++) {
76 const c = getStepContent(true, i);
77 assert.ok(c && c.id && c.title && c.bodyHtml.length > 20);
78 }
79 assert.equal(getStepContent(true, 3).id, 'h-imports');
80 assert.equal(getStepContent(true, 99), null);
81 });
82
83 it('getStepSecondaryActions lists expected hosted shortcuts', () => {
84 assert.ok(getStepSecondaryActions(true, 0).some((a) => a.id === 'openWhyTokenDoc'));
85 assert.ok(getStepSecondaryActions(true, 2).some((a) => a.id === 'openSettingsIntegrations'));
86 assert.ok(getStepSecondaryActions(true, 3).some((a) => a.id === 'openImportModal'));
87 assert.ok(getStepSecondaryActions(true, 4).some((a) => a.id === 'focusSuggestedTab'));
88 assert.ok(getStepSecondaryActions(true, 5).some((a) => a.id === 'projectsHelp'));
89 assert.ok(getStepSecondaryActions(true, 8).some((a) => a.id === 'openAgentIntegrationDoc'));
90 });
91
92 it('getStepSecondaryActions lists self-hosted doc jumps', () => {
93 assert.ok(getStepSecondaryActions(false, 1).some((a) => a.id === 'howToSetup4'));
94 assert.ok(getStepSecondaryActions(false, 2).some((a) => a.id === 'howToSetup3'));
95 });
96 });
File History 3 commits
sha256:fd47ab66017e55331b88ba3a59c34c23e4e05c5aec424251d3a404c5a7998c8e feat(hub): restore integration tile detail modals; add Herm… Human minor 16 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 16 days ago