Skip to main content

Test Utilities Overview

This section documents the various test utility packages available in the wrkbelt platform to help with testing different aspects of the application.

Available Test Utility Packages

PackageDescriptionPrimary Use Case
@wrkbelt/api/utils-test-apiAPI testing utilitiesTesting backend APIs with Playwright
@wrkbelt/ui/utils-test-uiUI testing utilitiesTesting UI components and pages with Playwright
@wrkbelt/shared/utils-testShared testing utilitiesCommon utilities for all test types

Getting Started with Test Utilities

To use these test utilities in your project, you'll need to install the relevant packages. Each package is designed to work with Playwright as the testing framework.

Setting Up a New Test

  1. Install the required packages:

    npm install @playwright/test @wrkbelt/shared/utils-test
    # Plus any other specific test utilities based on your needs
  2. Create test files:

    // example-api.spec.ts
    import { test, expect } from '@playwright/test';
    import { BookingAnswerCategoriesController } from '@wrkbelt/api/utils-test-api';
    import { getValueByEnv, Environments } from '@wrkbelt/shared/utils-test';

    test('API test example', async ({ request }) => {
    const controller = new BookingAnswerCategoriesController(request);
    const response = await controller.getBookingAnswerCategories('org-123');
    expect(response.ok()).toBeTruthy();
    });
  3. Run the tests:

    npx playwright test

Combining Utilities

The test utilities are designed to work together. For example, you can use:

  • @wrkbelt/shared/utils-test for environment configuration
  • @wrkbelt/api/utils-test-api for testing API endpoints
  • @wrkbelt/ui/utils-test-ui for testing UI components that interact with these APIs

Best Practices

  • Use the appropriate utility package for the specific testing task
  • Create reusable components and page objects for UI testing
  • Leverage the BaseController pattern for API testing
  • Use environment utilities to handle environment-specific configuration
  • Add metadata to test reports in CI/CD pipelines

For more detailed information about each package, please refer to their individual documentation pages.