|
| 1 | +import { by, device, element, expect, waitFor } from 'detox'; |
| 2 | + |
| 3 | +const BILLING_LABELS: Record<'monthly' | 'yearly' | 'weekly', string> = { |
| 4 | + monthly: 'Monthly', |
| 5 | + yearly: 'Yearly', |
| 6 | + weekly: 'Weekly', |
| 7 | +}; |
| 8 | + |
| 9 | +export const launchCleanApp = async () => { |
| 10 | + await device.launchApp({ newInstance: true, delete: true }); |
| 11 | + await waitFor(element(by.id('app-root'))).toExist().withTimeout(30000); |
| 12 | + await waitFor(element(by.id('home-screen'))).toExist().withTimeout(30000); |
| 13 | +}; |
| 14 | + |
| 15 | +export const createSubscription = async ( |
| 16 | + name: string, |
| 17 | + price: string, |
| 18 | + cycle: 'monthly' | 'yearly' | 'weekly' = 'monthly' |
| 19 | +) => { |
| 20 | + await element(by.id('add-subscription-button')).tap(); |
| 21 | + await waitFor(element(by.id('add-subscription-screen'))).toBeVisible().withTimeout(10000); |
| 22 | + await expect(element(by.id('subscription-form-title'))).toBeVisible(); |
| 23 | + |
| 24 | + await element(by.id('subscription-name-input')).replaceText(name); |
| 25 | + await element(by.id('subscription-price-input')).replaceText(price); |
| 26 | + |
| 27 | + if (cycle !== 'monthly') { |
| 28 | + await element(by.id(`billing-cycle-option-${cycle}`)).tap(); |
| 29 | + } |
| 30 | + |
| 31 | + await element(by.id('save-subscription-button')).tap(); |
| 32 | + await dismissAnySystemAlert(); |
| 33 | + |
| 34 | + await waitFor(element(by.text(name))).toBeVisible().withTimeout(15000); |
| 35 | +}; |
| 36 | + |
| 37 | +export const openSubscriptionByName = async (name: string) => { |
| 38 | + await waitFor(element(by.text(name))).toBeVisible().withTimeout(10000); |
| 39 | + await element(by.text(name)).tap(); |
| 40 | + await waitFor(element(by.id('subscription-detail-screen'))).toBeVisible().withTimeout(10000); |
| 41 | +}; |
| 42 | + |
| 43 | +export const expectBillingCycle = async (cycle: 'monthly' | 'yearly' | 'weekly') => { |
| 44 | + await expect(element(by.id('subscription-billing-cycle-value'))).toHaveText(BILLING_LABELS[cycle]); |
| 45 | +}; |
| 46 | + |
| 47 | +export const dismissAnySystemAlert = async () => { |
| 48 | + const labels = ['OK', 'Ok', 'Later', 'Cancel']; |
| 49 | + for (const label of labels) { |
| 50 | + const alertButton = element(by.text(label)); |
| 51 | + try { |
| 52 | + await waitFor(alertButton).toBeVisible().withTimeout(600); |
| 53 | + await alertButton.tap(); |
| 54 | + return; |
| 55 | + } catch { |
| 56 | + // No-op: button not present. |
| 57 | + } |
| 58 | + } |
| 59 | +}; |
0 commit comments