Skip to content

A local-first personal finance app

:white_check_mark: (e2e) adding mobile e2e tests (#1521)

Matiss Janis Aboltins884ab8c78306
diff --git a/packages/desktop-client/e2e/mobile.test.js b/packages/desktop-client/e2e/mobile.test.js
new file mode 100644
index 0000000000..d5f65b38ce
--- /dev/null
+++ b/packages/desktop-client/e2e/mobile.test.js
@@ -0,0 +1,111 @@
+import { test, expect } from '@playwright/test';
+
+import { ConfigurationPage } from './page-models/configuration-page';
+import { MobileNavigation } from './page-models/mobile-navigation';
+
+test.describe('Mobile', () => {
+ let page;
+ let navigation;
+ let configurationPage;
+
+ test.beforeEach(async ({ browser }) => {
+ page = await browser.newPage();
+ navigation = new MobileNavigation(page);
+ configurationPage = new ConfigurationPage(page);
+
+ await page.setViewportSize({
+ width: 350,
+ height: 600,
+ });
+ await page.goto('/');
+ await configurationPage.createTestFile();
+ });
+
+ test.afterEach(async () => {
+ await page.close();
+ });
+
+ test('loads the budget page with budgeted amounts', async () => {
+ const budgetPage = await navigation.goToBudgetPage();
+
+ await expect(budgetPage.categoryNames).toHaveText([
+ 'Food',
+ 'Restaurants',
+ 'Entertainment',
+ 'Clothing',
+ 'General',
+ 'Gift',
+ 'Medical',
+ 'Savings',
+ 'Cell',
+ 'Internet',
+ 'Mortgage',
+ 'Water',
+ 'Power',
+ ]);
+ });
+
+ test('opens the accounts page and asserts on balances', async () => {
+ const accountsPage = await navigation.goToAccountsPage();
+
+ const account = await accountsPage.getNthAccount(0);
+
+ expect(account.name).toEqual('Ally Savings');
+ expect(account.balance).toBeGreaterThan(0);
+ });
+
+ test('opens individual account page and checks that filtering is working', async () => {
+ const accountsPage = await navigation.goToAccountsPage();
+ const accountPage = await accountsPage.openNthAccount(1);
+
+ await expect(accountPage.heading).toHaveText('Bank of America');
+ expect(await accountPage.getBalance()).toBeGreaterThan(0);
+
+ await expect(accountPage.noTransactionsFoundError).not.toBeVisible();
+
+ await accountPage.searchByText('nothing should be found');
+ await expect(accountPage.noTransactionsFoundError).toBeVisible();
+ await expect(accountPage.transactions).toHaveCount(0);
+
+ await accountPage.searchByText('Kroger');
+ await expect(accountPage.transactions).not.toHaveCount(0);
+ });
+
+ test('creates a transaction', async () => {
+ const accountsPage = await navigation.goToAccountsPage();
+ const accountPage = await accountsPage.openNthAccount(1);
+ const transactionEntryPage = await accountPage.clickCreateTransaction();
+
+ await expect(transactionEntryPage.header).toHaveText('New Transaction');
+
+ await transactionEntryPage.amountField.fill('12.34');
+ await transactionEntryPage.fillField(
+ page.getByTestId('payee-field'),
+ 'Kroger',
+ );
+ await transactionEntryPage.fillField(
+ page.getByTestId('category-field'),
+ 'Clothing',
+ );
+
+ await transactionEntryPage.add.click();
+
+ await expect(accountPage.transactions.nth(0)).toHaveText(
+ 'KrogerClothing-12.34',
+ );
+ });
+
+ test('checks that settings page can be opened', async () => {
+ const settingsPage = await navigation.goToSettingsPage();
+
+ const downloadPromise = page.waitForEvent('download');
+
+ await settingsPage.exportData();
+
+ const download = await downloadPromise;
+
+ expect(await download.suggestedFilename()).toMatch(
+ /^\d{4}-\d{2}-\d{2}-.*.zip$/,
+ );
+ });
+});
diff --git a/packages/desktop-client/e2e/page-models/mobile-account-page.js b/packages/desktop-client/e2e/page-models/mobile-account-page.js
new file mode 100644
index 0000000000..9e58489fb7
--- /dev/null
+++ b/packages/desktop-client/e2e/page-models/mobile-account-page.js
@@ -0,0 +1,39 @@
+import { MobileTransactionEntryPage } from './mobile-transaction-entry-page';
+
+export class MobileAccountPage {
+ constructor(page) {
+ this.page = page;
+
+ this.heading = page.getByRole('heading');
+ this.balance = page.getByTestId('account-balance');
+ this.noTransactionsFoundError = page.getByText('No transactions');
+ this.searchBox = page.getByPlaceholder(/^Search/);
+ this.transactionList = page.getByLabel('transaction list');
+ this.transactions = this.transactionList.getByRole('button');
+ this.createTransactionButton = page.getByRole('button', {
+ name: 'Add Transaction',
+ });
+ }
+
+ /**
+ * Retrieve the balance of the account as a number
+ */
+ async getBalance() {
+ return parseInt(await this.balance.textContent(), 10);
+ }
+
+ /**
+ * Search by the given term
+ */
+ async searchByText(term) {
+ await this.searchBox.fill(term);
+ }
+
+ /**
+ * Go to transaction creation page
+ */
+ async clickCreateTransaction() {
+ this.createTransactionButton.click();
+ return new MobileTransactionEntryPage(this.page);
+ }
+}
diff --git a/packages/desktop-client/e2e/page-models/mobile-accounts-page.js b/packages/desktop-client/e2e/page-models/mobile-accounts-page.js
new file mode 100644
index 0000000000..5c0b8c601c
--- /dev/null
+++ b/packages/desktop-client/e2e/page-models/mobile-accounts-page.js
@@ -0,0 +1,33 @@
+import { MobileAccountPage } from './mobile-account-page';
+
+export class MobileAccountsPage {
+ constructor(page) {
+ this.page = page;
+
+ this.accounts = this.page.getByTestId('account');
+ }
+
+ /**
+ * Get the name and balance of the nth account
+ */
+ async getNthAccount(idx) {
+ const accountRow = this.accounts.nth(idx);
+
+ return {
+ name: await accountRow.getByTestId('account-name').textContent(),
+ balance: parseInt(
+ await accountRow.getByTestId('account-balance').textContent(),
+ 10,
+ ),
+ };
+ }
+
+ /**
+ * Click on the n-th account to open it up
+ */
+ async openNthAccount(idx) {
+ await this.accounts.nth(idx).getByRole('button').click();
+
+ return new MobileAccountPage(this.page);
+ }
+}
diff --git a/packages/desktop-client/e2e/page-models/mobile-budget-page.js b/packages/desktop-client/e2e/page-models/mobile-budget-page.js
new file mode 100644
index 0000000000..c5d843fd22
--- /dev/null
+++ b/packages/desktop-client/e2e/page-models/mobile-budget-page.js
@@ -0,0 +1,9 @@
+export class MobileBudgetPage {
+ constructor(page) {
+ this.page = page;
+
+ this.categoryNames = page
+ .getByTestId('budget-groups')
+ .getByTestId('category-name');
+ }
+}
diff --git a/packages/desktop-client/e2e/page-models/mobile-navigation.js b/packages/desktop-client/e2e/page-models/mobile-navigation.js
new file mode 100644
index 0000000000..16d667af25
--- /dev/null
+++ b/packages/desktop-client/e2e/page-models/mobile-navigation.js
@@ -0,0 +1,30 @@
+import { MobileAccountsPage } from './mobile-accounts-page';
+import { MobileBudgetPage } from './mobile-budget-page';
+import { SettingsPage } from './settings-page';
+
+export class MobileNavigation {
+ constructor(page) {
+ this.page = page;
+ }
+
+ async goToBudgetPage() {
+ const link = this.page.getByRole('link', { name: 'Budget' });
+ await link.click();
+
+ return new MobileBudgetPage(this.page);
+ }
+
+ async goToAccountsPage() {
+ const link = this.page.getByRole('link', { name: 'Accounts' });
+ await link.click();
+
+ return new MobileAccountsPage(this.page);
+ }
+
+ async goToSettingsPage() {
+ const link = this.page.getByRole('link', { name: 'Settings' });
+ await link.click();
+
+ return new SettingsPage(this.page);
+ }
+}
diff --git a/packages/desktop-client/e2e/page-models/mobile-transaction-entry-page.js b/packages/desktop-client/e2e/page-models/mobile-transaction-entry-page.js
new file mode 100644
index 0000000000..3b5115f72f
--- /dev/null
+++ b/packages/desktop-client/e2e/page-models/mobile-transaction-entry-page.js
@@ -0,0 +1,15 @@
+export class MobileTransactionEntryPage {
+ constructor(page) {
+ this.page = page;
+
+ this.header = page.getByRole('heading');
+ this.amountField = page.getByTestId('amount-input');
+ this.add = page.getByRole('button', { name: 'Add transaction' });
+ }
+
+ async fillField(fieldLocator, content) {
+ await fieldLocator.click();
+ await this.page.locator('css=[role=combobox] input').fill(content);
+ await this.page.keyboard.press('Enter');
+ }
+}
diff --git a/packages/desktop-client/src/components/accounts/MobileAccountDetails.js b/packages/desktop-client/src/components/accounts/MobileAccountDetails.js
index 6def3b6bad..1d3ac56fd7 100644
--- a/packages/desktop-client/src/components/accounts/MobileAccountDetails.js
+++ b/packages/desktop-client/src/components/accounts/MobileAccountDetails.js
@@ -5,7 +5,7 @@ import Add from '../../icons/v1/Add';
import CheveronLeft from '../../icons/v1/CheveronLeft';
import SearchAlternate from '../../icons/v2/SearchAlternate';
import { theme, styles } from '../../style';
-import Button from '../common/Button';
+import ButtonLink from '../common/ButtonLink';
import InputWithContent from '../common/InputWithContent';
import Label from '../common/Label';
import Text from '../common/Text';
@@ -126,21 +126,21 @@ export default function AccountDetails({
fontSize: 16,
fontWeight: 500,
}}
+ role="heading"
>
{account.name}
</View>
- {/*
- TODO: connect to an add transaction modal
- Only left here but hidden for flex centering of the account name.
- */}
- <Link to="transactions/new">
- <Button
- type="bare"
- style={{ justifyContent: 'center', width: LEFT_RIGHT_FLEX_WIDTH }}
- >
- <Add width={20} height={20} />
- </Button>
- </Link>
+
+ <ButtonLink
+ to="transactions/new"
+ type="bare"
+ aria-label="Add Transaction"
+ style={{ justifyContent: 'center', width: LEFT_RIGHT_FLEX_WIDTH }}
+ hoveredStyle={{ background: 'transparent' }}
+ activeStyle={{ background: 'transparent' }}
+ >
+ <Add width={20} height={20} />
+ </ButtonLink>
</View>
<Label title="BALANCE" style={{ marginTop: 10 }} />
<CellValue
@@ -154,6 +154,7 @@ export default function AccountDetails({
getStyle={value => ({
color: value < 0 ? theme.errorText : theme.pillTextHighlighted,
})}
+ data-testid="account-balance"
/>
<TransactionSearchInput
accountName={account.name}
diff --git a/packages/desktop-client/src/components/accounts/MobileAccounts.js b/packages/desktop-client/src/components/accounts/MobileAccounts.js
index 20b01341db..aae8c13d46 100644
--- a/packages/desktop-client/src/components/accounts/MobileAccounts.js
+++ b/packages/desktop-client/src/components/accounts/MobileAccounts.js
@@ -59,6 +59,7 @@ function AccountCard({ account, updated, getBalanceQuery, onSelect }) {
borderRadius: 6,
marginTop: 10,
}}
+ data-testid="account"
>
<Button
onMouseDown={() => onSelect(account.id)}
@@ -94,6 +95,7 @@ function AccountCard({ account, updated, getBalanceQuery, onSelect }) {
paddingRight: 30,
},
]}
+ data-testid="account-name"
>
{account.name}
</TextOneLine>
@@ -115,6 +117,7 @@ function AccountCard({ account, updated, getBalanceQuery, onSelect }) {
type="financial"
style={{ fontSize: 16, color: 'inherit' }}
getStyle={value => value < 0 && { color: 'inherit' }}
+ data-testid="account-balance"
/>
</Button>
</View>
diff --git a/packages/desktop-client/src/components/budget/MobileBudgetTable.js b/packages/desktop-client/src/components/budget/MobileBudgetTable.js
index c74999e326..255c7642b3 100644
--- a/packages/desktop-client/src/components/budget/MobileBudgetTable.js
+++ b/packages/desktop-client/src/components/budget/MobileBudgetTable.js
@@ -287,7 +287,9 @@ class BudgetCategory extends PureComponent {
data-testid="row"
>
<View style={{ flex: 1 }}>
- <Text style={styles.smallText}>{category.name}</Text>
+ <Text style={styles.smallText} data-testid="category-name">
+ {category.name}
+ </Text>
</View>
{/* <Animated.View
style={{
diff --git a/packages/desktop-client/src/components/common/Button.tsx b/packages/desktop-client/src/components/common/Button.tsx
index f630ba82d3..8d05afe8fc 100644
--- a/packages/desktop-client/src/components/common/Button.tsx
+++ b/packages/desktop-client/src/components/common/Button.tsx
@@ -94,11 +94,11 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
hoveredStyle = [
type !== 'bare' && styles.shadow,
- hoveredStyle,
{
backgroundColor: backgroundColorHover[type],
color: color || textColorHover[type],
},
+ hoveredStyle,
];
activeStyle = [
type === 'bare'
diff --git a/packages/desktop-client/src/components/common/ButtonLink.tsx b/packages/desktop-client/src/components/common/ButtonLink.tsx
index 77688daf56..2f0d8561c7 100644
--- a/packages/desktop-client/src/components/common/ButtonLink.tsx
+++ b/packages/desktop-client/src/components/common/ButtonLink.tsx
@@ -23,6 +23,7 @@ export default function ButtonLink({
...style,
...(match ? activeStyle : {}),
}}
+ activeStyle={activeStyle}
{...props}
onClick={e => {
props.onClick?.(e);
diff --git a/packages/desktop-client/src/components/mobile/MobileForms.js b/packages/desktop-client/src/components/mobile/MobileForms.js
index 67757db043..d921b5ad57 100644
--- a/packages/desktop-client/src/components/mobile/MobileForms.js
+++ b/packages/desktop-client/src/components/mobile/MobileForms.js
@@ -76,6 +76,7 @@ export function TapField({
style,
textStyle,
onClick,
+ ...props
}) {
return (
<Button
@@ -97,6 +98,7 @@ export function TapField({
boxShadow: 'none',
}}
// activeOpacity={0.05}
+ {...props}
>
{children ? (
children
diff --git a/packages/desktop-client/src/components/spreadsheet/CellValue.tsx b/packages/desktop-client/src/components/spreadsheet/CellValue.tsx
index af637da6c1..13a921f0a2 100644
--- a/packages/desktop-client/src/components/spreadsheet/CellValue.tsx
+++ b/packages/desktop-client/src/components/spreadsheet/CellValue.tsx
@@ -22,6 +22,7 @@ type CellValueProps = {
style?: CSSProperties;
getStyle?: (value) => CSSProperties;
privacyFilter?: ConditionalPrivacyFilterProps['privacyFilter'];
+ ['data-testid']?: string;
};
function CellValue({
@@ -31,6 +32,7 @@ function CellValue({
style,
getStyle,
privacyFilter,
+ 'data-testid': testId,
}: CellValueProps) {
let { fullSheetName } = useSheetName(binding);
let sheetValue = useSheetValue(binding);
@@ -53,7 +55,7 @@ function CellValue({
style,
getStyle && getStyle(sheetValue),
]}
- data-testid={fullSheetName}
+ data-testid={testId || fullSheetName}
data-cellname={fullSheetName}
>
{formatter ? formatter(sheetValue) : format(sheetValue, type)}
diff --git a/packages/desktop-client/src/components/transactions/MobileTransaction.js b/packages/desktop-client/src/components/transactions/MobileTransaction.js
index d5d3b66b6c..4f95dd8956 100644
--- a/packages/desktop-client/src/components/transactions/MobileTransaction.js
+++ b/packages/desktop-client/src/components/transactions/MobileTransaction.js
@@ -401,6 +401,7 @@ class TransactionEditInner extends PureComponent {
fontWeight: 600,
userSelect: 'none',
}}
+ role="heading"
>
{payeeId == null
? adding
@@ -473,6 +474,7 @@ class TransactionEditInner extends PureComponent {
<TapField
value={descriptionPretty}
onClick={() => this.onClick(transaction.id, 'payee')}
+ data-testid="payee-field"
/>
</View>
@@ -506,6 +508,7 @@ class TransactionEditInner extends PureComponent {
// </Button>
// }
onClick={() => this.onClick(transaction.id, 'category')}
+ data-testid="category-field"
/>
) : (
<Text style={{ paddingLeft: EDITING_PADDING }}>
diff --git a/upcoming-release-notes/1521.md b/upcoming-release-notes/1521.md
new file mode 100644
index 0000000000..e63435e87d
--- /dev/null
+++ b/upcoming-release-notes/1521.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+Add e2e tests for mobile views