-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathhomepageCustomizable.test.ts
More file actions
208 lines (183 loc) · 8.23 KB
/
Copy pathhomepageCustomizable.test.ts
File metadata and controls
208 lines (183 loc) · 8.23 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* Copyright Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect, BrowserContext, Page } from '@playwright/test';
import { TestUtils } from './utils/testUtils.js';
import { HomePageCustomization } from './pages/homePageCustomization.js';
import { runAccessibilityTests } from './utils/accessibility.js';
import { getTranslations } from './utils/translations.js';
test.describe.serial('Dynamic Home Page Customization', () => {
let testUtils: TestUtils;
let homePageCustomization: HomePageCustomization;
let sharedPage: Page;
let sharedContext: BrowserContext;
const translations = getTranslations('en');
test.beforeAll(async ({ browser }) => {
sharedContext = await browser.newContext();
sharedPage = await sharedContext.newPage();
testUtils = new TestUtils(sharedPage);
homePageCustomization = new HomePageCustomization(sharedPage);
const loginUrl = process.env.APP_MODE === 'nfs' ? '/' : '/customizable';
await testUtils.loginAsGuest(loginUrl);
});
test.afterAll(async () => {
await sharedContext.close();
});
test('Verify Cards Display After Login', async ({
browser: _browser,
}, testInfo) => {
await homePageCustomization.verifyHomePageLoaded();
await homePageCustomization.verifyAllCardsDisplayed();
await homePageCustomization.verifyEditButtonVisible();
await runAccessibilityTests(sharedPage, testInfo);
});
test('Verify All Cards Can Be Resized in Edit Mode', async ({
browser: _browser,
}, testInfo) => {
await homePageCustomization.enterEditMode();
await runAccessibilityTests(sharedPage, testInfo);
await homePageCustomization.resizeAllCards();
await homePageCustomization.exitEditMode();
});
test('Verify Cards Can Be Individually Deleted in Edit Mode', async ({
browser: _browser,
}, testInfo) => {
await homePageCustomization.enterEditMode();
await homePageCustomization.deleteAllCards();
await homePageCustomization.verifyCardsDeleted();
await runAccessibilityTests(sharedPage, testInfo);
});
test('Verify Restore Default Cards', async ({
browser: _browser,
}, testInfo) => {
await homePageCustomization.restoreDefaultWidgets();
await homePageCustomization.verifyCardsRestored();
await runAccessibilityTests(sharedPage, testInfo);
});
test('Verify All Cards can be Deleted with Clear all Button', async () => {
await homePageCustomization.enterEditMode();
await homePageCustomization.clearAllCardsWithButton();
await homePageCustomization.verifyCardsDeleted();
});
test('Verify Add Widget Button Adds Cards', async () => {
await homePageCustomization.addWidget(translations.onboarding.title);
await expect(
sharedPage.getByText(/Good (morning|afternoon|evening)/),
).toBeVisible();
await homePageCustomization.addWidget(translations.quickAccess.title);
await expect(
sharedPage.getByText(translations.quickAccess.title),
).toBeVisible();
});
// ── Persistent storage ────────────────────────────────────────────────
test.describe('Persistent storage', () => {
test('Customizations persist across page reload', async () => {
await homePageCustomization.deleteFirstCard();
await homePageCustomization.exitEditMode();
const countBeforeReload =
await homePageCustomization.getVisibleCardCount();
expect(countBeforeReload).toBeGreaterThan(0);
await sharedPage.reload();
await homePageCustomization.verifyCardHidden(
'Good (morning|afternoon|evening)',
);
await homePageCustomization.verifyCardVisible(
translations.quickAccess.title,
);
const countAfterReload =
await homePageCustomization.getVisibleCardCount();
expect(countAfterReload).toBe(countBeforeReload);
});
test('Customizations persist across sign-out and re-login', async () => {
const countBeforeLogout =
await homePageCustomization.getVisibleCardCount();
expect(countBeforeLogout).toBeGreaterThan(0);
await testUtils.signOut();
const loginUrl = process.env.APP_MODE === 'nfs' ? '/' : '/customizable';
await testUtils.loginAsGuest(loginUrl);
await homePageCustomization.verifyCardHidden(
'Good (morning|afternoon|evening)',
);
await homePageCustomization.verifyCardVisible(
translations.quickAccess.title,
);
const countAfterLogout =
await homePageCustomization.getVisibleCardCount();
expect(countAfterLogout).toBe(countBeforeLogout);
});
});
});
// ── Persona-based homepages ──────────────────────────────────────────────
//
// Three Backstage instances running in parallel:
// - Port 3000: guest (`user:default/guest-user`, no groups)
// - Port 3001: admin (`user:default/admin-user` in `group:default/admins`)
// - Port 3002: developer (`user:default/developer-user` in `group:default/developers`)
test.describe('Persona-Based Homepages', () => {
test('Groups filters default widgets by persona', async ({ browser }) => {
// The `if: groups:` condition in `homepage.defaultWidgets` is a legacy-only
// feature — NFS does not implement group-based widget filtering.
test.skip(
process.env.APP_MODE === 'nfs',
'`if: groups:` filtering is not supported in NFS mode',
);
const loginUrl = '/customizable';
// Guest (port 3000, no groups): sees common defaults only
const guestPage = await (
await browser.newContext({ baseURL: 'http://localhost:3000' })
).newPage();
const guestHome = new HomePageCustomization(guestPage);
await new TestUtils(guestPage).loginAsGuest(loginUrl);
await guestHome.verifyHomePageLoaded();
await expect(
guestPage.getByText(/Good (morning|afternoon|evening), Guest/),
).toBeVisible();
await guestHome.verifyCardVisible('Explore Your Software Catalog');
await guestHome.verifyCardVisible('Explore Templates');
await guestHome.verifyCardVisible('Quick Access');
await guestHome.verifyCardHidden('Featured Docs');
await guestHome.verifyCardHidden('Recently Visited');
// Admin (port 3001, group:default/admins): sees common + Featured Docs, Starred Entities
const adminPage = await (
await browser.newContext({ baseURL: 'http://localhost:3001' })
).newPage();
const adminHome = new HomePageCustomization(adminPage);
await new TestUtils(adminPage).loginAsGuest(loginUrl);
await adminHome.verifyHomePageLoaded();
await expect(
adminPage.getByText(/Good (morning|afternoon|evening), Admin-user/),
).toBeVisible();
await adminHome.verifyCardVisible('Explore Your Software Catalog');
await adminHome.verifyCardVisible('Explore Templates');
await adminHome.verifyCardVisible('Quick Access');
await adminHome.verifyCardVisible('Featured Docs');
await adminHome.verifyCardHidden('Recently Visited');
// Developer (port 3002, group:default/developers): sees common + Recently Visited, Top Visited
const devPage = await (
await browser.newContext({ baseURL: 'http://localhost:3002' })
).newPage();
const devHome = new HomePageCustomization(devPage);
await new TestUtils(devPage).loginAsGuest(loginUrl);
await devHome.verifyHomePageLoaded();
await expect(
devPage.getByText(/Good (morning|afternoon|evening), Developer-user/),
).toBeVisible();
await devHome.verifyCardVisible('Explore Your Software Catalog');
await devHome.verifyCardVisible('Explore Templates');
await devHome.verifyCardVisible('Quick Access');
await devHome.verifyCardVisible('Recently Visited');
await devHome.verifyCardHidden('Featured Docs');
});
});