Back to Repositories

Testing Workspace Label Assignment in Insomnia

This test suite validates the workspace label functionality in Insomnia, focusing on the getWorkspaceLabel utility. It ensures correct label assignment for different workspace scopes, specifically testing document and collection labels.

Test Coverage Overview

The test suite provides targeted coverage for workspace label determination based on scope values.

  • Tests document scope label assignment
  • Validates collection scope label assignment
  • Covers core workspace scope enumeration

Implementation Analysis

The testing approach utilizes Jest’s describe/it pattern with TypeScript integration. The implementation leverages workspace model initialization and scope verification, ensuring type safety through TypeScript interfaces.

  • Workspace model initialization testing
  • Scope enumeration validation
  • String constant verification

Technical Details

  • Testing Framework: Jest with TypeScript
  • Model Utilities: workspace.init()
  • Scope Enums: WorkspaceScopeKeys
  • String Constants: strings object

Best Practices Demonstrated

The test suite demonstrates clean testing practices with clear test case isolation and descriptive naming. Each test focuses on a single responsibility with explicit expectations and proper model initialization.

  • Isolated test cases
  • Clear test descriptions
  • Proper model initialization
  • Type-safe testing approach

kong/insomnia

packages/insomnia/src/common/__tests__/strings.test.ts

            
import { describe, expect, it } from 'vitest';

import * as models from '../../models';
import { WorkspaceScopeKeys } from '../../models/workspace';
import { getWorkspaceLabel } from '../get-workspace-label';
import { strings } from '../strings';

describe('getWorkspaceLabel', () => {
  it('should return document label', () => {
    const w = models.workspace.init();
    w.scope = WorkspaceScopeKeys.design;
    expect(getWorkspaceLabel(w)).toBe(strings.document);
  });

  it('should return collection label', () => {
    const w = models.workspace.init();
    w.scope = WorkspaceScopeKeys.collection;
    expect(getWorkspaceLabel(w)).toBe(strings.collection);
  });
});