Back to Repositories

Testing Preferences and Environment Filter Implementation in Insomnia

This test suite validates preferences and environment filtering functionality in Insomnia through both UI interactions and keyboard shortcuts. It covers essential user preference settings and environment-based response filtering capabilities.

Test Coverage Overview

The test suite provides comprehensive coverage of Insomnia’s preferences functionality.

Key areas tested include:
  • Preferences access via UI button clicks
  • Keyboard shortcut navigation (platform-specific)
  • Environment-based response filtering
  • Request sending and response validation
Integration points cover clipboard operations, modal dialogs, and environment configurations.

Implementation Analysis

The testing approach utilizes Playwright’s page object model for UI interaction simulation.

Technical patterns include:
  • Platform-specific logic handling (Darwin vs other OS)
  • Fixture loading for test data
  • Clipboard integration for import operations
  • Async/await patterns for UI interactions

Technical Details

Testing tools and configuration:
  • Playwright test runner
  • Custom fixture loading utilities
  • TestID-based element selection
  • Platform-aware keyboard shortcuts
  • YAML fixtures for data loading

Best Practices Demonstrated

The test suite exemplifies high-quality testing practices through structured organization and robust validation.

Notable practices include:
  • Consistent element selection strategies
  • Clear test case isolation
  • Platform-specific handling
  • Comprehensive UI interaction coverage
  • Explicit wait patterns for reliability

kong/insomnia

packages/insomnia-smoke-test/tests/smoke/preferences-interactions.test.ts

            
import { loadFixture } from '../../playwright/paths';
import { test } from '../../playwright/test';

test('Preferences through click', async ({ page }) => {
  await page.locator('[data-testid="settings-button"]').click();
  await page.locator('text=Insomnia Preferences').first().click();
});

test('Preferences through keyboard shortcut', async ({ page }) => {
  if (process.platform === 'darwin') {
    await page.locator('.app').press('Meta+,');
  } else {
    await page.locator('.app').press('Control+,');
  }
  await page.locator('text=Insomnia Preferences').first().click();
});

// Quick reproduction for Kong/insomnia#5664 and INS-2267
test('Check filter responses by environment preference', async ({ app, page }) => {
  const text = await loadFixture('simple.yaml');
  await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
  await page.getByLabel('Import').click();
  await page.locator('[data-test-id="import-from-clipboard"]').click();
  await page.getByRole('button', { name: 'Scan' }).click();
  await page.getByRole('dialog').getByRole('button', { name: 'Import' }).click();
  await page.getByLabel('simple').click();

  // Send a request
  await page.getByLabel('Request Collection').getByTestId('example http').press('Enter');
  await page.click('[data-testid="request-pane"] button:has-text("Send")');
  await page.click('text=Console');
  await page.locator('text=HTTP/1.1 200 OK').click();

  // Set filter responses by environment
  await page.locator('[data-testid="settings-button"]').click();
  await page.locator('text=Insomnia Preferences').first().click();
  await page.locator('text=Filter responses by environment').click();
  await page.locator('.app').press('Escape');

  // Re-send the request and check timeline
  await page.locator('[data-testid="request-pane"] button:has-text("Send")').click();
  await page.click('text=Console');
  await page.locator('text=HTTP/1.1 200 OK').click();
});