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

describe('Add Room Page', () => {
  const MeQuery = getMinimalMe();
  const operations = {
    MeQuery,
    AddRoomEntry: {
      addRoomEntry: {
        roomEntry: {},
      },
    },
    RoomEntriesQuery: {
      room: {
        roomEntries: {
          edges: [
            {
              node: {
                id: 1,
                slug: 'hello',
                title: 'A Room Entry',
                comments: [],
                author: {
                  id: MeQuery.me.id,
                },
              },
            },
          ],
        },
      },
    },
  };

  beforeEach(() => {
    cy.setup();
    cy.mockGraphqlOps({
      operations,
    });
  });

  it('visits the page and fills out the form', () => {
    // go to /room/some-room/add
    cy.visit('/room/some-room/add');

    // element with data-cy 'content-form-section-title' should have the text 'Titel (Pflichtfeld)'
    // focus the input with data-cy 'input-with-label-input' and type 'Raumtitel'
    cy.getByDataCy('content-form-section-title').should('have.text', 'Titel (Pflichtfeld)');
    cy.getByDataCy('input-with-label-input').type('Raumtitel');

    // click on first element with data-cy 'add-content-link'
    cy.getByDataCy('add-content-link').click();
    cy.getByDataCy('choose-text-widget').click();
    cy.get('.tip-tap__editor').type('Hello');

    cy.getByDataCy('save-button').click();
  });
});
