Skip to content

Commit

Permalink
test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mschile committed Dec 20, 2024
1 parent 3d0744c commit 2057168
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 47 deletions.
41 changes: 1 addition & 40 deletions packages/app/cypress/component/support/ctSupport.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { AutIframe } from '../../../src/runner/aut-iframe'
import { EventManager } from '../../../src/runner/event-manager'
import '../../e2e/support/browserIconCommands'
import type { Socket } from '@packages/socket/lib/browser'

declare global {
namespace Cypress {
interface Chainable {
verifyBrowserIconSvg(
expectedSvgData: string
): Chainable<JQuery<HTMLElement>>
}
}
}

export const StubWebsocket = new Proxy<Socket>(Object.create(null), {
get: (obj, prop) => {
throw Error(`Cannot access ${String(prop)} on StubWebsocket!`)
Expand Down Expand Up @@ -59,33 +50,3 @@ export const createTestAutIframe = (eventManager = createEventManager()) => {
null, // CypressJQuery, shouldn't be using driver in component tests anyway
)
}

function verifyBrowserIconSvg (
subject: JQuery<HTMLElement>,
expectedSvgData: string,
) {
cy.then(() => {
let actualSvgData = ''

subject.each((_, el) => {
actualSvgData += el.outerHTML
})

const actualNormalizedSvgData = actualSvgData
.replaceAll('></path>', '/>')
.replaceAll('></circle>', '/>')
.replace(/<title>.*<\/title>/, '')

const expectedNormalizedSvgData = expectedSvgData.replace(/<defs>.*<\/defs>/, '')

expect(actualNormalizedSvgData).to.equal(expectedNormalizedSvgData)

return subject
})
}

Cypress.Commands.add(
'verifyBrowserIconSvg',
{ prevSubject: true },
verifyBrowserIconSvg,
)
41 changes: 41 additions & 0 deletions packages/app/cypress/e2e/support/browserIconCommands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
declare global {
namespace Cypress {
interface Chainable {
verifyBrowserIconSvg(
expectedSvgData: string
): Chainable<JQuery<HTMLElement>>
}
}
}

function verifyBrowserIconSvg (
subject: JQuery<HTMLElement>,
expectedSvgData: string,
) {
cy.then(() => {
let actualSvgData = ''

subject.each((_, el) => {
actualSvgData += el.outerHTML
})

const actualNormalizedSvgData = actualSvgData
.replaceAll('></path>', '/>')
.replaceAll('></circle>', '/>')
.replace(/<title>.*<\/title>/, '')

const expectedNormalizedSvgData = expectedSvgData.replace(/<defs>.*<\/defs>/, '')

expect(actualNormalizedSvgData).to.equal(expectedNormalizedSvgData)

return subject
})
}

Cypress.Commands.add(
'verifyBrowserIconSvg',
{ prevSubject: true },
verifyBrowserIconSvg,
)

export {}
5 changes: 3 additions & 2 deletions packages/app/cypress/e2e/support/e2eSupport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '@packages/frontend-shared/cypress/support/e2e'
import './browserIconCommands'
import 'cypress-real-events/support'
import './execute-spec'

Expand All @@ -20,15 +21,15 @@ beforeEach(() => {
function e2eTestingTypeIsSelected () {
cy.findByTestId('specs-testing-type-header').within(() => {
cy.findByTestId('testing-type-switch').contains('button', 'E2E').should('have.attr', 'aria-selected', 'true')
cy.findByTestId('testing-type-switch').contains('button', 'Component').should('not.have.attr', 'aria-selected')
cy.findByTestId('testing-type-switch').contains('button', 'Component').should('have.attr', 'aria-selected', 'false')
})
}

Cypress.Commands.add('verifyE2ESelected', e2eTestingTypeIsSelected)

function ctTestingTypeIsSelected () {
cy.findByTestId('specs-testing-type-header').within(() => {
cy.findByTestId('testing-type-switch').contains('button', 'E2E').should('not.have.attr', 'aria-selected')
cy.findByTestId('testing-type-switch').contains('button', 'E2E').should('have.attr', 'aria-selected', 'false')
cy.findByTestId('testing-type-switch').contains('button', 'Component').should('have.attr', 'aria-selected', 'true')
})
}
Expand Down
12 changes: 7 additions & 5 deletions packages/app/cypress/e2e/top-nav.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'
import { CYPRESS_REMOTE_MANIFEST_URL, NPM_CYPRESS_REGISTRY_URL } from '@packages/types'
import type Sinon from 'sinon'
import { dayjs } from '../../src/runs/utils/day'
import { cyBrowserMozillaFirefoxX16, cyBrowserChromeX16 } from '@cypress-design/icon-registry'

const pkg = require('@packages/root')

Expand Down Expand Up @@ -40,9 +41,9 @@ describe('App Top Nav Workflows', () => {
cy.visitApp()
cy.specsPageIsVisible()

cy.findByTestId('top-nav-active-browser-icon')
.should('have.attr', 'src')
.and('contain', 'firefox')
cy.findByTestId('top-nav-active-browser-icon').children()
.verifyBrowserIconSvg(cyBrowserMozillaFirefoxX16.data)
.get('title').should('contain', 'Firefox')

cy.findByTestId('top-nav-active-browser').should('contain', 'Firefox 6')
})
Expand All @@ -63,8 +64,9 @@ describe('App Top Nav Workflows', () => {
})

it('shows the current browser in the top nav browser list button', () => {
cy.findByTestId('top-nav-active-browser-icon')
.should('have.attr', 'src')
cy.findByTestId('top-nav-active-browser-icon').children()
.verifyBrowserIconSvg(cyBrowserChromeX16.data)
.get('title').should('contain', 'Chrome')

cy.findByTestId('top-nav-active-browser').should('contain', 'Chrome 1')
})
Expand Down

0 comments on commit 2057168

Please sign in to comment.