Skip to content

Commit

Permalink
cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Mar 23, 2023
1 parent 1ecf949 commit 956d617
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
57 changes: 26 additions & 31 deletions cypress/e2e/main-page.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ import { registerCommand } from 'cypress-wait-for-stable-dom'

registerCommand()

describe('Main page', function () {
describe('Frontend', function () {
const backendUrl = Cypress.env('backend_url')
const SEARCH_INPUT = 'input[placeholder="search"]'

function expectBadgeExample(title, previewUrl, pattern) {
cy.contains('tr', `${title}:`).find('code').should('have.text', pattern)
cy.contains('tr', `${title}:`)
.find('img')
.should('have.attr', 'src', previewUrl)
}
const SEARCH_INPUT = 'input[placeholder="Search"]'

function visitAndWait(page) {
cy.visit(page)
Expand All @@ -26,36 +19,38 @@ describe('Main page', function () {
cy.contains('PyPI - License')
})

it('Shows badge from category', function () {
visitAndWait('/category/chat')
it('Shows badges from category', function () {
visitAndWait('/badges')

cy.contains('Build')
cy.contains('Chat').click()

expectBadgeExample(
'Discourse status',
'http://localhost:8080/badge/discourse-online-brightgreen',
'/discourse/status?server=https%3A%2F%2Fmeta.discourse.org'
)
cy.contains('Discourse status')
cy.contains('Stack Exchange questions')
})

it('Customizate badges', function () {
visitAndWait('/')
it('Shows expected code examples', function () {
visitAndWait('/badges/static-badge')

cy.get(SEARCH_INPUT).type('issues')
cy.contains('button', 'URL').should('have.class', 'api-code-tab')
cy.contains('button', 'Markdown').should('have.class', 'api-code-tab')
cy.contains('button', 'rSt').should('have.class', 'api-code-tab')
cy.contains('button', 'AsciiDoc').should('have.class', 'api-code-tab')
cy.contains('button', 'HTML').should('have.class', 'api-code-tab')
})

cy.contains('/github/issues/:user/:repo').click()
it('Build a badge', function () {
visitAndWait('/badges/git-hub-issues')

cy.get('input[name="user"]').type('badges')
cy.get('input[name="repo"]').type('shields')
cy.get('table input[name="color"]').type('orange')
cy.contains('/github/issues/:user/:repo')

cy.get(`img[src='${backendUrl}/github/issues/badges/shields?color=orange']`)
})
cy.get('input[placeholder="user"]').type('badges')
cy.get('input[placeholder="repo"]').type('shields')

it('Do not duplicate example parameters', function () {
visitAndWait('/category/funding')
cy.contains('Execute').click()

cy.contains('GitHub Sponsors').click()
cy.get('[name="style"]').should($style => {
expect($style).to.have.length(1)
})
cy.intercept('GET', `${backendUrl}/github/issues/badges/shields`).as('get')
cy.wait('@get').its('response.statusCode').should('eq', 200)
cy.get('img[id="badge-preview"]')
})
})
5 changes: 4 additions & 1 deletion frontend/src/theme/ApiDemoPanel/Response/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ function Response() {
return (
<FloatingButton label="Clear" onClick={() => dispatch(clearResponse())}>
{(response.startsWith('<svg ') && (
<img src={`data:image/svg+xml;utf8,${encodeURIComponent(response)}`} />
<img
id="badge-preview"
src={`data:image/svg+xml;utf8,${encodeURIComponent(response)}`}
/>
)) || (
<pre
style={{
Expand Down

0 comments on commit 956d617

Please sign in to comment.