Skip to content

An open source design system that's fully customizable and agent ready

TypeScript
1.3 KB
Raw Blame
// Copyright (c) Meta Platforms, Inc. and affiliates.

import {describe, expect, it} from 'vitest';
import {matchaTheme} from './matchaTheme';

const ROOT_FONT_SIZE_PX = 16;

// The pixel values these steps had before they moved to rem.
const previousPx: Record<string, number> = {
  '--spacing-0-5': 3,
  '--spacing-1': 6,
  '--spacing-1-5': 9,
  '--spacing-2': 12,
  '--spacing-3': 18,
  '--spacing-4': 24,
  '--spacing-5': 30,
  '--spacing-6': 36,
  '--spacing-7': 42,
  '--spacing-8': 48,
  '--spacing-9': 54,
  '--spacing-10': 60,
  '--spacing-11': 66,
  '--spacing-12': 72,
};

describe('matcha spacing steps', () => {
  const tokens = matchaTheme.tokens as Record<string, string>;
  const spacingSteps = Object.entries(tokens).filter(([name]) =>
    name.startsWith('--spacing-'),
  );

  it('are rem, so they follow the root font size', () => {
    expect(spacingSteps.length).toBe(Object.keys(previousPx).length);
    for (const [name, value] of spacingSteps) {
      expect(value, name).toMatch(/^\d+(\.\d+)?rem$/);
    }
  });

  it('keep their previous pixel values at the default 16px root', () => {
    for (const [name, px] of Object.entries(previousPx)) {
      expect(Number.parseFloat(tokens[name]) * ROOT_FONT_SIZE_PX, name).toBe(
        px,
      );
    }
  });
});