@things-factory/apptool-ui 10.1.278 → 10.1.279

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.
@@ -1,176 +0,0 @@
1
- import { readdirSync, readFileSync, statSync } from 'fs'
2
- import path from 'path'
3
-
4
- import { menuEntries, monogram, personName } from '../client/layout/user-menu-model'
5
-
6
- /**
7
- * The signed-in person's avatar at the right end of the header, and the menu it opens.
8
- *
9
- * Profile, settings and sign-out sat among the morendas - under the rail's 「시스템 › 관리」 next to user
10
- * management and the audit, and in more-ui's panel - and every app wrote its own settings entry. The
11
- * avatar is the band's own part, like the bell; each entry is registered once, by the module that
12
- * owns it. The drawing needs a DOM, so the deciding is tested here and the rest is read from source.
13
- */
14
-
15
- const PACKAGES = path.resolve(__dirname, '../..')
16
-
17
- /** The source with its comments stripped, so prose about a rule cannot satisfy the rule. */
18
- const code = (file: string) =>
19
- readFileSync(file, 'utf-8')
20
- .replace(/\/\*[\s\S]*?\*\//g, '')
21
- .replace(/<!--[\s\S]*?-->/g, '')
22
- .replace(/^\s*\/\/.*$/gm, '')
23
-
24
- const LAYOUT = path.resolve(__dirname, '../client/layout')
25
-
26
- describe('the menu the avatar opens', () => {
27
- it('★ entries come by their order, then as registered; one with no order sits before the about page', () => {
28
- const entries = [
29
- { name: 'about-system', order: 90 },
30
- { name: 'unordered-a' },
31
- { name: 'setting', order: 20 },
32
- { name: 'sign-out', order: 15 },
33
- { name: 'unordered-b' },
34
- { name: 'profile', order: 10 }
35
- ]
36
-
37
- expect(menuEntries(entries).map(entry => entry.name)).toEqual([
38
- 'profile',
39
- 'sign-out',
40
- 'setting',
41
- 'unordered-a',
42
- 'unordered-b',
43
- 'about-system'
44
- ])
45
- })
46
-
47
- it('does not reorder the registry it was given', () => {
48
- const entries = [{ name: 'b', order: 2 }, { name: 'a', order: 1 }]
49
-
50
- menuEntries(entries)
51
-
52
- expect(entries.map(entry => entry.name)).toEqual(['b', 'a'])
53
- })
54
-
55
- it('an empty or missing registry is an empty menu', () => {
56
- expect(menuEntries([])).toEqual([])
57
- expect(menuEntries(undefined)).toEqual([])
58
- })
59
- })
60
-
61
- describe('who the avatar is', () => {
62
- it('★ the name, or the email for one who has none', () => {
63
- expect(personName({ name: '남상혁', email: 'heartyoh@hatiolab.com' })).toBe('남상혁')
64
- expect(personName({ name: ' ', email: 'heartyoh@hatiolab.com' })).toBe('heartyoh@hatiolab.com')
65
- expect(personName(null)).toBe('')
66
- })
67
-
68
- it('★ one letter while there is no picture - a 28px circle has no room for two syllables', () => {
69
- expect(monogram('남상혁')).toBe('남')
70
- expect(monogram(' heartyoh@hatiolab.com')).toBe('H')
71
- expect(monogram('')).toBe('')
72
- expect(monogram(undefined)).toBe('')
73
- })
74
-
75
- it('a letter outside the basic plane is not cut in half', () => {
76
- expect(monogram('𠀋田')).toBe('𠀋')
77
- })
78
- })
79
-
80
- describe('both headers end with the avatar', () => {
81
- it('★ the band draws it last, after the bell', () => {
82
- const band = code(path.join(LAYOUT, 'app-header-band.ts'))
83
- const lastSlot = band.slice(band.lastIndexOf('<span class="slot fixed">'))
84
-
85
- expect(lastSlot.indexOf('this.renderBell()')).toBeGreaterThan(-1)
86
- expect(lastSlot.indexOf('<app-user-menu>')).toBeGreaterThan(lastSlot.indexOf('this.renderBell()'))
87
- expect(lastSlot.indexOf('</span>')).toBeGreaterThan(lastSlot.indexOf('<app-user-menu>'))
88
- })
89
-
90
- it('★ the app toolbar draws it last, after its rear-end tools', () => {
91
- const toolbar = code(path.join(LAYOUT, 'app-toolbar.ts'))
92
- const render = toolbar.slice(toolbar.indexOf('render()'), toolbar.indexOf('connectedCallback()'))
93
-
94
- expect(render.indexOf('<app-user-menu>')).toBeGreaterThan(render.indexOf('rearEndTools.map'))
95
- })
96
-
97
- it('★ the avatar knows no entry of its own - it reads the registry, the person and the picture from the store', () => {
98
- const avatar = code(path.join(LAYOUT, 'app-user-menu.ts'))
99
-
100
- expect(avatar).toMatch(/state\.usermenu\?\.items/)
101
- expect(avatar).toMatch(/state\.auth\?\.user/)
102
- expect(avatar).toMatch(/state\.auth\?\.picture/)
103
- expect(avatar).not.toMatch(/navigate\(|signout|'setting'|'profile'/)
104
- })
105
- })
106
-
107
- describe('the person\'s entries are registered once, to the user menu', () => {
108
- function clientFiles(dir: string): string[] {
109
- return readdirSync(dir).flatMap(entry => {
110
- if (entry === 'node_modules' || entry.startsWith('dist')) return []
111
- const file = path.join(dir, entry)
112
- return statSync(file).isDirectory() ? clientFiles(file) : /\.ts$/.test(entry) && !/\.test\.ts$/.test(entry) ? [file] : []
113
- })
114
- }
115
-
116
- const sources = readdirSync(PACKAGES)
117
- .map(name => path.join(PACKAGES, name, 'client'))
118
- .filter(dir => {
119
- try {
120
- return statSync(dir).isDirectory()
121
- } catch {
122
- return false
123
- }
124
- })
125
- .flatMap(clientFiles)
126
- .map(file => ({ file: path.relative(PACKAGES, file), text: code(file) }))
127
-
128
- /** The argument of every `store.dispatch(...)` whose action has this `type`, cut at its own closing brace. */
129
- function registrations(type: string) {
130
- return sources.flatMap(({ file, text }) =>
131
- text
132
- .split('store.dispatch(')
133
- .slice(1)
134
- .map(call => {
135
- let depth = 0
136
- for (let i = 0; i < call.length; i++) {
137
- if (call[i] === '{') depth++
138
- else if (call[i] === '}' && --depth === 0) return call.slice(0, i + 1)
139
- }
140
- return call
141
- })
142
- .filter(call => new RegExp(`^\\s*\\{\\s*type:\\s*${type}\\b`).test(call))
143
- .map(call => ({ file, call }))
144
- )
145
- }
146
-
147
- it('★ profile, one\'s gallery, settings, the about page, sign-out, writing an inquiry and the regulations are user menu entries, each from the module that owns it', () => {
148
- const named = registrations('ADD_USER_MENU').map(({ file, call }) => `${file.split(path.sep)[0]}:${/name: '([\w-]+)'/.exec(call)?.[1]}`)
149
-
150
- /* inquiry: ADR-0184 decision 9. regulations: ADR-0187 decision 10, added only for an employee of the domain. */
151
- expect(named.sort()).toEqual([
152
- 'auth-ui:profile',
153
- 'auth-ui:sign-out',
154
- 'compliance:regulations',
155
- 'gallery:my-gallery',
156
- 'inquiry:inquiry',
157
- 'setting-ui:setting',
158
- 'system:about-system'
159
- ])
160
- })
161
-
162
- it('★ the registered entries show as profile, one\'s gallery, sign-out, settings, inquiry, regulations, the about page (user, 2026-10-25; gallery right after the profile, ADR-0165 decision 6)', () => {
163
- const entries = registrations('ADD_USER_MENU').map(({ call }) => ({
164
- name: /name: '([\w-]+)'/.exec(call)![1],
165
- order: Number(/order: (\d+)/.exec(call)![1])
166
- }))
167
-
168
- expect(menuEntries(entries).map(entry => entry.name)).toEqual(['profile', 'my-gallery', 'sign-out', 'setting', 'inquiry', 'regulations', 'about-system'])
169
- })
170
-
171
- it('★ none of them is a morenda any more', () => {
172
- const morendas = registrations('ADD_MORENDA').filter(({ call }) => /navigate\('(profile|setting)'\)|auth\.signout\(\)/.test(call))
173
-
174
- expect(morendas.map(({ file }) => file)).toEqual([])
175
- })
176
- })