text: // NOTE(HashimotoYT): TypeScript declarations support for vscode. Feel free to remove this.
  /// <reference path="../../node_modules/cypress/types/index.d.ts" />
  
  const localhost = 'http://localhost:5000'
  
  /**
   * Visit the localhost page.
   *
   * @param {string} nextUrl url who need to visit, optional.
   */
  function visit(nextUrl) {
    if (nextUrl) cy.visit(`${localhost}/${nextUrl}`)
    else cy.visit(`${localhost}`)
  }
  
  describe('electronjs.org', () => {
    it('works', () => {
      cy.visit(localhost)
      cy.title().should('include', 'Build cross-platform desktop apps')
    })
  
    describe('apps page', () => {
      it('search apps', () => {
        cy.visit(localhost)
  
        // Apps page
        cy.get('a[href="/apps"]:first').click()
        cy.get('.app-list').should('contain', 'gitmoji')
  
        // Search specific app
        cy.get('#apps-filter').type('tusk')
        cy.wait(500)
        cy.get('.app-list').should('contain', 'Tusk')
        cy.get('.app-list').should('not.contain', 'gitmoji')
  
        cy.get('#apps-filter').clear()
  
        // Search not one specific app
        cy.get('#apps-filter').type('desktop')
        cy.wait(500)
        cy.get('.app-list').should('contain', 'GitHub Desktop')
      })
  
      it('shows downloads section for apps that have downloadable files', () => {
        cy.visit('http://localhost:5000/apps/dat')
        cy.get('.app-meta-entry-downloads').should('be.visible')
      })
  
      it('hides downloads section for apps with no downloadable files', () => {
        cy.visit('http://localhost:5000/apps/protegopdf')
        cy.wait(500)
        cy.get('.app-meta-entry-downloads').should('not.be.visible')
      })
  
      it('install command displayed for npmjs apps', () => {
        cy.visit(`${localhost}/apps/timeseriesadmin`)
        cy.wait(500)
        cy.get('.app-meta-entry .shell-one-liner').contains('npm install -g')
      })
    })
  
    describe('documentation page', () => {
      xit('open docs page', () => {
        cy.visit(localhost)
        cy.get('a[href="/docs"]:first').click()
        cy.wait(500)
  
        cy.get('.container-lg').contains('Electron Documentation')
      })
  
      it('documentation page has guides, api references, and advanced sections', () => {
        cy.visit(`${localhost}/docs`)
        cy.wait(500)
        cy.get('a[href="/docs/tutorial"]').contains('Guides')
        cy.get('a[href="/docs/api"]').contains('API Reference')
        cy.get('a[href="/docs/development"]').contains('Advanced')
      })
    })
  
    describe('search', () => {
      before(() => {
        cy.visit(localhost)
      })
  
      beforeEach(() => {
        cy.get('.nav-search').clear()
      })
  
      xit('the results returned from searching match the results returned from each algolia index', () => {
        cy.get('.nav-search').type('window')
        cy.wait(500)
        let types = ['#tutorial-hits', '#api-hits', '#package-hits', '#app-hits']
        types.forEach((type) => {
          cy.get(type).should((typeHits) => {
            if (type.includes('tutorial'))
              expect(typeHits.first()).to.contain('Windows Taskbar')
            if (type.includes('api'))
              expect(typeHits.first()).to.contain('window-all-closed')
            if (type.includes('package'))
              expect(typeHits.first()).to.contain('about-window')
          })
        })
      })
  
      xit('highlights what is typed in the input', () => {
        cy.get('.nav-search').type('window')
        cy.wait(500)
        cy.get('.ais-hits--item em').contains('window')
        cy.get('.nav-search').clear()
        cy.get('.nav-search').type('electron')
        cy.wait(500)
        cy.get('.ais-hits--item em').contains('electron')
      })
  
      // it('filters for type when search is prepended with type:', () => {
      //   cy.get('.nav-search').type('app:')
      //   cy.wait(100)
      //   cy.get('#api-hits').should('not.be.visible')
      //   cy.get('#package-hits').should('not.be.visible')
      //   cy.get('#tutorial-hits').should('not.be.visible')
      // })
  
      // it('filters for type when search is prepended with is:type', () => {
      //   cy.get('.nav-search').type('is:app')
      //   cy.wait(100)
      //   cy.get('#api-hits').should('not.be.visible')
      //   cy.get('#package-hits').should('not.be.visible')
      //   cy.get('#tutorial-hits').should('not.be.visible')
      // })
    })
  
    // FIXME: doesn't seem to be working
    describe.skip('localization', () => {
      it('change language via language drop-down menu', () => {
        cy.visit(`${localhost}`)
        cy.wait(500)
        cy.get('.lang-select-button').click()
        cy.wait(200)
        cy.get('#languages-header-menu a[href="/languages/fr-FR"]:first').click()
        cy.wait(500)
        cy.get('.jumbotron-lead').contains(
          'Développez des applications desktop multi-plateformes avec JavaScript, HTML et CSS'
        )
      })
  
      it('change language via languages page', () => {
        cy.visit(`${localhost}/languages`)
        cy.get('.container-lg a[href="/languages/fr-FR"]:first').click()
        cy.visit(`${localhost}`)
        cy.wait(500)
        cy.get('.jumbotron-lead').contains(
          'Développez des applications desktop multi-plateformes avec JavaScript, HTML et CSS'
        )
      })
    })
  
    describe('header', () => {
      it('"Electron" hides on small displays (less 1300px)', () => {
        cy.visit(localhost)
        cy.get('.site-header-logo').not('.vertical-middle')
      })
  
      it('"Electron" contains on displays more 1300px', () => {
        // Set display resolution to 1600x900
        cy.viewport(1600, 900)
        cy.visit(localhost)
        cy.get('.site-header-logo').contains('Electron')
      })
    })
  
    describe('landing pages', () => {
      it('Fiddle landing page', () => {
        cy.visit(`${localhost}/fiddle`)
        cy.get('.jumbotron-lead').contains(
          'The easiest way to get started with Electron'
        )
      })
  
      it('Devtron landing page', () => {
        visit(`devtron`)
        cy.get('.jumbotron-lead').contains('An Electron DevTools Extension')
      })
  
      it('Spectron landing page', () => {
        visit(`spectron`)
        cy.get('.jumbotron-lead').contains('An Electron Testing Framework')
      })
    })
  
    describe('releases', () => {
      it('/releases/stable', () => {
        cy.visit(`${localhost}/releases/stable`)
        cy.get('.r-resp-header-narrow').contains('Stable Releases')
        cy.get('.release-entry').should('have.length', 5)
        cy.get('a.releases-link-stable').should('have.class', 'active')
      })
  
      it('responsive navbar', () => {
        cy.viewport('iphone-6', 'portrait')
        cy.visit(`${localhost}/releases/stable`)
        cy.get('#release-navbar').should('have.class', 'd-none')
        cy.get('.r-resp-header-toggle').should('be.visible').click()
  
        cy.get('#release-navbar').should('not.have.class', 'd-none')
        cy.get('#release-navbar > h1')
          .should('be.visible')
          .contains('Show Releases:')
      })
  
      // FIXME: expected '' to equal 301
      it('/docs/versions redirects to /releases/stable', async () => {
        cy.visit(`${localhost}/docs/versions`).then((res) => {
          expect(res.status).to.eq(301)
          expect(res.redirectedToUrl).to.eq(`${localhost}/releases/stable`)
        })
      })
    })
  
    /**
     * This section tests minor website bugs. Each test contains steps to reproducing
     * the bug, and should have comments indicating what the behaviour should be when
     * fixed.
     */
    describe('Buggy Tests', () => {
      it('language bar responsive bug', () => {
        visit()
        cy.get('.lang-select-button')
          .click()
          .get('#languages-header-menu')
          .should('have.css', 'height', '235px')
          .viewport('iphone-6')
          .wait(500)
          .get('#languages-header-menu')
          .should('have.css', 'height', '355px')
          .viewport(1920, 1080)
          // .get('#languages-header-menu').should('have.css', 'height', '235px') // FIXME: Uncomment when fixed.
          .get('#languages-header-menu')
          .should('have.css', 'height', '355px')
      })
    })
  })
  