import { LOGBOOK_CONTAINER_CONTEXT } from '../../../constants/eventTypes';
import { goodComment1, goodComment4 } from '../../GoodEventLibrary';
import { createEventByAttributes } from '../../helpers';

module.exports = {
  renderinglinkToEditEvent: [
    {
      description: 'logbook is not public; event has no previous version',
      event: goodComment1,
      logbookContext: { name: LOGBOOK_CONTAINER_CONTEXT, isReleased: false },
      expected: 'pencil',
    },
    {
      description: 'logbook is not public; event has one previous version',
      event: goodComment4,
      logbookContext: { name: LOGBOOK_CONTAINER_CONTEXT, isReleased: false },
      expected: 'pencil',
    },
    {
      description: 'logbook is public',
      event: goodComment4,
      logbookContext: { name: LOGBOOK_CONTAINER_CONTEXT, isReleased: true },
      expected: 'eye-open',
    },
  ],

  renderingEvent: [
    {
      description: 'Annotation, User comment, no previous version',
      event: createEventByAttributes({
        type: 'annotation',
        category: 'comment',
        content: [
          { format: 'plainText', text: 'a comment' },
          { format: 'html', text: '<p> a comment </p>' },
        ],
      }),
      expected: {
        texts: ['<p> a comment </p>'],
      },
    },
    {
      description: 'Annotation, User comment, no previous version, lazyloaded',
      event: createEventByAttributes({
        type: 'annotation',
        category: 'comment',
        content: [
          { format: 'plainText', text: 'a comment' },
          {
            format: 'html',
            text:
              '<p> a comment  <img src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7"/> </p>',
          },
        ],
      }),
      expected: {
        texts: [
          '<p> a comment  <img onClick=\'makeFullScreen(this)\'   style="height:200px;width:auto;cursor:zoom-in;" src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7"/> </p>',
        ],
      },
    },
    {
      description:
        'Annotation, User comment, with previous version, lazyloaded',
      event: createEventByAttributes({
        type: 'annotation',
        category: 'comment',
        content: [
          { format: 'plainText', text: 'an updated comment' },
          {
            format: 'html',
            text:
              '<p> an updated comment  <img src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7"/> </p>',
          },
        ],
        previousVersionEvent: createEventByAttributes({
          type: 'annotation',
          category: 'comment',
          content: [
            { format: 'plainText', text: 'a comment' },
            {
              format: 'html',
              text:
                '<p> a comment  <img src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7"/> </p>',
            },
          ],
        }),
      }),
      expected: {
        texts: [
          '<p> an updated comment  <img onClick=\'makeFullScreen(this)\'   style="height:200px;width:auto;cursor:zoom-in;" src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7"/> </p>',
        ],
      },
    },
    {
      description:
        'Annotation, User comment, no previous version, no html format',
      event: createEventByAttributes({
        type: 'annotation',
        category: 'comment',
        content: [{ format: 'plainText', text: 'a comment' }],
      }),
      expected: {
        texts: ['a comment'],
      },
    },
  ]
    .concat(getNotificationResourcesByCategory('info'))
    .concat(getNotificationResourcesByCategory('error'))
    .concat(getNotificationResourcesByCategory('debug'))
    .concat(getNotificationResourcesByCategory('commandline'))
    .concat(getNotificationResourcesByCategory('commandLine'))
    .concat(getNotificationResourcesByCategory('comment')),
};

/** Helper function for the renderingEvent test which returns resources for this test */
function getNotificationResourcesByCategory(category) {
  return [
    {
      description: `Notification, ${category}, no comment`,
      event: createEventByAttributes({
        type: 'notification',
        category,
        content: [
          { format: 'plainText', text: 'originalText' },
          { format: 'html', text: '<p> originalText </p>' },
        ],
      }),
      expected: {
        texts: ['originalText'],
      },
    },
    {
      description: `Notification, ${category}, commented`,
      event: createEventByAttributes({
        type: 'notification',
        category,
        content: [
          { format: 'plainText', text: 'a comment' },
          { format: 'html', text: '<p> a comment</p>' },
        ],
        previousVersionEvent: createEventByAttributes({
          type: 'notification',
          category,
          content: [
            { format: 'plainText', text: 'originalText' },
            { format: 'html', text: '<p> originalText </p>' },
          ],
        }),
      }),
      expected: {
        texts: ['originalText', '<p> a comment</p>'],
      },
    },
    {
      description: `Notification, ${category}, commented, lazyloaded`,
      event: createEventByAttributes({
        type: 'notification',
        category,
        content: [
          { format: 'plainText', text: 'a comment' },
          {
            format: 'html',
            text:
              '<p> a comment <img src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7"/> </p>',
          },
        ],
        previousVersionEvent: createEventByAttributes({
          type: 'notification',
          category,
          content: [
            { format: 'plainText', text: 'originalText' },
            { format: 'html', text: '<p> originalText </p>' },
          ],
        }),
      }),
      expected: {
        texts: [
          'originalText',
          '<p> a comment <img onClick=\'makeFullScreen(this)\'   style="height:200px;width:auto;cursor:zoom-in;" src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7"/> </p>',
        ],
      },
    },
  ];
}
