Qiskit / platypus

Qiskit Textbook (beta)
https://learn.qiskit.org
Apache License 2.0
142 stars 249 forks source link

Grader: Add tests to CodeExercise cells #750

Closed korgan00 closed 9 months ago

korgan00 commented 2 years ago

The old code-cell has some tests that are deprecated and deleted from the current implementation (CodeExercise widget). We should add testing to this widget and

For reference the old test code was:

cypress/integration/code-mirror/copy-code-to-clipboard.spec.js

/// <reference types="cypress" />

describe('Copy code to clipboard', () => {
  beforeEach(() => {
    cy.viewport('macbook-15').visit('/course/examples/blocks')
  })

  it('displays only the copy icon', () => {
    cy.get('#code-mirror-element-0').should('be.hidden')
    cy.get('.copy-icon').should('be.visible')
    cy.get('.code-mirror-clipboard-copy .label').should('have.css', 'opacity', '0')
  })

  it('can focus the copy button', () => {
    cy.get('.code-mirror-clipboard-copy').first().focus()
    cy.get('.code-mirror-clipboard-copy .label').contains('Copy')
  })

  it('copies code to clipboard', () => {
    cy.get('.code-mirror-clipboard-copy').click()
    cy.get('.code-mirror-clipboard-copy .label').contains('Copied!')

    // TODO: Check the clipboard's content (for single and multiple lines of
    // code copied).
    // https://github.com/Qiskit/platypus/issues/96
  })
})

cypress/integration/code-mirror/copy-code-to-clipboard.spec.js

/// <reference types="cypress" />

describe('Code cell', () => {
  beforeEach(() => {
    cy.viewport('macbook-15').visit('/course/examples/blocks')
  })

  it('is displayed', () => {
    cy.get('[data-test=code-cell]').should('be.visible')
    cy.get('[data-test=code-cell-input]').contains('1 + 1')
    cy.get('[data-test=code-cell-output]').contains('2')
    cy.get('[data-test=code-cell-button-run]').contains('Run')
  })

  it('runs', () => {
    cy.get('[data-test=code-cell-code]')
      .click()
      .type('{backspace}{backspace}{backspace}{backspace}{backspace}2+3')
    cy.get('[data-test=code-cell-input]').contains('2+3')
    cy.get('[data-test=code-cell-button-run]').click()
    cy.get('[data-test=code-cell-output]').contains('Waiting for kernel...')
  })
})
vabarbosa commented 9 months ago

This repository is no longer maintained. It has been superseded by IBM Quantum Learning.