Skip to content

Commit 7dfc7a5

Browse files
committed
increase inapp test coverage
1 parent 7f55bb4 commit 7dfc7a5

18 files changed

+1970
-92
lines changed
Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
11
import { test, expect } from '@playwright/test';
22
import { BasePage } from './page-objects/BasePage';
33

4-
test.describe('Authentication and Navigation', () => {
4+
const TEST_EMAIL =
5+
process.env.LOGIN_EMAIL || '[email protected]';
6+
7+
/**
8+
* SDK Authentication Test Suite
9+
*
10+
* Tests Iterable SDK authentication features:
11+
* - SDK initialization with setEmail()
12+
* - User identity persistence across API calls
13+
* - Authentication state management
14+
*/
15+
test.describe('SDK Authentication', () => {
516
let basePage: BasePage;
617

718
test.beforeEach(async ({ page }) => {
819
basePage = new BasePage(page);
920
await basePage.goto();
21+
await basePage.dismissWebpackErrors();
1022
});
1123

12-
test('should handle email input correctly', async () => {
13-
const testEmail = '[email protected]';
14-
15-
await basePage.loginForm.enterEmail(testEmail);
16-
await expect(basePage.loginForm.emailInput).toHaveValue(testEmail);
17-
});
18-
19-
test('should display all navigation links', async () => {
20-
await basePage.navigation.isNavigationVisible();
21-
});
22-
23-
test('should navigate to all sections correctly', async () => {
24-
await basePage.navigation.navigateToCommerce();
25-
await basePage.navigation.navigateToEvents();
24+
test('should authenticate user with SDK setEmail and make API call', async ({
25+
page
26+
}) => {
27+
await basePage.loginForm.loginWithEmail(TEST_EMAIL);
2628
await basePage.navigation.navigateToUsers();
27-
await basePage.navigation.navigateToInApp();
28-
await basePage.navigation.navigateToEmbeddedMsgs();
29-
await basePage.navigation.navigateToEmbedded();
30-
await basePage.navigation.navigateToUUATesting();
31-
await basePage.navigation.navigateToHome();
32-
});
33-
34-
test('should maintain login state across navigation', async () => {
35-
const testEmail = '[email protected]';
36-
37-
await basePage.loginForm.loginWithEmail(testEmail);
38-
await basePage.navigation.navigateToCommerce();
39-
await basePage.navigation.navigateToHome();
40-
41-
const actualEmail = await basePage.loginForm.emailInput.inputValue();
42-
expect(actualEmail).toBeTruthy();
43-
expect(actualEmail.length).toBeGreaterThan(0);
44-
45-
await expect(basePage.loginForm.emailInput).toBeVisible();
46-
await expect(basePage.loginForm.loginButton).toBeVisible();
4729

48-
await basePage.loginForm.emailInput.clear();
49-
await basePage.loginForm.emailInput.fill('[email protected]');
50-
await expect(basePage.loginForm.emailInput).toHaveValue('[email protected]');
30+
// Accept both 200 and 400 responses (400 can occur due to field type mismatches)
31+
const apiCallPromise = page.waitForResponse(
32+
(response) =>
33+
response.url().includes('/api/users/update') &&
34+
(response.status() === 200 || response.status() === 400),
35+
{ timeout: 10000 }
36+
);
37+
38+
const fieldName = `testField_${Date.now()}`;
39+
const updateInput = page.locator('[data-qa-update-user-input]');
40+
await updateInput.fill(fieldName);
41+
42+
const updateButton = page.locator(
43+
'[data-qa-update-user-submit] button[type="submit"]'
44+
);
45+
await updateButton.click();
46+
47+
const response = await apiCallPromise;
48+
const requestBody = JSON.parse(response.request().postData() || '{}');
49+
50+
// SDK auto-injects email into request
51+
expect(requestBody.email).toBe(TEST_EMAIL);
52+
expect(requestBody.dataFields).toHaveProperty(fieldName);
53+
expect(requestBody.dataFields[fieldName]).toBe('test-data');
5154
});
5255
});
Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
/**
2+
* Mock message payloads for in-app message testing
3+
*
4+
* These are raw InAppMessage objects used for tests that need precise control
5+
* over message structure without using the MessageFactory.
6+
*/
7+
8+
import { InAppMessage } from '@iterable/web-sdk';
9+
10+
/**
11+
* Simple messages for position testing
12+
*/
13+
export const PositionTestMessages = {
14+
topRight: (): InAppMessage => ({
15+
messageId: 'topright-test',
16+
campaignId: 70001,
17+
createdAt: Date.now(),
18+
expiresAt: Date.now() + 3600000,
19+
content: {
20+
html: `
21+
<html>
22+
<head><style>body { margin: 0; padding: 20px; background: white; }</style></head>
23+
<body>
24+
<h3>TopRight Message</h3>
25+
<p>This should appear in top-right corner</p>
26+
<button style="position: absolute; top: 8px; right: 8px;">✕</button>
27+
</body>
28+
</html>
29+
`,
30+
payload: {},
31+
inAppDisplaySettings: {
32+
top: { displayOption: 'AutoExpand' },
33+
right: { percentage: 0 },
34+
bottom: { displayOption: 'AutoExpand' },
35+
left: { percentage: 0 },
36+
shouldAnimate: true
37+
},
38+
webInAppDisplaySettings: { position: 'TopRight' }
39+
},
40+
customPayload: {},
41+
trigger: { type: 'immediate' },
42+
saveToInbox: true,
43+
inboxMetadata: { title: 'Test', subtitle: '', icon: '' },
44+
priorityLevel: 350.0,
45+
read: false,
46+
jsonOnly: false,
47+
typeOfContent: 'Dynamic',
48+
messageType: 'Web'
49+
}),
50+
51+
bottomRight: (): InAppMessage => ({
52+
messageId: 'bottomright-test',
53+
campaignId: 70002,
54+
createdAt: Date.now(),
55+
expiresAt: Date.now() + 86400000,
56+
content: {
57+
html: `
58+
<html>
59+
<head><style>body { margin: 0; padding: 20px; background: white; }</style></head>
60+
<body>
61+
<h3>BottomRight Message</h3>
62+
<p>This should appear in bottom-right corner</p>
63+
<button style="position: absolute; top: 8px; right: 8px;">✕</button>
64+
</body>
65+
</html>
66+
`,
67+
payload: {},
68+
inAppDisplaySettings: {
69+
top: { displayOption: 'AutoExpand' },
70+
right: { percentage: 0 },
71+
bottom: { displayOption: 'AutoExpand' },
72+
left: { percentage: 0 },
73+
shouldAnimate: true
74+
},
75+
webInAppDisplaySettings: { position: 'BottomRight' }
76+
},
77+
customPayload: {},
78+
trigger: { type: 'immediate' },
79+
saveToInbox: true,
80+
inboxMetadata: { title: 'Test', subtitle: '', icon: '' },
81+
priorityLevel: 300.0,
82+
read: false,
83+
jsonOnly: false,
84+
typeOfContent: 'Dynamic',
85+
messageType: 'Web'
86+
}),
87+
88+
bottom: (): InAppMessage => ({
89+
messageId: 'bottom-banner',
90+
campaignId: 60008,
91+
createdAt: Date.now(),
92+
expiresAt: Date.now() + 86400000 * 365,
93+
content: {
94+
html: `
95+
<html>
96+
<head><style>body { margin: 0; padding: 15px; background: #f5f5f5; text-align: center; }</style></head>
97+
<body>
98+
<p>Bottom Banner Content</p>
99+
<button style="position: absolute; top: 5px; right: 5px;">✕</button>
100+
</body>
101+
</html>
102+
`,
103+
payload: {},
104+
inAppDisplaySettings: {
105+
top: { displayOption: 'AutoExpand' },
106+
right: { percentage: 0 },
107+
bottom: { displayOption: 'AutoExpand' },
108+
left: { percentage: 0 },
109+
shouldAnimate: false
110+
},
111+
webInAppDisplaySettings: { position: 'Bottom' }
112+
},
113+
customPayload: {},
114+
trigger: { type: 'immediate' },
115+
saveToInbox: false,
116+
inboxMetadata: { title: '', subtitle: '', icon: '' },
117+
priorityLevel: 500.0,
118+
read: false,
119+
jsonOnly: false,
120+
typeOfContent: 'Dynamic',
121+
messageType: 'Web'
122+
})
123+
};
124+
125+
/**
126+
* Messages for URL handling tests
127+
*/
128+
export const URLHandlingMessages = {
129+
iterableDismiss: (): InAppMessage => ({
130+
messageId: 'iterable-dismiss-url',
131+
campaignId: 70003,
132+
createdAt: Date.now(),
133+
expiresAt: Date.now() + 86400000,
134+
content: {
135+
html: `
136+
<html>
137+
<head><style>body { margin: 0; padding: 20px; background: white; }</style></head>
138+
<body>
139+
<h2>Test Dismiss URL</h2>
140+
<a href="iterable://dismiss" class="dismiss-link" data-qa-original-link="iterable://dismiss">Dismiss</a>
141+
<button>✕</button>
142+
</body>
143+
</html>
144+
`,
145+
payload: {},
146+
inAppDisplaySettings: {
147+
top: { displayOption: 'AutoExpand' },
148+
right: { percentage: 0 },
149+
bottom: { displayOption: 'AutoExpand' },
150+
left: { percentage: 0 },
151+
shouldAnimate: true
152+
},
153+
webInAppDisplaySettings: { position: 'Center' }
154+
},
155+
customPayload: {},
156+
trigger: { type: 'immediate' },
157+
saveToInbox: true,
158+
inboxMetadata: { title: 'Test', subtitle: '', icon: '' },
159+
priorityLevel: 300.0,
160+
read: false,
161+
jsonOnly: false,
162+
typeOfContent: 'Dynamic',
163+
messageType: 'Web'
164+
}),
165+
166+
actionURL: (): InAppMessage => ({
167+
messageId: 'action-url',
168+
campaignId: 70004,
169+
createdAt: Date.now(),
170+
expiresAt: Date.now() + 86400000,
171+
content: {
172+
html: `
173+
<html>
174+
<head><style>body { margin: 0; padding: 20px; background: white; }</style></head>
175+
<body>
176+
<h2>Test Action URL</h2>
177+
<a href="action://navigate-home" class="action-link" data-qa-original-link="action://navigate-home">Go Home</a>
178+
<button>✕</button>
179+
</body>
180+
</html>
181+
`,
182+
payload: {},
183+
inAppDisplaySettings: {
184+
top: { displayOption: 'AutoExpand' },
185+
right: { percentage: 0 },
186+
bottom: { displayOption: 'AutoExpand' },
187+
left: { percentage: 0 },
188+
shouldAnimate: true
189+
},
190+
webInAppDisplaySettings: { position: 'Center' }
191+
},
192+
customPayload: { action: 'navigate-home' },
193+
trigger: { type: 'immediate' },
194+
saveToInbox: true,
195+
inboxMetadata: { title: 'Test', subtitle: '', icon: '' },
196+
priorityLevel: 300.0,
197+
read: false,
198+
jsonOnly: false,
199+
typeOfContent: 'Dynamic',
200+
messageType: 'Web'
201+
})
202+
};
203+
204+
/**
205+
* Messages for close button feature tests
206+
*/
207+
export const CloseButtonMessages = {
208+
requiredDismiss: (): InAppMessage => ({
209+
messageId: 'required-dismiss',
210+
campaignId: 80002,
211+
createdAt: Date.now(),
212+
expiresAt: Date.now() + 86400000,
213+
content: {
214+
html: `
215+
<html>
216+
<head><style>body { margin: 0; padding: 30px; background: white; text-align: center; }</style></head>
217+
<body>
218+
<h2>Important Message</h2>
219+
<p>You must click the button to dismiss this message</p>
220+
<button id="close-btn" style="position: absolute; top: 10px; right: 10px; background: #007bff; border: none; color: white; padding: 10px 20px; border-radius: 5px; cursor: pointer;">Got It</button>
221+
</body>
222+
</html>
223+
`,
224+
payload: {},
225+
inAppDisplaySettings: {
226+
top: { displayOption: 'AutoExpand' },
227+
right: { percentage: 0 },
228+
bottom: { displayOption: 'AutoExpand' },
229+
left: { percentage: 0 },
230+
shouldAnimate: true
231+
},
232+
webInAppDisplaySettings: { position: 'Center' }
233+
},
234+
customPayload: { requiresDismiss: true },
235+
trigger: { type: 'immediate' },
236+
saveToInbox: true,
237+
inboxMetadata: { title: 'Important', subtitle: '', icon: '' },
238+
priorityLevel: 100.0,
239+
read: false,
240+
jsonOnly: false,
241+
typeOfContent: 'Dynamic',
242+
messageType: 'Web'
243+
}),
244+
245+
customStyling: (): InAppMessage => ({
246+
messageId: 'custom-close-button',
247+
campaignId: 80003,
248+
createdAt: Date.now(),
249+
expiresAt: Date.now() + 86400000,
250+
content: {
251+
html: `
252+
<html>
253+
<head><style>body { margin: 0; padding: 30px; background: white; }</style></head>
254+
<body>
255+
<h2>Custom Close Button</h2>
256+
<p>Testing custom button styling</p>
257+
<button style="position: absolute; top: 20px; right: 20px; background: #ff0000; border: none; color: white; width: 50px; height: 50px; border-radius: 50%; font-size: 24px; cursor: pointer;">✕</button>
258+
</body>
259+
</html>
260+
`,
261+
payload: {},
262+
inAppDisplaySettings: {
263+
top: { displayOption: 'AutoExpand' },
264+
right: { percentage: 0 },
265+
bottom: { displayOption: 'AutoExpand' },
266+
left: { percentage: 0 },
267+
shouldAnimate: true
268+
},
269+
webInAppDisplaySettings: { position: 'Center' }
270+
},
271+
customPayload: {},
272+
trigger: { type: 'immediate' },
273+
saveToInbox: true,
274+
inboxMetadata: { title: 'Test', subtitle: '', icon: '' },
275+
priorityLevel: 300.0,
276+
read: false,
277+
jsonOnly: false,
278+
typeOfContent: 'Dynamic',
279+
messageType: 'Web'
280+
})
281+
};

0 commit comments

Comments
 (0)