@iblai/iblai-js 1.5.3 → 1.6.0

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,88 @@
1
+ import { Locator, Page } from '@playwright/test';
2
+ import type { CreditBalancePlan } from './credit-balance-helpers';
3
+ export type BillingAutoRechargeStatus = 'Enabled' | 'Disabled';
4
+ /** Locator for the Plan section card on the BillingTab. */
5
+ export declare function billingPlanSection(page: Page): Locator;
6
+ /** Locator for the Credits section card on the BillingTab. */
7
+ export declare function billingCreditsSection(page: Page): Locator;
8
+ /** Locator for the Auto Recharge section card on the BillingTab.
9
+ * This section is only rendered for non-Free plans with a payment method on file.
10
+ */
11
+ export declare function billingAutoRechargeSection(page: Page): Locator;
12
+ /** Reads the plan label (Free / Trial / Premium) from the Plan section. */
13
+ export declare function getBillingPlanLabel(page: Page): Promise<CreditBalancePlan | null>;
14
+ /** Reads the auto-recharge status badge (Enabled / Disabled) when the section is rendered. */
15
+ export declare function getBillingAutoRechargeStatus(page: Page): Promise<BillingAutoRechargeStatus | null>;
16
+ /** Waits for the BillingTab loading skeletons to clear by waiting for the Plan
17
+ * section card to mount. */
18
+ export declare function waitForBillingTabReady(page: Page): Promise<void>;
19
+ /**
20
+ * Asserts the Plan section state for a given plan. Verifies:
21
+ * - The plan label text matches `options.plan`
22
+ * - The "Current" pill is visible
23
+ * - The Upgrade button is visible iff the plan is not Premium
24
+ */
25
+ export declare function expectBillingPlanSection(page: Page, options: {
26
+ plan: CreditBalancePlan;
27
+ }): Promise<void>;
28
+ /**
29
+ * Asserts the Credits section state. Always verifies the "Available" stat row.
30
+ * The action button rule mirrors the component:
31
+ * - Free plan → no Add Credits / Manage Billing button
32
+ * - Non-Free + hasPaymentMethod=true → "Add Credits" visible, "Manage Billing" absent
33
+ * - Non-Free + hasPaymentMethod=false → "Manage Billing" visible, "Add Credits" absent
34
+ * - Non-Free with hasPaymentMethod omitted → only the "Available" row is asserted
35
+ */
36
+ export declare function expectBillingCreditsSection(page: Page, options: {
37
+ plan: CreditBalancePlan;
38
+ hasPaymentMethod?: boolean;
39
+ }): Promise<void>;
40
+ /**
41
+ * Asserts the Auto Recharge section visibility. Section is rendered only when
42
+ * `hasPaymentMethod && !isFreePlan` in the component. Pass `expectVisible: false`
43
+ * to assert the section is absent. When visible and `status` is provided, also
44
+ * asserts the Enabled/Disabled badge text.
45
+ */
46
+ export declare function expectBillingAutoRechargeSection(page: Page, options: {
47
+ expectVisible: boolean;
48
+ status?: BillingAutoRechargeStatus;
49
+ }): Promise<void>;
50
+ /**
51
+ * Free plan: Plan="Free" with Upgrade visible; Credits section has no action;
52
+ * Auto Recharge section is hidden entirely (regardless of has_payment_method).
53
+ */
54
+ export declare function expectBillingTabForFreePlan(page: Page): Promise<void>;
55
+ /**
56
+ * Trial plan: Plan="Trial" with Upgrade visible; Credits action depends on
57
+ * `hasPaymentMethod` (Add Credits when true, Manage Billing when false);
58
+ * Auto Recharge section is rendered iff `hasPaymentMethod` is true.
59
+ */
60
+ export declare function expectBillingTabForTrialPlan(page: Page, options: {
61
+ hasPaymentMethod: boolean;
62
+ }): Promise<void>;
63
+ /**
64
+ * Premium plan: Plan="Premium" with Upgrade hidden; Credits action depends on
65
+ * `hasPaymentMethod` (Add Credits when true, Manage Billing when false);
66
+ * Auto Recharge section is rendered iff `hasPaymentMethod` is true.
67
+ */
68
+ export declare function expectBillingTabForPremiumPlan(page: Page, options: {
69
+ hasPaymentMethod: boolean;
70
+ }): Promise<void>;
71
+ /**
72
+ * Convenience: detects the active plan from the Plan section badge and runs
73
+ * the matching state assertions. Returns the detected plan.
74
+ *
75
+ * For non-Free plans, pass `hasPaymentMethod` to assert the Credits/Auto Recharge
76
+ * sub-states; if omitted, only the Plan section + base Credits row is verified.
77
+ */
78
+ export declare function expectBillingTabForCurrentPlan(page: Page, options?: {
79
+ hasPaymentMethod?: boolean;
80
+ }): Promise<CreditBalancePlan>;
81
+ /** Clicks the Upgrade button in the Plan section (visible only on non-Premium plans). */
82
+ export declare function clickBillingUpgrade(page: Page): Promise<void>;
83
+ /** Clicks the Add Credits button in the Credits section (non-Free + has payment method). */
84
+ export declare function clickBillingAddCredits(page: Page): Promise<void>;
85
+ /** Clicks the Manage Billing button in the Credits section (non-Free + no payment method). */
86
+ export declare function clickBillingManageBilling(page: Page): Promise<void>;
87
+ /** Clicks the Manage Usage button in the Auto Recharge section. */
88
+ export declare function clickBillingManageUsage(page: Page): Promise<void>;
@@ -0,0 +1,73 @@
1
+ import { Locator, Page } from '@playwright/test';
2
+ export type CreditBalancePlan = 'Free' | 'Trial' | 'Premium';
3
+ /**
4
+ * Reads `current_tenant` from localStorage and returns its `show_paywall` flag.
5
+ * Returns false if the entry is missing, malformed, or the flag is unset.
6
+ */
7
+ export declare function getCurrentTenantShowPaywall(page: Page): Promise<boolean>;
8
+ /** Locator for the credit-balance trigger button (icon in the nav). */
9
+ export declare function creditBalanceTrigger(page: Page): Locator;
10
+ /** Locator for the credit-balance dropdown panel (rendered in a Radix portal). */
11
+ export declare function creditBalancePanel(page: Page): Locator;
12
+ /** Locator for the plan badge (Free / Trial / Premium) inside the open panel. */
13
+ export declare function creditBalancePlanBadge(page: Page): Locator;
14
+ /**
15
+ * Asserts the credit-balance trigger is visible iff the current tenant has
16
+ * `show_paywall=true`. Returns the resolved expectation so callers can branch.
17
+ */
18
+ export declare function expectCreditBalanceVisibilityForTenant(page: Page): Promise<{
19
+ shouldBeVisible: boolean;
20
+ }>;
21
+ /**
22
+ * Opens the credit-balance dropdown if not already open, waits for the panel
23
+ * to be visible, and waits for the initial "Loading credits..." placeholder to
24
+ * clear so callers can immediately read content. Idempotent — safe to call
25
+ * when the panel is already up.
26
+ */
27
+ export declare function openCreditBalanceDropdown(page: Page): Promise<Locator>;
28
+ /**
29
+ * Waits for the "Loading credits..." placeholder to disappear from the open
30
+ * panel. Resolves in the success path (real content rendered) or the error
31
+ * path ("Unable to load credit balance." rendered) — both replace the loading
32
+ * row. Returns immediately if the placeholder was never present.
33
+ */
34
+ export declare function waitForCreditBalanceLoaded(page: Page): Promise<void>;
35
+ /** Closes the credit-balance dropdown via Escape and waits for it to detach. */
36
+ export declare function closeCreditBalanceDropdown(page: Page): Promise<void>;
37
+ /**
38
+ * Reads the plan label text from the open panel. Returns null if the badge is
39
+ * not rendered (e.g. billing data still loading or errored).
40
+ */
41
+ export declare function getCreditBalancePlanLabel(page: Page): Promise<CreditBalancePlan | null>;
42
+ /**
43
+ * Reads the "Remaining" credits value from the open panel ("X,XXX Credits").
44
+ * Returns null when the row is not rendered or unparseable.
45
+ */
46
+ export declare function getCreditBalanceRemaining(page: Page): Promise<number | null>;
47
+ /**
48
+ * Free plan UI: Upgrade Plan only. No payment buttons. No auto-recharge section.
49
+ */
50
+ export declare function expectCreditBalancePanelForFreePlan(page: Page): Promise<void>;
51
+ /**
52
+ * Trial plan UI: Upgrade Plan only. No Manage Usage / Add Credits / Manage Billing.
53
+ */
54
+ export declare function expectCreditBalancePanelForTrialPlan(page: Page): Promise<void>;
55
+ /**
56
+ * Premium plan UI: Upgrade Plan must NOT appear.
57
+ * - With payment method: Manage Usage + Add Credits both visible; Manage Billing hidden.
58
+ * - Without payment method: Manage Billing visible; Manage Usage + Add Credits hidden.
59
+ */
60
+ export declare function expectCreditBalancePanelForPremiumPlan(page: Page, options: {
61
+ hasPaymentMethod: boolean;
62
+ }): Promise<void>;
63
+ /**
64
+ * Convenience: opens the dropdown, detects the active plan from the badge,
65
+ * and runs the matching state assertions on the already-open panel. Returns
66
+ * the detected plan label.
67
+ *
68
+ * For Premium plans you may pass `hasPaymentMethod` to assert the specific
69
+ * sub-state; if omitted on Premium, only the "no Upgrade Plan button" check runs.
70
+ */
71
+ export declare function expectCreditBalanceForCurrentPlan(page: Page, options?: {
72
+ hasPaymentMethod?: boolean;
73
+ }): Promise<CreditBalancePlan>;
@@ -17,5 +17,9 @@ export { buildReportUrl, parseReportUrlParams, navigateToReportDownload, verifyP
17
17
  export type { ReportDownloadOptions } from './report-download';
18
18
  export { isMemoryTabVisible, switchToMemoryTab, verifyMemoryTabSettings, verifyMemoryTabMemoriesList, openAddMemoryDialog, toggleMemorySwitch, addMemory, deleteFirstMemory, deleteMemoryByContent, archiveFirstMemory, archiveMemoryByContent, getMemoryCount, verifyMemoryExists, verifyMemoryNotExists, } from './memory-test-helpers';
19
19
  export { navigateToAuditLog, verifyAuditLogTableVisible, getAuditLogRowCount, verifyAuditLogEntryStructure, verifyAuditLogEmptyState, verifyAuditLogPermissionError, verifyAuditLogGenericError, verifyAuditLogLoading, waitForAuditLogDataLoaded, filterByAction, filterByActor, getAvailableActors, filterByDateRange, clearDateRangeFilter, getPaginationInfo, goToNextPage, goToPreviousPage, goToFirstPage, goToLastPage, goToPage, verifyCurrentPage, isOnLastPage, isOnFirstPage, navigateToAuditLogAndWaitForData, filterByActionAndVerify, filterByActorAndVerify, } from './audit-log-helpers';
20
+ export { getCurrentTenantShowPaywall, creditBalanceTrigger, creditBalancePanel, creditBalancePlanBadge, expectCreditBalanceVisibilityForTenant, openCreditBalanceDropdown, waitForCreditBalanceLoaded, closeCreditBalanceDropdown, getCreditBalancePlanLabel, getCreditBalanceRemaining, expectCreditBalancePanelForFreePlan, expectCreditBalancePanelForTrialPlan, expectCreditBalancePanelForPremiumPlan, expectCreditBalanceForCurrentPlan, } from './credit-balance-helpers';
21
+ export type { CreditBalancePlan } from './credit-balance-helpers';
22
+ export { billingPlanSection, billingCreditsSection, billingAutoRechargeSection, getBillingPlanLabel, getBillingAutoRechargeStatus, waitForBillingTabReady, expectBillingPlanSection, expectBillingCreditsSection, expectBillingAutoRechargeSection, expectBillingTabForFreePlan, expectBillingTabForTrialPlan, expectBillingTabForPremiumPlan, expectBillingTabForCurrentPlan, clickBillingUpgrade, clickBillingAddCredits, clickBillingManageBilling, clickBillingManageUsage, } from './billing-tab-helpers';
23
+ export type { BillingAutoRechargeStatus } from './billing-tab-helpers';
20
24
  export { createPlaywrightConfig, generateProjectConfig, generateBrowserSetupProjects, getBrowserKey, } from './playwright-config';
21
25
  export type { PlatformConfig, CreatePlaywrightConfigOptions } from './playwright-config';
@@ -2078,6 +2078,413 @@ async function filterByActorAndVerify(page, actorName) {
2078
2078
  return count;
2079
2079
  }
2080
2080
 
2081
+ const DEFAULT_TIMEOUT$1 = 10000;
2082
+ /**
2083
+ * Reads `current_tenant` from localStorage and returns its `show_paywall` flag.
2084
+ * Returns false if the entry is missing, malformed, or the flag is unset.
2085
+ */
2086
+ async function getCurrentTenantShowPaywall(page) {
2087
+ return page.evaluate(() => {
2088
+ try {
2089
+ const raw = window.localStorage.getItem('current_tenant');
2090
+ if (!raw)
2091
+ return false;
2092
+ const parsed = JSON.parse(raw);
2093
+ return Boolean(parsed === null || parsed === void 0 ? void 0 : parsed.show_paywall);
2094
+ }
2095
+ catch (_a) {
2096
+ return false;
2097
+ }
2098
+ });
2099
+ }
2100
+ /** Locator for the credit-balance trigger button (icon in the nav). */
2101
+ function creditBalanceTrigger(page) {
2102
+ return page.getByTestId('credit-balance-trigger');
2103
+ }
2104
+ /** Locator for the credit-balance dropdown panel (rendered in a Radix portal). */
2105
+ function creditBalancePanel(page) {
2106
+ return page.getByTestId('credit-balance-panel');
2107
+ }
2108
+ /** Locator for the plan badge (Free / Trial / Premium) inside the open panel. */
2109
+ function creditBalancePlanBadge(page) {
2110
+ return creditBalancePanel(page).getByTestId('credit-balance-plan-badge');
2111
+ }
2112
+ /**
2113
+ * Asserts the credit-balance trigger is visible iff the current tenant has
2114
+ * `show_paywall=true`. Returns the resolved expectation so callers can branch.
2115
+ */
2116
+ async function expectCreditBalanceVisibilityForTenant(page) {
2117
+ const showPaywall = await getCurrentTenantShowPaywall(page);
2118
+ const trigger = creditBalanceTrigger(page);
2119
+ if (showPaywall) {
2120
+ await test$1.expect(trigger).toBeVisible({ timeout: DEFAULT_TIMEOUT$1 });
2121
+ logger.info('Credit balance trigger is visible (current_tenant.show_paywall=true)');
2122
+ }
2123
+ else {
2124
+ await test$1.expect(trigger).toHaveCount(0);
2125
+ logger.info('Credit balance trigger is hidden (current_tenant.show_paywall is falsy or missing)');
2126
+ }
2127
+ return { shouldBeVisible: showPaywall };
2128
+ }
2129
+ /**
2130
+ * Opens the credit-balance dropdown if not already open, waits for the panel
2131
+ * to be visible, and waits for the initial "Loading credits..." placeholder to
2132
+ * clear so callers can immediately read content. Idempotent — safe to call
2133
+ * when the panel is already up.
2134
+ */
2135
+ async function openCreditBalanceDropdown(page) {
2136
+ const panel = creditBalancePanel(page);
2137
+ if (!(await panel.isVisible().catch(() => false))) {
2138
+ const trigger = creditBalanceTrigger(page);
2139
+ await test$1.expect(trigger).toBeVisible({ timeout: DEFAULT_TIMEOUT$1 });
2140
+ await trigger.click();
2141
+ }
2142
+ await test$1.expect(panel).toBeVisible({ timeout: DEFAULT_TIMEOUT$1 });
2143
+ await waitForCreditBalanceLoaded(page);
2144
+ return panel;
2145
+ }
2146
+ /**
2147
+ * Waits for the "Loading credits..." placeholder to disappear from the open
2148
+ * panel. Resolves in the success path (real content rendered) or the error
2149
+ * path ("Unable to load credit balance." rendered) — both replace the loading
2150
+ * row. Returns immediately if the placeholder was never present.
2151
+ */
2152
+ async function waitForCreditBalanceLoaded(page) {
2153
+ const loading = creditBalancePanel(page).getByText(/^Loading credits/i);
2154
+ await test$1.expect(loading).toHaveCount(0, { timeout: DEFAULT_TIMEOUT$1 });
2155
+ }
2156
+ /** Closes the credit-balance dropdown via Escape and waits for it to detach. */
2157
+ async function closeCreditBalanceDropdown(page) {
2158
+ await page.keyboard.press('Escape');
2159
+ await test$1.expect(creditBalancePanel(page)).toHaveCount(0);
2160
+ }
2161
+ /**
2162
+ * Reads the plan label text from the open panel. Returns null if the badge is
2163
+ * not rendered (e.g. billing data still loading or errored).
2164
+ */
2165
+ async function getCreditBalancePlanLabel(page) {
2166
+ const badge = creditBalancePlanBadge(page);
2167
+ if ((await badge.count()) === 0)
2168
+ return null;
2169
+ const text = (await badge.innerText()).trim();
2170
+ if (text === 'Free' || text === 'Trial' || text === 'Premium')
2171
+ return text;
2172
+ return null;
2173
+ }
2174
+ /**
2175
+ * Reads the "Remaining" credits value from the open panel ("X,XXX Credits").
2176
+ * Returns null when the row is not rendered or unparseable.
2177
+ */
2178
+ async function getCreditBalanceRemaining(page) {
2179
+ const panel = creditBalancePanel(page);
2180
+ const row = panel.locator('div', { has: page.getByText(/^Remaining$/) }).first();
2181
+ if ((await row.count()) === 0)
2182
+ return null;
2183
+ const text = await row.innerText().catch(() => '');
2184
+ const match = text.match(/([0-9][0-9,]*)\s*Credits/i);
2185
+ if (!match)
2186
+ return null;
2187
+ return parseInt(match[1].replace(/,/g, ''), 10);
2188
+ }
2189
+ function panelButtons(panel, page) {
2190
+ return {
2191
+ upgradePlan: panel.getByRole('button', { name: /^Upgrade Plan$/ }),
2192
+ manageUsage: panel.getByRole('button', { name: /^Manage Usage$/ }),
2193
+ addCredits: panel.getByRole('button', { name: /^Add Credits$/ }),
2194
+ manageBilling: panel.getByRole('button', { name: /^Manage Billing$/ }),
2195
+ autoRechargeHeading: panel.getByText(/^Auto Recharge$/),
2196
+ };
2197
+ }
2198
+ /**
2199
+ * Free plan UI: Upgrade Plan only. No payment buttons. No auto-recharge section.
2200
+ */
2201
+ async function expectCreditBalancePanelForFreePlan(page) {
2202
+ const panel = await openCreditBalanceDropdown(page);
2203
+ await test$1.expect(creditBalancePlanBadge(page)).toHaveText('Free');
2204
+ const btn = panelButtons(panel);
2205
+ await test$1.expect(btn.autoRechargeHeading).toHaveCount(0);
2206
+ await test$1.expect(btn.upgradePlan).toBeVisible();
2207
+ await test$1.expect(btn.manageUsage).toHaveCount(0);
2208
+ await test$1.expect(btn.addCredits).toHaveCount(0);
2209
+ await test$1.expect(btn.manageBilling).toHaveCount(0);
2210
+ logger.info('Verified credit balance panel for Free plan');
2211
+ }
2212
+ /**
2213
+ * Trial plan UI: Upgrade Plan only. No Manage Usage / Add Credits / Manage Billing.
2214
+ */
2215
+ async function expectCreditBalancePanelForTrialPlan(page) {
2216
+ const panel = await openCreditBalanceDropdown(page);
2217
+ await test$1.expect(creditBalancePlanBadge(page)).toHaveText('Trial');
2218
+ const btn = panelButtons(panel);
2219
+ await test$1.expect(btn.upgradePlan).toBeVisible();
2220
+ await test$1.expect(btn.manageUsage).toHaveCount(0);
2221
+ await test$1.expect(btn.addCredits).toHaveCount(0);
2222
+ await test$1.expect(btn.manageBilling).toHaveCount(0);
2223
+ logger.info('Verified credit balance panel for Trial plan');
2224
+ }
2225
+ /**
2226
+ * Premium plan UI: Upgrade Plan must NOT appear.
2227
+ * - With payment method: Manage Usage + Add Credits both visible; Manage Billing hidden.
2228
+ * - Without payment method: Manage Billing visible; Manage Usage + Add Credits hidden.
2229
+ */
2230
+ async function expectCreditBalancePanelForPremiumPlan(page, options) {
2231
+ const panel = await openCreditBalanceDropdown(page);
2232
+ await test$1.expect(creditBalancePlanBadge(page)).toHaveText('Premium');
2233
+ const btn = panelButtons(panel);
2234
+ await test$1.expect(btn.upgradePlan).toHaveCount(0);
2235
+ if (options.hasPaymentMethod) {
2236
+ await test$1.expect(btn.manageUsage).toBeVisible();
2237
+ await test$1.expect(btn.addCredits).toBeVisible();
2238
+ await test$1.expect(btn.manageBilling).toHaveCount(0);
2239
+ }
2240
+ else {
2241
+ await test$1.expect(btn.manageBilling).toBeVisible();
2242
+ await test$1.expect(btn.manageUsage).toHaveCount(0);
2243
+ await test$1.expect(btn.addCredits).toHaveCount(0);
2244
+ }
2245
+ logger.info(`Verified credit balance panel for Premium plan (hasPaymentMethod=${options.hasPaymentMethod})`);
2246
+ }
2247
+ /**
2248
+ * Convenience: opens the dropdown, detects the active plan from the badge,
2249
+ * and runs the matching state assertions on the already-open panel. Returns
2250
+ * the detected plan label.
2251
+ *
2252
+ * For Premium plans you may pass `hasPaymentMethod` to assert the specific
2253
+ * sub-state; if omitted on Premium, only the "no Upgrade Plan button" check runs.
2254
+ */
2255
+ async function expectCreditBalanceForCurrentPlan(page, options) {
2256
+ const panel = await openCreditBalanceDropdown(page);
2257
+ const plan = await getCreditBalancePlanLabel(page);
2258
+ if (!plan) {
2259
+ throw new Error('Credit balance plan badge was not found in the dropdown panel');
2260
+ }
2261
+ const btn = panelButtons(panel);
2262
+ if (plan === 'Free') {
2263
+ await test$1.expect(btn.autoRechargeHeading).toHaveCount(0);
2264
+ await test$1.expect(btn.upgradePlan).toBeVisible();
2265
+ await test$1.expect(btn.manageUsage).toHaveCount(0);
2266
+ await test$1.expect(btn.addCredits).toHaveCount(0);
2267
+ await test$1.expect(btn.manageBilling).toHaveCount(0);
2268
+ }
2269
+ else if (plan === 'Trial') {
2270
+ await test$1.expect(btn.upgradePlan).toBeVisible();
2271
+ await test$1.expect(btn.manageUsage).toHaveCount(0);
2272
+ await test$1.expect(btn.addCredits).toHaveCount(0);
2273
+ await test$1.expect(btn.manageBilling).toHaveCount(0);
2274
+ }
2275
+ else {
2276
+ // Premium
2277
+ await test$1.expect(btn.upgradePlan).toHaveCount(0);
2278
+ if ((options === null || options === void 0 ? void 0 : options.hasPaymentMethod) === true) {
2279
+ await test$1.expect(btn.manageUsage).toBeVisible();
2280
+ await test$1.expect(btn.addCredits).toBeVisible();
2281
+ await test$1.expect(btn.manageBilling).toHaveCount(0);
2282
+ }
2283
+ else if ((options === null || options === void 0 ? void 0 : options.hasPaymentMethod) === false) {
2284
+ await test$1.expect(btn.manageBilling).toBeVisible();
2285
+ await test$1.expect(btn.manageUsage).toHaveCount(0);
2286
+ await test$1.expect(btn.addCredits).toHaveCount(0);
2287
+ }
2288
+ }
2289
+ logger.info(`Verified credit balance UI for plan="${plan}"`);
2290
+ return plan;
2291
+ }
2292
+
2293
+ const DEFAULT_TIMEOUT = 10000;
2294
+ /** Locator for the Plan section card on the BillingTab. */
2295
+ function billingPlanSection(page) {
2296
+ return page.getByTestId('billing-plan-section');
2297
+ }
2298
+ /** Locator for the Credits section card on the BillingTab. */
2299
+ function billingCreditsSection(page) {
2300
+ return page.getByTestId('billing-credits-section');
2301
+ }
2302
+ /** Locator for the Auto Recharge section card on the BillingTab.
2303
+ * This section is only rendered for non-Free plans with a payment method on file.
2304
+ */
2305
+ function billingAutoRechargeSection(page) {
2306
+ return page.getByTestId('billing-auto-recharge-section');
2307
+ }
2308
+ /** Reads the plan label (Free / Trial / Premium) from the Plan section. */
2309
+ async function getBillingPlanLabel(page) {
2310
+ const label = billingPlanSection(page).getByTestId('billing-plan-label');
2311
+ if ((await label.count()) === 0)
2312
+ return null;
2313
+ const text = (await label.innerText()).trim();
2314
+ if (text === 'Free' || text === 'Trial' || text === 'Premium')
2315
+ return text;
2316
+ return null;
2317
+ }
2318
+ /** Reads the auto-recharge status badge (Enabled / Disabled) when the section is rendered. */
2319
+ async function getBillingAutoRechargeStatus(page) {
2320
+ const badge = billingAutoRechargeSection(page).getByTestId('billing-auto-recharge-status');
2321
+ if ((await badge.count()) === 0)
2322
+ return null;
2323
+ const text = (await badge.innerText()).trim();
2324
+ if (text === 'Enabled' || text === 'Disabled')
2325
+ return text;
2326
+ return null;
2327
+ }
2328
+ /** Waits for the BillingTab loading skeletons to clear by waiting for the Plan
2329
+ * section card to mount. */
2330
+ async function waitForBillingTabReady(page) {
2331
+ await test$1.expect(billingPlanSection(page)).toBeVisible({ timeout: 15000 });
2332
+ }
2333
+ /**
2334
+ * Asserts the Plan section state for a given plan. Verifies:
2335
+ * - The plan label text matches `options.plan`
2336
+ * - The "Current" pill is visible
2337
+ * - The Upgrade button is visible iff the plan is not Premium
2338
+ */
2339
+ async function expectBillingPlanSection(page, options) {
2340
+ const section = billingPlanSection(page);
2341
+ await test$1.expect(section).toBeVisible({ timeout: DEFAULT_TIMEOUT });
2342
+ await test$1.expect(section.getByTestId('billing-plan-label')).toHaveText(options.plan);
2343
+ await test$1.expect(section.getByText(/^Current$/)).toBeVisible();
2344
+ const upgradeBtn = section.getByRole('button', { name: /^Upgrade$/ });
2345
+ if (options.plan === 'Premium') {
2346
+ await test$1.expect(upgradeBtn).toHaveCount(0);
2347
+ }
2348
+ else {
2349
+ await test$1.expect(upgradeBtn).toBeVisible();
2350
+ }
2351
+ }
2352
+ /**
2353
+ * Asserts the Credits section state. Always verifies the "Available" stat row.
2354
+ * The action button rule mirrors the component:
2355
+ * - Free plan → no Add Credits / Manage Billing button
2356
+ * - Non-Free + hasPaymentMethod=true → "Add Credits" visible, "Manage Billing" absent
2357
+ * - Non-Free + hasPaymentMethod=false → "Manage Billing" visible, "Add Credits" absent
2358
+ * - Non-Free with hasPaymentMethod omitted → only the "Available" row is asserted
2359
+ */
2360
+ async function expectBillingCreditsSection(page, options) {
2361
+ const section = billingCreditsSection(page);
2362
+ await test$1.expect(section).toBeVisible({ timeout: DEFAULT_TIMEOUT });
2363
+ await test$1.expect(section.getByText(/^Available$/)).toBeVisible();
2364
+ const addCreditsBtn = section.getByRole('button', { name: /^Add Credits$/ });
2365
+ const manageBillingBtn = section.getByRole('button', { name: /^Manage Billing$/ });
2366
+ if (options.plan === 'Free') {
2367
+ await test$1.expect(addCreditsBtn).toHaveCount(0);
2368
+ await test$1.expect(manageBillingBtn).toHaveCount(0);
2369
+ }
2370
+ else if (options.hasPaymentMethod === true) {
2371
+ await test$1.expect(addCreditsBtn).toBeVisible();
2372
+ await test$1.expect(manageBillingBtn).toHaveCount(0);
2373
+ }
2374
+ else if (options.hasPaymentMethod === false) {
2375
+ await test$1.expect(manageBillingBtn).toBeVisible();
2376
+ await test$1.expect(addCreditsBtn).toHaveCount(0);
2377
+ }
2378
+ }
2379
+ /**
2380
+ * Asserts the Auto Recharge section visibility. Section is rendered only when
2381
+ * `hasPaymentMethod && !isFreePlan` in the component. Pass `expectVisible: false`
2382
+ * to assert the section is absent. When visible and `status` is provided, also
2383
+ * asserts the Enabled/Disabled badge text.
2384
+ */
2385
+ async function expectBillingAutoRechargeSection(page, options) {
2386
+ const section = billingAutoRechargeSection(page);
2387
+ if (!options.expectVisible) {
2388
+ await test$1.expect(section).toHaveCount(0);
2389
+ return;
2390
+ }
2391
+ await test$1.expect(section).toBeVisible({ timeout: DEFAULT_TIMEOUT });
2392
+ await test$1.expect(section.getByRole('button', { name: /^Manage Usage$/ })).toBeVisible();
2393
+ if (options.status) {
2394
+ await test$1.expect(section.getByTestId('billing-auto-recharge-status')).toHaveText(options.status);
2395
+ }
2396
+ }
2397
+ /**
2398
+ * Free plan: Plan="Free" with Upgrade visible; Credits section has no action;
2399
+ * Auto Recharge section is hidden entirely (regardless of has_payment_method).
2400
+ */
2401
+ async function expectBillingTabForFreePlan(page) {
2402
+ await expectBillingPlanSection(page, { plan: 'Free' });
2403
+ await expectBillingCreditsSection(page, { plan: 'Free' });
2404
+ await expectBillingAutoRechargeSection(page, { expectVisible: false });
2405
+ logger.info('Verified billing tab for Free plan');
2406
+ }
2407
+ /**
2408
+ * Trial plan: Plan="Trial" with Upgrade visible; Credits action depends on
2409
+ * `hasPaymentMethod` (Add Credits when true, Manage Billing when false);
2410
+ * Auto Recharge section is rendered iff `hasPaymentMethod` is true.
2411
+ */
2412
+ async function expectBillingTabForTrialPlan(page, options) {
2413
+ await expectBillingPlanSection(page, { plan: 'Trial' });
2414
+ await expectBillingCreditsSection(page, {
2415
+ plan: 'Trial',
2416
+ hasPaymentMethod: options.hasPaymentMethod,
2417
+ });
2418
+ await expectBillingAutoRechargeSection(page, { expectVisible: options.hasPaymentMethod });
2419
+ logger.info(`Verified billing tab for Trial plan (hasPaymentMethod=${options.hasPaymentMethod})`);
2420
+ }
2421
+ /**
2422
+ * Premium plan: Plan="Premium" with Upgrade hidden; Credits action depends on
2423
+ * `hasPaymentMethod` (Add Credits when true, Manage Billing when false);
2424
+ * Auto Recharge section is rendered iff `hasPaymentMethod` is true.
2425
+ */
2426
+ async function expectBillingTabForPremiumPlan(page, options) {
2427
+ await expectBillingPlanSection(page, { plan: 'Premium' });
2428
+ await expectBillingCreditsSection(page, {
2429
+ plan: 'Premium',
2430
+ hasPaymentMethod: options.hasPaymentMethod,
2431
+ });
2432
+ await expectBillingAutoRechargeSection(page, { expectVisible: options.hasPaymentMethod });
2433
+ logger.info(`Verified billing tab for Premium plan (hasPaymentMethod=${options.hasPaymentMethod})`);
2434
+ }
2435
+ /**
2436
+ * Convenience: detects the active plan from the Plan section badge and runs
2437
+ * the matching state assertions. Returns the detected plan.
2438
+ *
2439
+ * For non-Free plans, pass `hasPaymentMethod` to assert the Credits/Auto Recharge
2440
+ * sub-states; if omitted, only the Plan section + base Credits row is verified.
2441
+ */
2442
+ async function expectBillingTabForCurrentPlan(page, options) {
2443
+ await waitForBillingTabReady(page);
2444
+ const plan = await getBillingPlanLabel(page);
2445
+ if (!plan) {
2446
+ throw new Error('Could not detect plan label in BillingTab Plan section');
2447
+ }
2448
+ if (plan === 'Free') {
2449
+ await expectBillingTabForFreePlan(page);
2450
+ }
2451
+ else if (plan === 'Trial') {
2452
+ await expectBillingTabForTrialPlan(page, {
2453
+ hasPaymentMethod: Boolean(options === null || options === void 0 ? void 0 : options.hasPaymentMethod),
2454
+ });
2455
+ }
2456
+ else {
2457
+ await expectBillingTabForPremiumPlan(page, {
2458
+ hasPaymentMethod: Boolean(options === null || options === void 0 ? void 0 : options.hasPaymentMethod),
2459
+ });
2460
+ }
2461
+ return plan;
2462
+ }
2463
+ /** Clicks the Upgrade button in the Plan section (visible only on non-Premium plans). */
2464
+ async function clickBillingUpgrade(page) {
2465
+ const btn = billingPlanSection(page).getByRole('button', { name: /^Upgrade$/ });
2466
+ await test$1.expect(btn).toBeVisible({ timeout: DEFAULT_TIMEOUT });
2467
+ await btn.click();
2468
+ }
2469
+ /** Clicks the Add Credits button in the Credits section (non-Free + has payment method). */
2470
+ async function clickBillingAddCredits(page) {
2471
+ const btn = billingCreditsSection(page).getByRole('button', { name: /^Add Credits$/ });
2472
+ await test$1.expect(btn).toBeVisible({ timeout: DEFAULT_TIMEOUT });
2473
+ await btn.click();
2474
+ }
2475
+ /** Clicks the Manage Billing button in the Credits section (non-Free + no payment method). */
2476
+ async function clickBillingManageBilling(page) {
2477
+ const btn = billingCreditsSection(page).getByRole('button', { name: /^Manage Billing$/ });
2478
+ await test$1.expect(btn).toBeVisible({ timeout: DEFAULT_TIMEOUT });
2479
+ await btn.click();
2480
+ }
2481
+ /** Clicks the Manage Usage button in the Auto Recharge section. */
2482
+ async function clickBillingManageUsage(page) {
2483
+ const btn = billingAutoRechargeSection(page).getByRole('button', { name: /^Manage Usage$/ });
2484
+ await test$1.expect(btn).toBeVisible({ timeout: DEFAULT_TIMEOUT });
2485
+ await btn.click();
2486
+ }
2487
+
2081
2488
  /** Extract browser key from device name (e.g., 'Desktop Chrome' -> 'chrome') */
2082
2489
  function getBrowserKey(deviceName) {
2083
2490
  return deviceName.toLowerCase().replace(/^desktop\s+/, '');
@@ -2213,19 +2620,42 @@ exports.MailsacClient = MailsacClient;
2213
2620
  exports.addMemory = addMemory;
2214
2621
  exports.archiveFirstMemory = archiveFirstMemory;
2215
2622
  exports.archiveMemoryByContent = archiveMemoryByContent;
2623
+ exports.billingAutoRechargeSection = billingAutoRechargeSection;
2624
+ exports.billingCreditsSection = billingCreditsSection;
2625
+ exports.billingPlanSection = billingPlanSection;
2216
2626
  exports.buildReportUrl = buildReportUrl;
2217
2627
  exports.canChatWithEmbedMentor = canChatWithEmbedMentor;
2218
2628
  exports.checkAdminStatus = checkAdminStatus;
2219
2629
  exports.clearDateRangeFilter = clearDateRangeFilter;
2220
2630
  exports.clickBackHome = clickBackHome;
2631
+ exports.clickBillingAddCredits = clickBillingAddCredits;
2632
+ exports.clickBillingManageBilling = clickBillingManageBilling;
2633
+ exports.clickBillingManageUsage = clickBillingManageUsage;
2634
+ exports.clickBillingUpgrade = clickBillingUpgrade;
2221
2635
  exports.clickDownloadAgain = clickDownloadAgain;
2222
2636
  exports.clickManualDownloadLink = clickManualDownloadLink;
2637
+ exports.closeCreditBalanceDropdown = closeCreditBalanceDropdown;
2223
2638
  exports.closeWithEsc = closeWithEsc;
2224
2639
  exports.createAuthSetup = createAuthSetup;
2225
2640
  exports.createEnvConfig = createEnvConfig;
2226
2641
  exports.createPlaywrightConfig = createPlaywrightConfig;
2642
+ exports.creditBalancePanel = creditBalancePanel;
2643
+ exports.creditBalancePlanBadge = creditBalancePlanBadge;
2644
+ exports.creditBalanceTrigger = creditBalanceTrigger;
2227
2645
  exports.deleteFirstMemory = deleteFirstMemory;
2228
2646
  exports.deleteMemoryByContent = deleteMemoryByContent;
2647
+ exports.expectBillingAutoRechargeSection = expectBillingAutoRechargeSection;
2648
+ exports.expectBillingCreditsSection = expectBillingCreditsSection;
2649
+ exports.expectBillingPlanSection = expectBillingPlanSection;
2650
+ exports.expectBillingTabForCurrentPlan = expectBillingTabForCurrentPlan;
2651
+ exports.expectBillingTabForFreePlan = expectBillingTabForFreePlan;
2652
+ exports.expectBillingTabForPremiumPlan = expectBillingTabForPremiumPlan;
2653
+ exports.expectBillingTabForTrialPlan = expectBillingTabForTrialPlan;
2654
+ exports.expectCreditBalanceForCurrentPlan = expectCreditBalanceForCurrentPlan;
2655
+ exports.expectCreditBalancePanelForFreePlan = expectCreditBalancePanelForFreePlan;
2656
+ exports.expectCreditBalancePanelForPremiumPlan = expectCreditBalancePanelForPremiumPlan;
2657
+ exports.expectCreditBalancePanelForTrialPlan = expectCreditBalancePanelForTrialPlan;
2658
+ exports.expectCreditBalanceVisibilityForTenant = expectCreditBalanceVisibilityForTenant;
2229
2659
  exports.expectNoAccessibilityViolations = expectNoAccessibilityViolations;
2230
2660
  exports.expectNoAccessibilityViolationsOnDialogs = expectNoAccessibilityViolationsOnDialogs;
2231
2661
  exports.filterByAction = filterByAction;
@@ -2237,7 +2667,12 @@ exports.generateBrowserSetupProjects = generateBrowserSetupProjects;
2237
2667
  exports.generateProjectConfig = generateProjectConfig;
2238
2668
  exports.getAuditLogRowCount = getAuditLogRowCount;
2239
2669
  exports.getAvailableActors = getAvailableActors;
2670
+ exports.getBillingAutoRechargeStatus = getBillingAutoRechargeStatus;
2671
+ exports.getBillingPlanLabel = getBillingPlanLabel;
2240
2672
  exports.getBrowserKey = getBrowserKey;
2673
+ exports.getCreditBalancePlanLabel = getCreditBalancePlanLabel;
2674
+ exports.getCreditBalanceRemaining = getCreditBalanceRemaining;
2675
+ exports.getCurrentTenantShowPaywall = getCurrentTenantShowPaywall;
2241
2676
  exports.getMemoryCount = getMemoryCount;
2242
2677
  exports.getMentorIdFromUrl = getMentorIdFromUrl;
2243
2678
  exports.getPaginationInfo = getPaginationInfo;
@@ -2261,6 +2696,7 @@ exports.navigateToAuditLogAndWaitForData = navigateToAuditLogAndWaitForData;
2261
2696
  exports.navigateToDataReports = navigateToDataReports;
2262
2697
  exports.navigateToReportDownload = navigateToReportDownload;
2263
2698
  exports.openAddMemoryDialog = openAddMemoryDialog;
2699
+ exports.openCreditBalanceDropdown = openCreditBalanceDropdown;
2264
2700
  exports.parseReportUrlParams = parseReportUrlParams;
2265
2701
  exports.reliableClick = reliableClick;
2266
2702
  exports.reliableFill = reliableFill;
@@ -2303,6 +2739,8 @@ exports.verifyMemoryTabMemoriesList = verifyMemoryTabMemoriesList;
2303
2739
  exports.verifyMemoryTabSettings = verifyMemoryTabSettings;
2304
2740
  exports.verifyPreparingPhase = verifyPreparingPhase;
2305
2741
  exports.waitForAuditLogDataLoaded = waitForAuditLogDataLoaded;
2742
+ exports.waitForBillingTabReady = waitForBillingTabReady;
2743
+ exports.waitForCreditBalanceLoaded = waitForCreditBalanceLoaded;
2306
2744
  exports.waitForDialogReady = waitForDialogReady;
2307
2745
  exports.waitForElementStable = waitForElementStable;
2308
2746
  exports.waitForPageLoad = waitForPageLoad;