import React from 'react';
import { shallow } from 'enzyme';

import StagingFeed from '.';

describe('StagingFeed', () => {
  it('displays the empty <StagingFeed> if deployed', () => {
    const node = shallow(<StagingFeed displayingDeployed={true} timelineContent={[]} />);
    expect(node.hasClass('StagingFeed')).toBe(true);
    expect(node.find('.StagingFeed-Timeline-Day-Deployed_empty')).toHaveLength(1);
  });

  it('displays the <StagingFeed> with data if not deployed', () => {
    const auditlog5 = {
      _id: '5e21da2127e2fd0481892f16',
      project: 'ixon-api',
      createdAt: '2020-01-17T16:00:33.531Z',
      filter: {
        action: 'DELETE',
        version: '1.0',
        user: 'Willem Hofmans\nsupport@ixon.cloud',
        project: 'IXON-API',
      },
      description: 'Deleted \n API setting "5e21da1131b38d0703798495" for "IXON-API"',
      __v: 0,
    };
    const changelog2 = {
      _id: '5f0cddddc53967004d2fad39',
      link: 'https://docs.readme.com/guides/changelog/2020-07-13-v3-5-0', // must generate on the backend
      metadata: {
        image: [],
        title: '',
        description: '',
      },
      title: 'Owlet Weekly Update (Week of July 13)',
      slug: '2020-07-13-v3-5-0',
      body:
        "> 🎉\n> Welcome to another update!\n> We have exciting news to share.\n> This week, we updated the [ReadMe API](https://docs.readme.com/developers/reference/intro)\n> To include poems with every err'!\n\nAlas, I'm not nearly as good at writing poems as Greg (our CEO) is — who literally wrote over 30 unique poems for each and every error code that is returned from the [ReadMe HTTP API](https://docs.readme.com/developers/reference/intro)! 🖋️\n\nIn other non-poetry-related (but nevertheless exciting) news, we also shipped some exciting updates to our icons, made a ton of usability improvements to our GitHub integration, and lots more. More information below! :owlbert-reading:\n\n## ✨",
      type: 'added',
      hidden: false,
      pendingAlgoliaPublish: false,
      user: '560efaf7a8e6680d00b2e3f9',
      createdAt: '2020-07-14T22:19:00.000Z',
      project: '542334961972e21d7dae4e00',
      __v: 0,
    };
    const timelineContent = [
      {
        date: new Date('2020-07-19'),
        changelogs: [changelog2], // can come from multiple projects
        auditlogs: [auditlog5],
      },
    ];
    const node = shallow(<StagingFeed displayingDeployed={false} timelineContent={timelineContent} />);
    expect(node.find('.StagingFeed-Timeline-Day-Log_AuditLog')).toHaveLength(1);
    expect(node.find('.StagingFeed-Timeline-Day-Log_Owlet')).toHaveLength(1);
    expect(node.find('.StagingFeed-Timeline-Day')).toHaveLength(1);
  });

  it('displays the <StagingFeed> with data if deployed', () => {
    const auditlog5 = {
      _id: '5e21da2127e2fd0481892f16',
      project: 'ixon-api',
      createdAt: '2020-01-17T16:00:33.531Z',
      filter: {
        action: 'DELETE',
        version: '1.0',
        user: 'Willem Hofmans\nsupport@ixon.cloud',
        project: 'IXON-API',
      },
      description: 'Deleted \n API setting "5e21da1131b38d0703798495" for "IXON-API"',
      __v: 0,
    };
    const changelog2 = {
      _id: '5f0cddddc53967004d2fad39',
      link: 'https://docs.readme.com/guides/changelog/2020-07-13-v3-5-0', // must generate on the backend
      metadata: {
        image: [],
        title: '',
        description: '',
      },
      title: 'Owlet Weekly Update (Week of July 13)',
      slug: '2020-07-13-v3-5-0',
      body:
        "> 🎉\n> Welcome to another update!\n> We have exciting news to share.\n> This week, we updated the [ReadMe API](https://docs.readme.com/developers/reference/intro)\n> To include poems with every err'!\n\nAlas, I'm not nearly as good at writing poems as Greg (our CEO) is — who literally wrote over 30 unique poems for each and every error code that is returned from the [ReadMe HTTP API](https://docs.readme.com/developers/reference/intro)! 🖋️\n\nIn other non-poetry-related (but nevertheless exciting) news, we also shipped some exciting updates to our icons, made a ton of usability improvements to our GitHub integration, and lots more. More information below! :owlbert-reading:\n\n## ✨",
      type: 'added',
      hidden: false,
      pendingAlgoliaPublish: false,
      user: '560efaf7a8e6680d00b2e3f9',
      createdAt: '2020-07-14T22:19:00.000Z',
      project: '542334961972e21d7dae4e00',
      __v: 0,
    };
    const timelineContent = [
      {
        date: new Date('2020-07-19'),
        changelogs: [changelog2], // can come from multiple projects
        auditlogs: [auditlog5],
      },
    ];
    const node = shallow(<StagingFeed displayingDeployed={true} timelineContent={timelineContent} />);
    expect(node.hasClass('StagingFeed_deployed')).toBe(true);
    expect(node.find('.StagingFeed-Timeline-Day-Log_AuditLog')).toHaveLength(1);
    expect(node.find('.StagingFeed-Timeline-Day-Log_Owlet')).toHaveLength(1);
    expect(node.find('.StagingFeed-Timeline-Day')).toHaveLength(1);
  });
});
