{"size": 1735, "ext": "js", "max_stars_repo_path": "lib/component-data/template.test.js", "max_stars_repo_name": "slategroup/clay-kiln", "max_stars_repo_stars_event_min_datetime": "2017-12-12T13:30:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-14T14:29:00.000Z", "max_issues_repo_path": "lib/component-data/template.test.js", "max_issues_repo_name": "slategroup/clay-kiln", "max_issues_repo_issues_event_min_datetime": "2017-05-16T18:05:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T19:38:21.000Z", "max_forks_repo_path": "lib/component-data/template.test.js", "max_forks_repo_name": "slategroup/clay-kiln", "max_forks_repo_forks_event_min_datetime": "2017-06-08T21:04:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-11T17:34:09.000Z"}
{"max_stars_count": 24, "max_issues_count": 545, "max_forks_count": 23, "avg_line_length": 33.3653846154, "max_line_length": 135, "alphanum_fraction": 0.5492795389}
import * as components from '../core-data/components';
import * as lib from './template';

jest.mock('../core-data/components');

describe('component template', () => {
  beforeEach(() => {
    components.getTemplate.mockReturnValue(data => `hi ${data.locals.edit} ${data.text} (${data._ref}) (${data.componentVariation})!`);
    components.getLocals.mockReturnValue({ edit: true });
  });

  describe('compose', () => {
    const fn = lib.compose;

    test('gets data for leaf components', () => {
      expect(fn('foo', { a: 'b' })).toEqual({ a: 'b' });
    });

    test('gets data for branch components', () => {
      components.getData.mockReturnValue({ a: 'b' });
      expect(fn('foo', { child: { _ref: 'bar' }, c: 'd' })).toEqual({ child: { _ref: 'bar', a: 'b' }, c: 'd' });
    });

    test('throws error if child does not exist in store', () => {
      components.getData.mockReturnValue(undefined);
      expect(() => fn('foo', { child: { _ref: 'bar' } })).toThrow(Error);
    });
  });

  describe('render', () => {
    const fn = lib.render;

    test('renders with data and locals', () => {
      fn('foo', { _ref: 'foo', text: 'friend', componentVariation: 'foo_bar' }).then((res) => {
        expect(res.wholeText).toBe('hi true friend (foo) (foo_bar)!');
      });
    });

    test('adds _ref if not passed in', () => {
      fn('foo', { text: 'friend', componentVariation: 'foo_bar' }).then((res) => {
        expect(res.wholeText).toBe('hi true friend (foo) (foo_bar)!');
      });
    });

    test('adds componentVariation if not passed in', () => {
      fn('foo', { _ref: 'foo', text: 'friend' }).then((res) => {
        expect(res.wholeText).toBe('hi true friend (foo) (foo)!');
      });
    });
  });
});
