page-title.test.ts94 lines · main
1import { describe, expect, it } from 'vitest'
2
3import { buildStudioPageTitle, STUDIO_PAGE_TITLE_SEPARATOR } from './page-title'
4
5describe('buildStudioPageTitle', () => {
6 it('builds a project-scoped title in most-specific-first order', () => {
7 expect(
8 buildStudioPageTitle({
9 surface: 'Database',
10 project: 'Acme Project',
11 org: 'Acme Org',
12 brand: 'Briven',
13 })
14 ).toBe(
15 `Database${STUDIO_PAGE_TITLE_SEPARATOR}Acme Project${STUDIO_PAGE_TITLE_SEPARATOR}Acme Org${STUDIO_PAGE_TITLE_SEPARATOR}Briven`
16 )
17 })
18
19 it('includes entity and section when provided', () => {
20 expect(
21 buildStudioPageTitle({
22 entity: 'users',
23 section: 'Tables',
24 surface: 'Database',
25 project: 'Acme Project',
26 org: 'Acme Org',
27 brand: 'Briven',
28 })
29 ).toBe(
30 `users${STUDIO_PAGE_TITLE_SEPARATOR}Tables${STUDIO_PAGE_TITLE_SEPARATOR}Database${STUDIO_PAGE_TITLE_SEPARATOR}Acme Project${STUDIO_PAGE_TITLE_SEPARATOR}Acme Org${STUDIO_PAGE_TITLE_SEPARATOR}Briven`
31 )
32 })
33
34 it('omits missing segments', () => {
35 expect(
36 buildStudioPageTitle({
37 section: 'Authentication',
38 project: 'Acme Project',
39 brand: 'Briven',
40 })
41 ).toBe(
42 `Authentication${STUDIO_PAGE_TITLE_SEPARATOR}Acme Project${STUDIO_PAGE_TITLE_SEPARATOR}Briven`
43 )
44 })
45
46 it('deduplicates adjacent segments case-insensitively', () => {
47 expect(
48 buildStudioPageTitle({
49 section: 'Database',
50 surface: 'database',
51 project: 'Acme Project',
52 org: 'Acme Org',
53 brand: 'Briven',
54 })
55 ).toBe(
56 `Database${STUDIO_PAGE_TITLE_SEPARATOR}Acme Project${STUDIO_PAGE_TITLE_SEPARATOR}Acme Org${STUDIO_PAGE_TITLE_SEPARATOR}Briven`
57 )
58 })
59
60 it('normalizes whitespace in each segment', () => {
61 expect(
62 buildStudioPageTitle({
63 entity: ' hello world ',
64 surface: ' Edge Functions ',
65 brand: ' Briven ',
66 })
67 ).toBe(
68 `hello world${STUDIO_PAGE_TITLE_SEPARATOR}Edge Functions${STUDIO_PAGE_TITLE_SEPARATOR}Briven`
69 )
70 })
71
72 it('truncates very long segments', () => {
73 const longName = 'x'.repeat(80)
74
75 expect(
76 buildStudioPageTitle({
77 entity: longName,
78 surface: 'Table Editor',
79 brand: 'Briven',
80 })
81 ).toBe(
82 `${'x'.repeat(59)}…${STUDIO_PAGE_TITLE_SEPARATOR}Table Editor${STUDIO_PAGE_TITLE_SEPARATOR}Briven`
83 )
84 })
85
86 it('supports custom brand titles', () => {
87 expect(
88 buildStudioPageTitle({
89 surface: 'Settings',
90 brand: 'Briven Studio',
91 })
92 ).toBe(`Settings${STUDIO_PAGE_TITLE_SEPARATOR}Briven Studio`)
93 })
94})