Skip to content

Commit

Permalink
Update DocsContext tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Mar 5, 2023
1 parent ade8805 commit 47efd80
Showing 1 changed file with 61 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ describe('resolveOf', () => {
const { story, csfFile, storyExport, metaExport, moduleExports, component } = csfFileParts();

describe('attached', () => {
const projectAnnotations = { render: jest.fn() };
const store = {
componentStoriesFromCSFFile: () => [story],
projectAnnotations,
} as unknown as StoryStore<Renderer>;
const context = new DocsContext(channel, store, renderStoryToElement, [csfFile]);
context.attachCSFFile(csfFile);
Expand All @@ -47,27 +49,47 @@ describe('resolveOf', () => {
});

it('works for meta exports', () => {
expect(context.resolveOf(metaExport)).toEqual({ type: 'meta', csfFile });
expect(context.resolveOf(metaExport)).toEqual({
type: 'meta',
csfFile,
preparedMeta: expect.any(Object),
});
});

it('works for full module exports', () => {
expect(context.resolveOf(moduleExports)).toEqual({ type: 'meta', csfFile });
expect(context.resolveOf(moduleExports)).toEqual({
type: 'meta',
csfFile,
preparedMeta: expect.any(Object),
});
});

it('works for components', () => {
expect(context.resolveOf(component)).toEqual({ type: 'component', component });
expect(context.resolveOf(component)).toEqual({
type: 'component',
component,
projectAnnotations: expect.objectContaining(projectAnnotations),
});
});

it('finds primary story', () => {
expect(context.resolveOf('story')).toEqual({ type: 'story', story });
});

it('finds attached CSF file', () => {
expect(context.resolveOf('meta')).toEqual({ type: 'meta', csfFile });
expect(context.resolveOf('meta')).toEqual({
type: 'meta',
csfFile,
preparedMeta: expect.any(Object),
});
});

it('finds attached component', () => {
expect(context.resolveOf('component')).toEqual({ type: 'component', component });
expect(context.resolveOf('component')).toEqual({
type: 'component',
component,
projectAnnotations: expect.objectContaining(projectAnnotations),
});
});

describe('validation allowed', () => {
Expand All @@ -76,17 +98,26 @@ describe('resolveOf', () => {
});

it('works for meta exports', () => {
expect(context.resolveOf(metaExport, ['meta'])).toEqual({ type: 'meta', csfFile });
expect(context.resolveOf(metaExport, ['meta'])).toEqual({
type: 'meta',
csfFile,
preparedMeta: expect.any(Object),
});
});

it('works for full module exports', () => {
expect(context.resolveOf(moduleExports, ['meta'])).toEqual({ type: 'meta', csfFile });
expect(context.resolveOf(moduleExports, ['meta'])).toEqual({
type: 'meta',
csfFile,
preparedMeta: expect.any(Object),
});
});

it('works for components', () => {
expect(context.resolveOf(component, ['component'])).toEqual({
type: 'component',
component,
projectAnnotations: expect.objectContaining(projectAnnotations),
});
});

Expand All @@ -95,13 +126,18 @@ describe('resolveOf', () => {
});

it('finds attached CSF file', () => {
expect(context.resolveOf('meta', ['meta'])).toEqual({ type: 'meta', csfFile });
expect(context.resolveOf('meta', ['meta'])).toEqual({
type: 'meta',
csfFile,
preparedMeta: expect.any(Object),
});
});

it('finds attached component', () => {
expect(context.resolveOf('component', ['component'])).toEqual({
type: 'component',
component,
projectAnnotations: expect.objectContaining(projectAnnotations),
});
});
});
Expand Down Expand Up @@ -140,8 +176,10 @@ describe('resolveOf', () => {
});

describe('unattached', () => {
const projectAnnotations = { render: jest.fn() };
const store = {
componentStoriesFromCSFFile: () => [story],
projectAnnotations,
} as unknown as StoryStore<Renderer>;
const context = new DocsContext(channel, store, renderStoryToElement, [csfFile]);

Expand All @@ -150,15 +188,27 @@ describe('resolveOf', () => {
});

it('works for meta exports', () => {
expect(context.resolveOf(metaExport)).toEqual({ type: 'meta', csfFile });
expect(context.resolveOf(metaExport)).toEqual({
type: 'meta',
csfFile,
preparedMeta: expect.any(Object),
});
});

it('works for full module exports', () => {
expect(context.resolveOf(moduleExports)).toEqual({ type: 'meta', csfFile });
expect(context.resolveOf(moduleExports)).toEqual({
type: 'meta',
csfFile,
preparedMeta: expect.any(Object),
});
});

it('works for components', () => {
expect(context.resolveOf(component)).toEqual({ type: 'component', component });
expect(context.resolveOf(component)).toEqual({
type: 'component',
component,
projectAnnotations: expect.objectContaining(projectAnnotations),
});
});

it('throws for primary story', () => {
Expand Down

0 comments on commit 47efd80

Please sign in to comment.