Skip to content

A local-first personal finance app

4.5 KB
Raw Blame
import path from 'path';

import type { Page } from '@playwright/test';

import { expect, test } from './fixtures';
import { ConfigurationPage } from './page-models/configuration-page';
import { Navigation } from './page-models/navigation';

test.describe('Onboarding', () => {
  let page: Page;
  let navigation: Navigation;
  let configurationPage: ConfigurationPage;

  test.beforeEach(async ({ browser }) => {
    page = await browser.newPage();
    navigation = new Navigation(page);
    configurationPage = new ConfigurationPage(page);

    await page.goto('/');
  });

  test.afterEach(async () => {
    await page?.close();
  });

  test('checks the page visuals', async () => {
    await expect(page.getByText('Welcome to Actual')).toBeVisible();
    await expect(page).toMatchThemeScreenshots();

    await configurationPage.clickOnConnectServer();
    await expect(configurationPage.heading).toHaveText('Connect to a server');
    await expect(page).toMatchThemeScreenshots();
  });

  test('creates a new budget file by importing YNAB4 budget', async () => {
    const budgetPage = await configurationPage.importBudget(
      'YNAB4',
      path.resolve(__dirname, 'data/ynab4-demo-budget.zip'),
    );

    await expect(budgetPage.budgetTable).toBeVisible({ timeout: 30000 });

    const accountPage = await navigation.goToAccountPage(
      'Account1 with Starting Balance',
    );
    await expect(accountPage.accountBalance).toHaveText('-400.00');

    await navigation.goToAccountPage('Account2 no Starting Balance');
    await expect(accountPage.accountBalance).toHaveText('2,607.00');
  });

  test('creates a new budget file by importing nYNAB budget', async () => {
    const budgetPage = await configurationPage.importBudget(
      'nYNAB',
      path.resolve(__dirname, 'data/ynab5-demo-budget.json'),
    );

    await expect(budgetPage.budgetTable).toBeVisible({ timeout: 30000 });

    const accountPage = await navigation.goToAccountPage('Checking');
    await expect(accountPage.accountBalance).toHaveText('2,600.00');

    await navigation.goToAccountPage('Saving');
    await expect(accountPage.accountBalance).toHaveText('250.00');

    await navigation.goToSchedulesPage();
    const scheduleRows = page.getByTestId('table').getByTestId('row');
    const scheduleNames = [
      'Scheduled - repeated every four weeks',
      'Scheduled - repeated every other week',
      'Scheduled - repeated every other year',
      'Scheduled - repeated every four months',
      'Scheduled - repeated twice a month',
      'Scheduled - repeated monthly',
      'Scheduled - repeated weekly',
      'Scheduled - not repeated',
      'Scheduled - repeated twice a year',
      'Scheduled - repeated yearly',
      'Scheduled - repeated every other month',
      'Scheduled - repeated every three months',
      'Scheduled - repeated daily',
      'Scheduled - split categories monthly',
      'Scheduled - transfer to Saving',
    ];

    for (const scheduleName of scheduleNames) {
      await expect(scheduleRows.filter({ hasText: scheduleName })).toHaveCount(
        1,
      );
    }
  });

  test('creates a new budget file by importing Actual budget', async () => {
    const budgetPage = await configurationPage.importBudget(
      'Actual',
      path.resolve(__dirname, 'data/actual-demo-budget.zip'),
    );

    await expect(budgetPage.budgetTable).toBeVisible({ timeout: 20_000 });

    const accountPage = await navigation.goToAccountPage('Ally Savings');
    await expect(accountPage.accountBalance).toHaveText('1,772.80');

    await navigation.goToAccountPage('Roth IRA');
    await expect(accountPage.accountBalance).toHaveText('2,745.81');
  });

  test('creates a new empty budget file', async () => {
    const budgetPage = await configurationPage.startFresh();

    await expect(budgetPage.budgetTable).toBeVisible();

    const accountPage = await navigation.goToAccountPage('All accounts');
    await expect(accountPage.accountName).toBeVisible();
    await expect(accountPage.accountName).toHaveText('All Accounts');
    await expect(accountPage.accountBalance).toHaveText('0.00');
  });

  test('navigates back to start page by clicking on "no server" in an empty budget file', async () => {
    const budgetPage = await configurationPage.startFresh();

    await expect(budgetPage.budgetTable).toBeVisible();

    await navigation.clickOnNoServer();
    await page.getByRole('button', { name: 'Start using a server' }).click();

    await expect(configurationPage.heading).toHaveText('Connect to a server');
  });
});