-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpid-parsing.test.js
More file actions
163 lines (128 loc) · 5.91 KB
/
Copy pathpid-parsing.test.js
File metadata and controls
163 lines (128 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { describe, test, expect } from 'vitest';
// ── Static PID builders ─────────────────────────────────────────
describe('EstreUiPage — static PID builders', () => {
test('getPidComponent: main + static', () => {
expect(EstreUiPage.getPidComponent('home', 'main', 'static'))
.toBe('$s&m=home');
});
test('getPidComponent: overlay + instant', () => {
expect(EstreUiPage.getPidComponent('dialog', 'overlay', 'instant'))
.toBe('$i&o=dialog');
});
test('getPidComponent: blind, no statement', () => {
expect(EstreUiPage.getPidComponent('splash', 'blind'))
.toBe('&b=splash');
});
test('getPidComponent: header', () => {
expect(EstreUiPage.getPidComponent('appbar', 'header', 'static'))
.toBe('$s&h=appbar');
});
test('getPidComponent: menu', () => {
expect(EstreUiPage.getPidComponent('menuArea', 'menu', 'static'))
.toBe('$s&u=menuArea');
});
test('getPidComponent: null id → null', () => {
expect(EstreUiPage.getPidComponent(null, 'main')).toBeNull();
});
test('getPidComponent: empty id → null', () => {
expect(EstreUiPage.getPidComponent('', 'main')).toBeNull();
});
test('getPidComponent: invalid sectionBound → null', () => {
expect(EstreUiPage.getPidComponent('home', 'unknown')).toBeNull();
});
test('getPidContainer: builds component#container', () => {
expect(EstreUiPage.getPidContainer('root', 'home', 'main', 'static'))
.toBe('$s&m=home#root');
});
test('getPidContainer: null componentId → undefined', () => {
expect(EstreUiPage.getPidContainer('root', null, 'main'))
.toBeUndefined();
});
test('getPidArticle: builds component#container@article', () => {
expect(EstreUiPage.getPidArticle('detail', 'root', 'home', 'main', 'static'))
.toBe('$s&m=home#root@detail');
});
test('getPidArticle: instant overlay', () => {
expect(EstreUiPage.getPidArticle('form', 'content', 'functional', 'overlay', 'instant'))
.toBe('$i&o=functional#content@form');
});
});
// ── Static PID strippers ────────────────────────────────────────
describe('EstreUiPage — PID strippers', () => {
test('getPidStatementless: removes $s prefix', () => {
expect(EstreUiPage.getPidStatementless('$s&m=home#root'))
.toBe('&m=home#root');
});
test('getPidStatementless: removes $i prefix', () => {
expect(EstreUiPage.getPidStatementless('$i&o=dialog'))
.toBe('&o=dialog');
});
test('getPidStatementless: no statement prefix → unchanged', () => {
expect(EstreUiPage.getPidStatementless('&m=home'))
.toBe('&m=home');
});
test('getPidOriginless: removes instance origin after ^', () => {
expect(EstreUiPage.getPidOriginless('$s&m=home^origin1'))
.toBe('$s&m=home');
});
test('getPidOriginless: no ^ → unchanged', () => {
expect(EstreUiPage.getPidOriginless('$s&m=home#root'))
.toBe('$s&m=home#root');
});
test('getPidSeamless: strips both statement and origin', () => {
expect(EstreUiPage.getPidSeamless('$i&o=dialog^session123'))
.toBe('&o=dialog');
});
});
// ── Instance PID construction via setters ───────────────────────
describe('EstreUiPage — pid getter via manual construction', () => {
function buildPage({ sectionBound, component, container, article, statement }) {
const page = new EstreUiPage();
if (sectionBound) page.setSectionBound(sectionBound);
if (component) page.setComponent(component);
if (container) page.setContainer(container);
if (article) page.setArticle(article);
return page;
}
test('component-only PID', () => {
const page = buildPage({ sectionBound: 'main', component: 'home' });
expect(page.pid).toBe('$&m=home');
expect(page.hostType).toBe('component');
expect(page.isComponent).toBe(true);
expect(page.isContainer).toBe(false);
expect(page.isMain).toBe(true);
});
test('component + container PID', () => {
const page = buildPage({ sectionBound: 'main', component: 'home', container: 'root' });
expect(page.pid).toBe('$&m=home#root');
expect(page.hostType).toBe('container');
expect(page.isContainer).toBe(true);
});
test('full article PID', () => {
const page = buildPage({ sectionBound: 'overlay', component: 'functional', container: 'content', article: 'form' });
expect(page.pid).toBe('$&o=functional#content@form');
expect(page.hostType).toBe('article');
expect(page.isArticle).toBe(true);
expect(page.isOverlay).toBe(true);
});
test('sectionBound accessors', () => {
const page = buildPage({ sectionBound: 'blind', component: 'splash' });
expect(page.isBlinded).toBe(true);
expect(page.isMain).toBe(false);
});
test('id returns deepest level', () => {
const pageComp = buildPage({ sectionBound: 'main', component: 'home' });
expect(pageComp.id).toBe('home');
const pageCont = buildPage({ sectionBound: 'main', component: 'home', container: 'root' });
expect(pageCont.id).toBe('root');
const pageArt = buildPage({ sectionBound: 'main', component: 'home', container: 'root', article: 'detail' });
expect(pageArt.id).toBe('detail');
});
test('setComponent is idempotent (first call wins)', () => {
const page = new EstreUiPage();
page.setSectionBound('main');
page.setComponent('first');
page.setComponent('second');
expect(page.component).toBe('first');
});
});