070959e133
landing-page-staging / Deploy landing page to staging (push) Has been skipped
landing-page-ci / Validate landing page (push) Failing after 4s
visual-baseline / Capture visual baselines (push) Has been cancelled
bake-plugin-previews / Bake plugin previews (push) Has been cancelled
97 lines
3.3 KiB
TypeScript
97 lines
3.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import type { DesignSystemSummary, Project } from '../../src/types';
|
|
|
|
import {
|
|
isDesignSystemProject,
|
|
isPublishedDesignSystemProject,
|
|
resolveProjectDesignSystemId,
|
|
} from '../../src/components/design-system-project';
|
|
|
|
function project(overrides: Partial<Project> = {}): Project {
|
|
return {
|
|
id: 'p1',
|
|
name: 'StackMe',
|
|
updatedAt: 1,
|
|
designSystemId: null,
|
|
...overrides,
|
|
} as Project;
|
|
}
|
|
|
|
function system(overrides: Partial<DesignSystemSummary> = {}): DesignSystemSummary {
|
|
return {
|
|
id: 'user:stackme',
|
|
title: 'StackMe',
|
|
category: 'Custom',
|
|
summary: '',
|
|
swatches: [],
|
|
surface: 'web',
|
|
source: 'user',
|
|
status: 'draft',
|
|
isEditable: true,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe('isDesignSystemProject', () => {
|
|
it('matches projects imported from a design system or generated by brand extraction', () => {
|
|
expect(isDesignSystemProject(project({ metadata: { kind: 'other', importedFrom: 'design-system' } }))).toBe(true);
|
|
expect(isDesignSystemProject(project({ metadata: { kind: 'brand', importedFrom: 'brand-extraction' } }))).toBe(true);
|
|
expect(isDesignSystemProject(project({ metadata: { kind: 'prototype', brandDesignSystemId: 'user:stackme' } }))).toBe(true);
|
|
expect(isDesignSystemProject(project({ metadata: { kind: 'prototype' } }))).toBe(false);
|
|
expect(isDesignSystemProject(project({ designSystemId: 'default', metadata: { kind: 'prototype' } }))).toBe(false);
|
|
expect(isDesignSystemProject(project())).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('resolveProjectDesignSystemId', () => {
|
|
it('prefers the extracted brand backing system over a generic project context', () => {
|
|
expect(resolveProjectDesignSystemId(project({
|
|
designSystemId: 'default',
|
|
metadata: {
|
|
kind: 'brand',
|
|
importedFrom: 'brand-extraction',
|
|
brandDesignSystemId: 'user:stackme',
|
|
},
|
|
}))).toBe('user:stackme');
|
|
});
|
|
|
|
it('uses the regular project design system id for non-brand projects', () => {
|
|
expect(resolveProjectDesignSystemId(project({
|
|
designSystemId: 'default',
|
|
metadata: { kind: 'prototype' },
|
|
}))).toBe('default');
|
|
});
|
|
});
|
|
|
|
describe('isPublishedDesignSystemProject', () => {
|
|
const dsProject = project({
|
|
metadata: { kind: 'other', importedFrom: 'design-system' },
|
|
designSystemId: 'user:stackme',
|
|
});
|
|
const brandProject = project({
|
|
metadata: {
|
|
kind: 'brand',
|
|
importedFrom: 'brand-extraction',
|
|
brandDesignSystemId: 'user:stackme',
|
|
},
|
|
});
|
|
|
|
it('is true when the backing design system is published, even if the run failed', () => {
|
|
expect(isPublishedDesignSystemProject(dsProject, [system({ status: 'published' })])).toBe(true);
|
|
expect(isPublishedDesignSystemProject(brandProject, [system({ status: 'published' })])).toBe(true);
|
|
});
|
|
|
|
it('is false while the design system is still a draft', () => {
|
|
expect(isPublishedDesignSystemProject(dsProject, [system({ status: 'draft' })])).toBe(false);
|
|
});
|
|
|
|
it('is false for non-design-system projects and when the system is missing', () => {
|
|
expect(
|
|
isPublishedDesignSystemProject(project({ metadata: { kind: 'prototype' } }), [
|
|
system({ status: 'published' }),
|
|
]),
|
|
).toBe(false);
|
|
expect(isPublishedDesignSystemProject(dsProject, [])).toBe(false);
|
|
});
|
|
});
|