-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprograms.e2e.js
More file actions
302 lines (248 loc) · 11 KB
/
programs.e2e.js
File metadata and controls
302 lines (248 loc) · 11 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
const { expect } = require('@wdio/globals');
const programsPage = require('../pageobjects/programs.page');
const morePage = require('../pageobjects/more.page');
const { ensureLoggedIn } = require('../pageobjects/utils/auth.helper');
const navigation = require('../pageobjects/utils/navigation.page');
const { apiClient } = require('../utils/api-client');
const { isAndroid } = require('../pageobjects/utils/selectors');
const { TIMEOUT, PAUSE, REGEX } = require('../pageobjects/utils/constants');
describe('Programs Page', () => {
// Data state flags - set once in before() to avoid redundant checks
let hasProgramsData = false;
let hasEmptyState = false;
let apiProgramsAvailable = false;
/**
* Navigate to Programs page via More menu
*/
async function navigateToPrograms() {
// First ensure we're on a page with footer visible
await programsPage.footer.moreTab.click();
await browser.pause(PAUSE.NAVIGATION);
// Click Programs menu item
await morePage.programsMenuItem.click();
await programsPage.waitForScreenReady();
}
before(async function () {
this.timeout(TIMEOUT.TEST_SETUP_LONG);
await ensureLoggedIn();
// Navigate to home page once after login
await navigation.ensureHomePage({ resetFilters: false });
// Navigate to Programs page via More menu
await navigateToPrograms();
// Check data state ONCE and cache the results
hasProgramsData = await programsPage.hasPrograms();
hasEmptyState = !hasProgramsData && await programsPage.emptyState.isDisplayed().catch(() => false);
apiProgramsAvailable = !!process.env.API_OPS_TOKEN;
console.info(`📊 Programs data state: hasPrograms=${hasProgramsData}, emptyState=${hasEmptyState}, apiAvailable=${apiProgramsAvailable}`);
});
beforeEach(async function () {
// Ensure we're on Programs page
const isOnPrograms = await programsPage.isOnProgramsPage();
if (!isOnPrograms) {
await navigateToPrograms();
}
});
describe('Navigation', () => {
it('should be accessible from More menu', async () => {
// Navigate away first
await programsPage.goBack();
await browser.pause(PAUSE.NAVIGATION);
// Navigate back to Programs
await morePage.programsMenuItem.click();
await programsPage.waitForScreenReady();
await expect(programsPage.headerTitle).toBeDisplayed();
});
it('should display Go back button', async () => {
await expect(programsPage.goBackButton).toBeDisplayed();
});
it('should navigate back to More page when back button tapped', async () => {
await programsPage.goBack();
// Verify we're back on More page by checking for Programs menu item
await expect(morePage.programsMenuItem).toBeDisplayed();
// Navigate back to Programs for subsequent tests
await morePage.programsMenuItem.click();
await programsPage.waitForScreenReady();
});
});
describe('Page Structure', () => {
it('should display the Programs header title', async () => {
await expect(programsPage.headerTitle).toBeDisplayed();
});
it('should display the account button in header', async function () {
const isDisplayed = await programsPage.accountButton.isDisplayed().catch(() => false);
if (!isDisplayed && isAndroid()) {
this.skip();
return;
}
await expect(programsPage.accountButton).toBeDisplayed();
});
it('should display all footer navigation tabs', async () => {
await expect(programsPage.footer.spotlightsTab).toBeDisplayed();
await expect(programsPage.footer.chatTab).toBeDisplayed();
await expect(programsPage.footer.subscriptionsTab).toBeDisplayed();
await expect(programsPage.footer.moreTab).toBeDisplayed();
});
it('should have More tab selected', async () => {
const moreTab = programsPage.footer.moreTab;
if (isAndroid()) {
// Android uses 'selected' attribute
const selected = await moreTab.getAttribute('selected');
expect(selected).toBe('true');
} else {
// iOS uses 'value' attribute
const value = await moreTab.getAttribute('value');
expect(value).toBe('1');
}
});
});
describe('Empty State', () => {
// This test suite runs when user has no programs
it('should display empty state when no programs exist', async function () {
if (hasProgramsData || !hasEmptyState) {
this.skip();
return;
}
await expect(programsPage.emptyState).toBeDisplayed();
await expect(programsPage.noProgramsTitle).toBeDisplayed();
await expect(programsPage.noProgramsDescription).toBeDisplayed();
});
it('should display "No programs" title text', async function () {
if (hasProgramsData || !hasEmptyState) {
this.skip();
return;
}
const titleText = await programsPage.noProgramsTitle.getText();
expect(titleText).toBe('No programs');
});
it('should display "No programs found." description', async function () {
if (hasProgramsData || !hasEmptyState) {
this.skip();
return;
}
const descriptionText = await programsPage.noProgramsDescription.getText();
expect(descriptionText).toBe('No programs found.');
});
});
describe('Programs List', () => {
// This test suite runs when user has programs data
it('should display programs list when programs exist', async function () {
if (!hasProgramsData) {
this.skip();
return;
}
await expect(programsPage.programsScrollView).toBeDisplayed();
const programsCount = await programsPage.getVisibleProgramsCount();
expect(programsCount).toBeGreaterThan(0);
});
it('should display program items with ID and status', async function () {
if (!hasProgramsData) {
this.skip();
return;
}
const firstProgram = programsPage.firstProgramItem;
await expect(firstProgram).toBeDisplayed();
const details = await programsPage.getProgramDetails(firstProgram);
// Programs use 3-group IDs: PRG-XXXX-XXXX
expect(details.programId).toMatch(REGEX.PROGRAM_ID);
expect(['Unpublished', 'Draft', 'Published']).toContain(details.status);
});
it('should detect all loaded programs in the list', async function () {
if (!hasProgramsData) {
this.skip();
return;
}
const programsCount = await programsPage.getVisibleProgramsCount();
const programIds = await programsPage.getVisibleProgramIds();
console.info(`Total programs detected: ${programsCount}`);
console.info(`First 5 program IDs: ${programIds.slice(0, 5).join(', ')}`);
console.info(`Last 5 program IDs: ${programIds.slice(-5).join(', ')}`);
expect(programsCount).toBeGreaterThan(0);
// Verify all program IDs have valid format (3-group)
for (const programId of programIds) {
expect(programId).toMatch(REGEX.PROGRAM_ID);
}
});
it('should not display empty state when programs exist', async function () {
if (!hasProgramsData) {
this.skip();
return;
}
const emptyStateVisible = await programsPage.emptyState.isDisplayed().catch(() => false);
expect(emptyStateVisible).toBe(false);
});
});
describe('Programs by Status', () => {
it('should be able to display different statuses', async function () {
if (!hasProgramsData) {
this.skip();
return;
}
const unpublishedPrograms = await programsPage.getProgramsByStatus('Unpublished');
const draftPrograms = await programsPage.getProgramsByStatus('Draft');
const publishedPrograms = await programsPage.getProgramsByStatus('Published');
// At least one status should have programs
const totalStatusPrograms = unpublishedPrograms.length + draftPrograms.length + publishedPrograms.length;
expect(totalStatusPrograms).toBeGreaterThanOrEqual(0);
console.info(`Programs by status - Unpublished: ${unpublishedPrograms.length}, Draft: ${draftPrograms.length}, Published: ${publishedPrograms.length}`);
});
});
describe('API Integration', () => {
it('should match API programs count with visible programs', async function () {
// Skip if API token not configured or no programs in UI
if (!apiProgramsAvailable || !hasProgramsData) {
this.skip();
return;
}
try {
const apiPrograms = await apiClient.getPrograms({ limit: 100 });
const apiProgramsList = apiPrograms.data || apiPrograms;
const apiCount = apiProgramsList.length;
const uiCount = await programsPage.getVisibleProgramsCount();
console.info(`[Count Compare] API programs: ${apiCount}, UI visible programs: ${uiCount}`);
// UI should show at least some programs if API has programs
if (apiCount > 0) {
expect(uiCount).toBeGreaterThan(0);
}
} catch (error) {
console.warn('API check skipped:', error.message);
this.skip();
}
});
it('should verify first 10 program IDs and statuses match API data', async function () {
if (!apiProgramsAvailable || !hasProgramsData) {
this.skip();
return;
}
try {
const apiPrograms = await apiClient.getPrograms({ limit: 10 });
const apiProgramsList = apiPrograms.data || apiPrograms;
const uiProgramIds = await programsPage.getVisibleProgramIds();
const uiProgramsWithStatus = await programsPage.getVisibleProgramsWithStatus();
// Compare each API program with UI and log results
const comparisons = [];
for (let i = 0; i < Math.min(apiProgramsList.length, 10); i++) {
const apiProgram = apiProgramsList[i];
const apiProgramId = apiProgram.programId || apiProgram.id;
const apiStatus = apiProgram.status;
const uiProgram = uiProgramsWithStatus[i] || {};
const uiProgramId = uiProgram.programId;
const uiStatus = uiProgram.status;
const idMatches = apiProgramId === uiProgramId;
const statusMatches = apiStatus === uiStatus;
console.info(`[${i + 1}] ID: ${apiProgramId} vs ${uiProgramId} ${idMatches ? '✓' : '✗'} | Status: ${apiStatus} vs ${uiStatus} ${statusMatches ? '✓' : '✗'}`);
comparisons.push({ apiProgramId, uiProgramId, idMatches, apiStatus, uiStatus, statusMatches });
}
const idMatchCount = comparisons.filter(c => c.idMatches).length;
const statusMatchCount = comparisons.filter(c => c.statusMatches).length;
console.info(`Match summary - IDs: ${idMatchCount}/${comparisons.length}, Statuses: ${statusMatchCount}/${comparisons.length}`);
// Verify all visible UI programs have valid format (3-group)
for (const uiProgramId of uiProgramIds.slice(0, 10)) {
expect(uiProgramId).toMatch(REGEX.PROGRAM_ID);
}
} catch (error) {
console.warn('API verification skipped:', error.message);
this.skip();
}
});
});
});