import addons from '@storybook/addons';
import { withNotes } from '..';

jest.mock('@storybook/addons');

describe('Storybook Addon Notes', () => {
  it('should inject info', () => {
    const channel = { emit: jest.fn() };
    addons.getChannel.mockReturnValue(channel);

    const getStory = jest.fn();
    const context = {};

    const decoratedStory = withNotes('hello')(getStory);
    decoratedStory(context);
    expect(channel.emit).toHaveBeenCalledWith('storybook/notes/add_notes', 'hello');
    expect(getStory).toHaveBeenCalledWith(context);
  });
});

import addons from '@storybook/addons';
import { withNotes } from '..';

jest.mock('@storybook/addons');

describe('Storybook Addon Notes', () => {
  it('should inject text from `notes` parameter', () => {
    const channel = { emit: jest.fn() };
    addons.getChannel.mockReturnValue(channel);

    const getStory = jest.fn();
    const context = { parameters: { notes: 'hello' } };

    withNotes(getStory, context);
    expect(channel.emit).toHaveBeenCalledWith('storybook/notes/add_notes', 'hello');
    expect(getStory).toHaveBeenCalledWith(context);
  });

  it('should inject markdown from `notes.markdown` parameter', () => {
    const channel = { emit: jest.fn() };
    addons.getChannel.mockReturnValue(channel);

    const getStory = jest.fn();
    const context = { parameters: { notes: { markdown: '# hello' } } };

    withNotes(getStory, context);
    expect(channel.emit).toHaveBeenCalledWith(
      'storybook/notes/add_notes',
      expect.stringContaining('<h1 id="hello">hello</h1>')
    );
    expect(getStory).toHaveBeenCalledWith(context);
  });

  it('should inject info (deprecated API)', () => {
    const channel = { emit: jest.fn() };
    addons.getChannel.mockReturnValue(channel);

    const getStory = jest.fn();
    const context = { parameters: {} };

    const decoratedStory = withNotes('hello')(getStory);
    decoratedStory(context);
    expect(channel.emit).toHaveBeenCalledWith('storybook/notes/add_notes', 'hello');
    expect(getStory).toHaveBeenCalledWith(context);
  });
});

Update tests with new API
Update tests with new API
