{"size": 1210, "ext": "js", "max_stars_repo_path": "cypress/integration/pagination-spec.js", "max_stars_repo_name": "Omar97perez/cypress-example-realworld", "max_stars_repo_stars_event_min_datetime": "2020-06-12T14:18:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T23:37:21.000Z", "max_issues_repo_path": "cypress/integration/pagination-spec.js", "max_issues_repo_name": "Omar97perez/cypress-example-realworld", "max_issues_repo_issues_event_min_datetime": "2019-06-28T13:09:15.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-08T20:45:38.000Z", "max_forks_repo_path": "cypress/integration/pagination-spec.js", "max_forks_repo_name": "Omar97perez/cypress-example-realworld", "max_forks_repo_forks_event_min_datetime": "2020-06-12T16:04:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-22T05:49:11.000Z"}
{"max_stars_count": 60, "max_issues_count": 244, "max_forks_count": 30, "avg_line_length": 25.7446808511, "max_line_length": 48, "alphanum_fraction": 0.5487603306}
/// <reference types="Cypress" />

describe('Pagination', () => {
  beforeEach(() => {
    cy.task('cleanDatabase')
    cy.registerUserIfNeeded()
    cy.login()
  })

  it('shows pagination', () => {
    Cypress._.times(20, k =>
      cy.postArticle({
        title: `post ${k + 1}`,
        description: 'description',
        body: 'article',
        tagList: []
      })
    )
    cy.get('[data-cy=global-feed]').click()
    // only the last 10 articles should be shown
    cy.get('.article-preview')
      .should('have.length', 10)
      .contains('.article-preview', 'post 20')

    // the pagination controls should be visible
    cy.get('.pagination').should('be.visible')
    cy.get('[data-cy=page-link]')
      .should('have.length', 2)
      .first()
      .parent()
      .should('have.class', 'active')
    cy.get('[data-cy=page-link]')
      .should('have.length', 2)
      .eq(1)
      .parent()
      .should('not.have.class', 'active')
    cy.log('going to second page')
    cy.get('[data-cy=page-link]')
      .eq(1)
      .click()
    // very first article should be there
    cy.get('.article-preview')
      .should('have.length', 10)
      .contains('.article-preview', 'post 1')
  })
})
