import {getMinimalMe} from '../../../support/helpers';

describe('Article page', () => {
  const slug = 'this-article-has-a-slug';
  const roomEntry = {
        slug,
        id: 'room-entry-id',
        title: 'Some Room Entry, yay!',
        comments: {
          edges: [],
        },
      };

  const operations = {
    MeQuery: getMinimalMe({}),
    RoomEntryQuery: {
      roomEntry,
    },
    AddComment({input}) {
      return {
        addComment: {
          success: true,
          comment: {
            text: input.comment,
            roomEntry: roomEntry,
            owner: {
              firstName: 'Matt',
              lastName: 'Damon'
            }
          }
        }
      };
    }
  };

  beforeEach(() => {
    cy.setup();
  });

  it('goes to article and leaves a comment', () => {
    cy.mockGraphqlOps({
      operations,
    });

    const commentText = 'First! ';
    const emoji = '🖐';
    cy.visit(`/article/${slug}`);
    cy.getByDataCy('comment-textarea').type(commentText);
    cy.getByDataCy('emoji-button').should('have.length', 9).first().click();
    cy.getByDataCy('submit-comment').should('contain', 'Kommentar teilen').click();
    cy.getByDataCy('comment').first().should('contain', commentText + emoji);
  });
});
