@rimori/playwright-testing 0.3.6 → 0.3.7

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.
@@ -0,0 +1,48 @@
1
+ import { Browser, Page } from '@playwright/test';
2
+ interface RimoriE2ETestEnvironmentOptions {
3
+ browser: Browser;
4
+ pluginId: string;
5
+ }
6
+ interface Exercise {
7
+ title: string;
8
+ description: string;
9
+ pluginId: string;
10
+ actionKey: string;
11
+ parameters?: Record<string, unknown>;
12
+ }
13
+ export interface Onboarding {
14
+ motivation_type?: string;
15
+ preferred_genre?: string;
16
+ target_country?: string;
17
+ target_city?: string;
18
+ }
19
+ interface SetupOptions {
20
+ onboarding?: Onboarding;
21
+ exercises?: Array<Exercise>;
22
+ studyPlan?: {
23
+ complete: boolean;
24
+ };
25
+ }
26
+ export declare class RimoriE2ETestEnvironment {
27
+ private browser;
28
+ private pluginId;
29
+ private persistentUserContext;
30
+ private tempUserContext;
31
+ private testUserEmail;
32
+ private existingUserEmail;
33
+ private authToken;
34
+ constructor(options: RimoriE2ETestEnvironmentOptions);
35
+ setup({ onboarding, exercises, studyPlan }?: SetupOptions): Promise<void>;
36
+ getTempUserPage(): Promise<Page>;
37
+ getPersistUserPage(): Promise<Page>;
38
+ getTempUserEmail(): string;
39
+ getPersistUserEmail(): string;
40
+ private createTestUserViaApi;
41
+ private deleteTestUserViaApi;
42
+ private setupConsoleLogging;
43
+ private setSessionFromMagicLink;
44
+ private completeOnboarding;
45
+ private completeExerciseSetup;
46
+ private completeStudyPlanCreation;
47
+ }
48
+ export {};
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RimoriE2ETestEnvironment = void 0;
4
+ const dotenv_1 = require("dotenv");
5
+ const study_plan_setup_1 = require("../helpers/e2e/study-plan-setup");
6
+ const onboarding_1 = require("../helpers/e2e/onboarding");
7
+ (0, dotenv_1.config)();
8
+ const RIMORI_URL = 'https://dev-app.rimori.se';
9
+ const BACKEND_URL = 'http://localhost:2800';
10
+ class RimoriE2ETestEnvironment {
11
+ constructor(options) {
12
+ this.persistentUserContext = null;
13
+ this.tempUserContext = null;
14
+ this.testUserEmail = null;
15
+ this.existingUserEmail = null;
16
+ this.authToken = null;
17
+ this.browser = options.browser;
18
+ this.pluginId = options.pluginId;
19
+ this.authToken = process.env.RIMORI_TOKEN ?? '';
20
+ if (!this.authToken) {
21
+ throw new Error('RIMORI_TOKEN is not set as an environment variable.');
22
+ }
23
+ }
24
+ async setup({ onboarding, exercises, studyPlan } = {}) {
25
+ const onboardingData = {
26
+ motivation_type: onboarding?.motivation_type ?? 'accomplishment',
27
+ preferred_genre: onboarding?.preferred_genre ?? 'comedy',
28
+ target_country: onboarding?.target_country ?? 'SE',
29
+ target_city: onboarding?.target_city ?? 'Malmö',
30
+ };
31
+ // Step 1: Create both test users (temp + persist) via API
32
+ const { temp, persist } = await this.createTestUserViaApi();
33
+ this.testUserEmail = temp.email;
34
+ this.existingUserEmail = persist.email;
35
+ console.log(`[E2E] Test user (temp): ${temp.email}`);
36
+ console.log(`[E2E] Existing user (persist): ${persist.email}`);
37
+ this.tempUserContext = await this.browser.newContext({ baseURL: RIMORI_URL });
38
+ this.persistentUserContext = await this.browser.newContext({ baseURL: RIMORI_URL });
39
+ await this.setupConsoleLogging(this.tempUserContext, 'temp');
40
+ await this.setupConsoleLogging(this.persistentUserContext, 'persist');
41
+ console.log(`[E2E] Preparing existing user context`);
42
+ // Step 2: Set up existing user browser context with session via magic link
43
+ await this.setSessionFromMagicLink(this.persistentUserContext, persist.magicLink);
44
+ // Step 3: Run onboarding for existing user
45
+ await this.completeOnboarding(this.persistentUserContext, onboardingData);
46
+ console.log(`[E2E] Setting up test user context`);
47
+ // Step 4: Set up test user browser context with session via magic link
48
+ await this.setSessionFromMagicLink(this.tempUserContext, temp.magicLink);
49
+ // Delete test user when test user context is closed
50
+ this.tempUserContext.on('close', async () => {
51
+ await this.deleteTestUserViaApi(temp.email);
52
+ console.log(`[E2E] Deleted test user: ${temp.email}`);
53
+ });
54
+ // Step 5: Run onboarding for test user with e2e plugin flag
55
+ await this.completeOnboarding(this.tempUserContext, onboardingData, this.pluginId);
56
+ // Step 6: Add exercises if specified
57
+ if (exercises && exercises?.length > 0) {
58
+ console.log(`[E2E] Setting up exercises`);
59
+ await this.completeExerciseSetup(this.tempUserContext, exercises);
60
+ }
61
+ // Step 7: Complete study plan creation if specified
62
+ if (studyPlan?.complete) {
63
+ console.log(`[E2E] Setting up study plan`);
64
+ await this.completeStudyPlanCreation(this.tempUserContext);
65
+ }
66
+ console.log(`[E2E] Setup completed`);
67
+ }
68
+ async getTempUserPage() {
69
+ if (!this.tempUserContext) {
70
+ throw new Error('Test user context not initialized. Call setup() first.');
71
+ }
72
+ return this.tempUserContext.newPage();
73
+ }
74
+ async getPersistUserPage() {
75
+ if (!this.persistentUserContext) {
76
+ throw new Error('Existing user context not initialized. Call setup() first.');
77
+ }
78
+ return this.persistentUserContext.newPage();
79
+ }
80
+ getTempUserEmail() {
81
+ if (!this.testUserEmail) {
82
+ throw new Error('Test user not created. Call setup() first.');
83
+ }
84
+ return this.testUserEmail;
85
+ }
86
+ getPersistUserEmail() {
87
+ if (!this.existingUserEmail) {
88
+ throw new Error('Existing user not created. Call setup() first.');
89
+ }
90
+ return this.existingUserEmail;
91
+ }
92
+ async createTestUserViaApi() {
93
+ const response = await fetch(`${BACKEND_URL}/testing/test-user`, {
94
+ method: 'POST',
95
+ headers: {
96
+ 'Content-Type': 'application/json',
97
+ Authorization: `Bearer ${this.authToken}`,
98
+ },
99
+ body: JSON.stringify({
100
+ plugin_id: this.pluginId,
101
+ }),
102
+ });
103
+ if (!response.ok) {
104
+ const errorText = await response.text();
105
+ throw new Error(`Failed to create test user: ${response.status} ${errorText}`);
106
+ }
107
+ return response.json();
108
+ }
109
+ async deleteTestUserViaApi(email) {
110
+ const response = await fetch(`${BACKEND_URL}/testing/test-user`, {
111
+ method: 'DELETE',
112
+ headers: {
113
+ 'Content-Type': 'application/json',
114
+ Authorization: `Bearer ${this.authToken}`,
115
+ },
116
+ body: JSON.stringify({
117
+ plugin_id: this.pluginId,
118
+ email,
119
+ }),
120
+ });
121
+ if (!response.ok) {
122
+ const errorText = await response.text();
123
+ throw new Error(`Failed to delete test user: ${response.status} ${errorText}`);
124
+ }
125
+ }
126
+ async setupConsoleLogging(context, user) {
127
+ console.log(`[E2E] Setting up console logging for ${user}`);
128
+ context.on('console', (msg) => {
129
+ const logLevel = msg.type();
130
+ const logMessage = msg.text();
131
+ if (logLevel === 'debug')
132
+ return;
133
+ if (logMessage.includes('Download the React DevTools'))
134
+ return;
135
+ if (logMessage.includes('languageChanged en'))
136
+ return;
137
+ if (logMessage.includes('i18next: initialized {debug: true'))
138
+ return;
139
+ console.log(`[browser:${logLevel}] [${user}]`, logMessage);
140
+ });
141
+ }
142
+ async setSessionFromMagicLink(context, magicLink) {
143
+ const page = await context.newPage();
144
+ await page.goto(magicLink, { waitUntil: 'networkidle' });
145
+ await page.waitForTimeout(5000);
146
+ const url = page.url();
147
+ if (!url.includes('/dashboard') && !url.includes('/onboarding')) {
148
+ throw new Error(`Failed to set session from magic link: ${url}`);
149
+ }
150
+ await page.close();
151
+ console.log(`[E2E] Authentication completed`);
152
+ }
153
+ async completeOnboarding(context, onboarding, e2ePluginId) {
154
+ console.log(`[E2E] Starting onboarding`);
155
+ const page = await context.newPage();
156
+ await page.goto('/onboarding');
157
+ await page.waitForTimeout(5000);
158
+ const isOnboaded = page.url().includes('/dashboard');
159
+ if (!isOnboaded) {
160
+ console.log(`[E2E] Onboarding user`);
161
+ await (0, onboarding_1.completeOnboarding)(page, onboarding, e2ePluginId);
162
+ console.log(`[E2E] Onboarding completed`);
163
+ }
164
+ else {
165
+ console.log(`[E2E] User already onboarded`);
166
+ }
167
+ await page.close();
168
+ }
169
+ async completeExerciseSetup(context, exercises) {
170
+ const page = await context.newPage();
171
+ for (const exercise of exercises) {
172
+ const encoded = encodeURIComponent(JSON.stringify(exercise));
173
+ await page.goto(`${RIMORI_URL}/dashboard?flag-e2e-exercise=${encoded}`);
174
+ // Wait for the exercise to be created and the flag to be cleared from URL
175
+ await page.waitForURL((url) => !url.searchParams.has('flag-e2e-exercise'), { timeout: 15000 });
176
+ }
177
+ await page.close();
178
+ }
179
+ async completeStudyPlanCreation(context) {
180
+ const page = await context.newPage();
181
+ await (0, study_plan_setup_1.completeStudyPlanGettingStarted)(page);
182
+ await page.close();
183
+ }
184
+ }
185
+ exports.RimoriE2ETestEnvironment = RimoriE2ETestEnvironment;
@@ -0,0 +1,3 @@
1
+ import { Page } from "@playwright/test";
2
+ import { Onboarding } from "../../core/RimoriE2ETestEnvironment";
3
+ export declare function completeOnboarding(page: Page, onboarding: Required<Onboarding>, e2ePluginId?: string): Promise<void>;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.completeOnboarding = completeOnboarding;
4
+ const test_1 = require("@playwright/test");
5
+ async function completeOnboarding(page, onboarding, e2ePluginId) {
6
+ console.log(`[E2E] Onboarding user`);
7
+ console.log(`[E2E] E2E plugin ID: ${e2ePluginId}`);
8
+ console.log(`[E2E] Onboarding: ${JSON.stringify(onboarding)}`);
9
+ const url = e2ePluginId ? `/onboarding?flag-e2e-plugin-id=${e2ePluginId}` : `/onboarding`;
10
+ await page.goto(url, { waitUntil: 'networkidle' });
11
+ page.setDefaultTimeout(60000);
12
+ page.setDefaultNavigationTimeout(60000);
13
+ // Ensure we're on onboarding page
14
+ await (0, test_1.expect)(page).toHaveURL(/\/onboarding/);
15
+ // Step 1: Purpose/Long-term goal
16
+ const goalInput = page.locator('textarea, input[type="text"]');
17
+ await goalInput.waitFor({ state: 'visible' });
18
+ await goalInput.click();
19
+ await goalInput.fill("test goal");
20
+ const continueButton = page.getByRole('button', { name: /continue/i });
21
+ await (0, test_1.expect)(continueButton).toBeEnabled({ timeout: 10000 });
22
+ await continueButton.click();
23
+ // Step 2: Motivation type (auto-advances after selection)
24
+ // Wait for the motivation step heading to appear
25
+ const motivationHeading = page.getByText('What motivates you most?');
26
+ await (0, test_1.expect)(motivationHeading).toBeVisible({ timeout: 10000 });
27
+ const motivationOption = page.locator('label').filter({ hasText: '🏆Progress & Accomplishment' });
28
+ await (0, test_1.expect)(motivationOption).toBeVisible({ timeout: 10000 });
29
+ await motivationOption.click();
30
+ // Step 3: Genre preference (auto-advances after selection)
31
+ // Wait for the genre step heading to appear
32
+ const genreHeading = page.getByText('What kind of stories do you like most?');
33
+ await (0, test_1.expect)(genreHeading).toBeVisible({ timeout: 10000 });
34
+ const genreOption = page.locator('label').filter({ hasText: 'Comedy' });
35
+ await (0, test_1.expect)(genreOption).toBeVisible({ timeout: 10000 });
36
+ await genreOption.click();
37
+ // Step 4: Location
38
+ // Wait for the location step to appear
39
+ const countrySelect = page.getByLabel('Country');
40
+ await (0, test_1.expect)(countrySelect).toBeVisible({ timeout: 10000 });
41
+ await countrySelect.selectOption('SE');
42
+ await page.getByLabel('City (optional)').selectOption('Malmö');
43
+ await page.getByRole('button', { name: 'Continue' }).click();
44
+ // Step 5: Wait for setup completion
45
+ await (0, test_1.expect)(page.getByRole('heading', { name: 'Almost there!' })).toBeVisible({ timeout: 10000 });
46
+ await page.waitForURL('**/dashboard', { timeout: 120000 });
47
+ // await page.screenshot({ path: path.join(process.cwd(), 'playwright/dashboard.png') });
48
+ await (0, test_1.expect)(page.getByRole('heading', { name: "Today's Mission" })).toBeVisible({ timeout: 30000 });
49
+ await (0, test_1.expect)(page.getByRole('button', { name: 'Grammar', exact: true })).toBeVisible({ timeout: 60000 });
50
+ await (0, test_1.expect)(page.getByRole('heading', { name: 'Getting Started: Create your first study plan' })).toBeVisible({
51
+ timeout: 60000,
52
+ });
53
+ await (0, test_1.expect)(page.getByText('Train your first flashcard deck', { exact: true })).toBeVisible({ timeout: 200000 });
54
+ await (0, test_1.expect)(page.locator('iframe').contentFrame().getByRole('button', { name: 'Back to Plugins' })).toBeVisible({
55
+ timeout: 250000,
56
+ });
57
+ }
@@ -0,0 +1,11 @@
1
+ import { Page } from '@playwright/test';
2
+ /**
3
+ * Navigates through the study plan getting-started flow on the dashboard.
4
+ * This clicks through the real UI: milestone planning (Submit Topics) and
5
+ * exercise creation (Save Exercises).
6
+ *
7
+ * Expects the page to already be on the dashboard with a "Getting Started" exercise visible.
8
+ *
9
+ * @param page - Playwright page instance, should be on the dashboard
10
+ */
11
+ export declare function completeStudyPlanGettingStarted(page: Page): Promise<void>;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.completeStudyPlanGettingStarted = completeStudyPlanGettingStarted;
4
+ const test_1 = require("@playwright/test");
5
+ /**
6
+ * Navigates through the study plan getting-started flow on the dashboard.
7
+ * This clicks through the real UI: milestone planning (Submit Topics) and
8
+ * exercise creation (Save Exercises).
9
+ *
10
+ * Expects the page to already be on the dashboard with a "Getting Started" exercise visible.
11
+ *
12
+ * @param page - Playwright page instance, should be on the dashboard
13
+ */
14
+ async function completeStudyPlanGettingStarted(page) {
15
+ page.goto('/dashboard');
16
+ await page.waitForTimeout(2000);
17
+ // Step 1: Find and click the Getting Started exercise card
18
+ const card = page.getByText('Getting Started: Create your first study plan', { exact: false });
19
+ await card.waitFor({ timeout: 10000, state: 'visible' }).catch(() => {
20
+ /* not visible within 10s, continue to early return below */
21
+ });
22
+ if (!(await card.isVisible())) {
23
+ page.close();
24
+ console.warn(`[E2E] Getting Started card not found, skipping study plan setup`);
25
+ return;
26
+ }
27
+ const gettingStartedCard = page.getByText('Start Exercise', { exact: false }).first();
28
+ await (0, test_1.expect)(gettingStartedCard).toBeVisible({ timeout: 30000 });
29
+ await gettingStartedCard.click();
30
+ // Wait for the study plan plugin iframe to load
31
+ const iframe = page.locator('iframe').first();
32
+ await (0, test_1.expect)(iframe).toBeVisible({ timeout: 30000 });
33
+ const frame = iframe.contentFrame();
34
+ // Step 2: Milestone Planning Stage
35
+ // Wait for the 3 milestone cards to appear (AI generates them)
36
+ await (0, test_1.expect)(frame.getByText('Week 1', { exact: false })).toBeVisible({ timeout: 180000 });
37
+ await (0, test_1.expect)(frame.getByText('Week 2', { exact: false })).toBeVisible({ timeout: 10000 });
38
+ await (0, test_1.expect)(frame.getByText('Week 3', { exact: false })).toBeVisible({ timeout: 10000 });
39
+ // Wait for "Submit Topics" button to be enabled and click it
40
+ const submitTopicsButton = frame.getByRole('button', { name: /submit topics/i });
41
+ await (0, test_1.expect)(submitTopicsButton).toBeEnabled({ timeout: 180000 });
42
+ await submitTopicsButton.click();
43
+ // Step 3: Exercise Creation Stage
44
+ // Wait for "Save Exercises" button to appear (AI generates all exercises)
45
+ const saveExercisesButton = frame.getByRole('button', { name: /save exercises/i });
46
+ await (0, test_1.expect)(saveExercisesButton).toBeVisible({ timeout: 300000 });
47
+ await (0, test_1.expect)(saveExercisesButton).toBeEnabled({ timeout: 30000 });
48
+ await saveExercisesButton.click();
49
+ // Wait for save to complete (button should disappear or page navigates)
50
+ await (0, test_1.expect)(saveExercisesButton).toBeHidden({ timeout: 30000 });
51
+ // Step 4: Verify completion - should be back on dashboard
52
+ // The "Getting Started" card should be gone and exercises should appear
53
+ await (0, test_1.expect)(page.getByText("Today's Mission", { exact: false })).toBeVisible({ timeout: 30000 });
54
+ }
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './core/RimoriTestEnvironment';
2
+ export * from './core/RimoriE2ETestEnvironment';
package/dist/index.js CHANGED
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./core/RimoriTestEnvironment"), exports);
18
+ __exportStar(require("./core/RimoriE2ETestEnvironment"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimori/playwright-testing",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "Playwright testing utilities for Rimori plugins and workers",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -21,13 +21,16 @@
21
21
  "test:ui": "playwright test --ui",
22
22
  "test:headed:debug": "playwright test --headed --debug"
23
23
  },
24
+ "dependencies": {
25
+ "dotenv": "^16.4.5"
26
+ },
24
27
  "peerDependencies": {
25
28
  "@playwright/test": "^1.40.0",
26
- "@rimori/client": "^2.5.12"
29
+ "@rimori/client": "^2.5.13"
27
30
  },
28
31
  "devDependencies": {
29
32
  "@playwright/test": "^1.40.0",
30
- "@rimori/client": "^2.5.12",
33
+ "@rimori/client": "^2.5.13",
31
34
  "@types/node": "^20.12.7",
32
35
  "rimraf": "^5.0.7",
33
36
  "typescript": "^5.7.2"