const plantName = 'Tomato'

Cypress._.times(1, () => {
  describe('Manage plots', () => {

    beforeEach(() => {
      cy.visit('/')
    })

    describe(`An unauthenticated user`, () => {
      // Fails and requires a fix.
      it(`Can see the plots`, () => {
        cy.getByData('plot').should('exist')
      })

      it(`Can filter the plots, when all filters are turned of, all plots must be hidden.`, () => {
        cy.getByData('plot').should('exist').its('length').should('be.gt', 0)
        cy.getByData('planted-filter').should('exist').click()
        cy.getByData('trimmed-filter').should('exist').click()
        cy.getByData('harvested-filter').should('exist').click()
        cy.getByData('plot').should('not.exist')
      })
    })

    describe(`An authenticated user`, () => {

      beforeEach(() => {
        cy.createTestAccount()
        cy.login()
        cy.visit('/')
      })

      afterEach(() => {
        cy.deleteTestAccount()
      })

      it(`Cannot create a plot with an empty plant name.`, () => {
        // Fails and requires a fix.
        cy.getByData('plot').its('length').then(oldLength => {
            cy.getByData('create-plot').click()
            cy.getByData('plot').should('have.length', oldLength)
        })
      })

      it(`Can create a new plot with a valid plant name.`, () => {
        cy.getByData('plant-name').type(plantName)
        cy.getByData('create-plot').click()
        cy.getByData('plot').should('contain', plantName)
      })
    })
  })

})
