Skip to content

Commit

Permalink
chore: fix visual test lib (#1325)
Browse files Browse the repository at this point in the history
* chore: fix visual test lib

* chore: update popups

* chore: adjust scrolling

* chore: adjust scrolling

* chore: change nav visuals

* chore: remove 400ms waits

* chore: remove scroll to top

* chore(): update base images

* chore: trigger build

* chore: hide scrollbar for visual test

* chore: hide scrollbar for visual test

* chore(): update base images

* chore: trigger build

* chore: adjust popup visuals

* chore: adjust popup visuals

* chore: adjust popup visuals

* chore: adjust popup visuals

* chore: adjust popup visuals

---------

Co-authored-by: hirsch88 <[email protected]>
  • Loading branch information
hirsch88 and hirsch88 authored Feb 6, 2024
1 parent deff986 commit 8480c46
Show file tree
Hide file tree
Showing 189 changed files with 5,419 additions and 1,908 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_OLD.md
Original file line number Diff line number Diff line change
Expand Up @@ -3375,3 +3375,5 @@ Follow the migration guide [Migration from 8.x to 9.x](https://design.baloise.de

- add design part to the documentation



25 changes: 5 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"storybook": "turbo run build --force --filter=@baloise/design-system-tokens --filter=@baloise/design-system-maps --filter=@baloise/design-system-icons --filter=@baloise/design-system-brand-icons --filter=@baloise/design-system-favicons --filter=@baloise/design-system-css --filter=@baloise/design-system-styles --filter=@baloise/design-system-output-target-* && npm --prefix packages/components run build && npm --prefix packages/components-table run build && npm --prefix docs run storybook",
"==================== INSTALLATION / SETUP =====": "================================",
"precommit": "lint-staged --allow-empty",
"cy:install": "npm --prefix test run install",
"cy:install": "npm --prefix test install",
"cy:build": "turbo run build --filter=@baloise/design-system-tokens --filter=@baloise/design-system-fonts --filter=@baloise/design-system-icons --filter=@baloise/design-system-styles --filter=@baloise/design-system-output-target-vue && npm --prefix packages/components run cy:build && npm --prefix packages/testing run build && npm --prefix test run build",
"registry": "bash scripts/registry",
"==================== FORMATTER / LINTER =======": "================================",
Expand Down
28 changes: 8 additions & 20 deletions packages/testing/src/commands/custom/platform.command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { waitAfterFramePaint } from '../helpers'
import { Platforms, waitAfterFramePaint } from '../helpers'
import { balViewport } from '../../viewports'

Cypress.Commands.add<any>('platform', platform => {
Cypress.log({
Expand All @@ -7,24 +8,11 @@ Cypress.Commands.add<any>('platform', platform => {
message: platform,
})

switch (platform) {
case 'mobile':
return cy.viewport(375, 667, { log: false }).then(() => waitAfterFramePaint())
const key: Platforms = (platform as Platforms) || 'desktop'
const viewport = balViewport[key]

case 'tablet':
return cy.viewport(769, 1024, { log: false }).then(() => waitAfterFramePaint())

case 'desktop':
return cy.viewport(1024, 1280, { log: false }).then(() => waitAfterFramePaint())

case 'highDefinition':
return cy.viewport(1280, 1440, { log: false }).then(() => waitAfterFramePaint())

case 'widescreen':
return cy.viewport(1440, 1920, { log: false }).then(() => waitAfterFramePaint())

case 'fullhd':
return cy.viewport(1920, 1920, { log: false }).then(() => waitAfterFramePaint())
}
return cy.viewport(1024, 1280, { log: false }).then(() => waitAfterFramePaint())
return cy
.viewport(viewport.width, viewport.height, { log: false })
.then(() => waitAfterFramePaint())
.wait(32)
})
5 changes: 5 additions & 0 deletions packages/testing/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
export * from './selectors'

/**
* Viewports sizes
*/
export * from './viewports'

/**
* Helpers
*/
Expand Down
50 changes: 50 additions & 0 deletions packages/testing/src/viewports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Platforms } from './commands/helpers'

type Viewport = {
[key in Platforms]: Cypress.Dimensions
}

export const balViewport: Viewport = {
mobile: {
width: 375,
height: 667,
x: 0,
y: 0,
},
tablet: {
width: 769,
height: 1024,
x: 0,
y: 0,
},
touch: {
width: 769,
height: 1024,
x: 0,
y: 0,
},
desktop: {
width: 1024,
height: 1280,
x: 0,
y: 0,
},
highDefinition: {
width: 1280,
height: 1440,
x: 0,
y: 0,
},
widescreen: {
width: 1440,
height: 1920,
x: 0,
y: 0,
},
fullhd: {
width: 1920,
height: 1920,
x: 0,
y: 0,
},
}
2 changes: 1 addition & 1 deletion test/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'cypress'
import { configureVisualRegression } from 'cypress-visual-regression'
import { configureVisualRegression } from './cypress/support/lib/visuals'
import cypressSplit from 'cypress-split'

export default defineConfig({
Expand Down
Binary file removed test/cypress/downloads/downloads.html
Binary file not shown.
64 changes: 43 additions & 21 deletions test/cypress/e2e/visual/bal-nav-menu-flyout.visual.cy.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,55 @@
import { balViewport } from 'support/utils'

describe('bal-nav-menu-flyout', () => {
describe('basic', () => {
it('basic component', () => {
cy.visit('/components/bal-nav/bal-nav-menu-flyout/test/bal-nav-menu-flyout.visual.html')
.platform('fullhd')
.waitForDesignSystem()
.wait(32)
it('basic component', () => {
cy.visit('/components/bal-nav/bal-nav-menu-flyout/test/bal-nav-menu-flyout.visual.html')
.platform('fullhd')
.waitForDesignSystem()

cy.testVisual('menu-flyout-fullhd')
cy.testVisual('menu-flyout-fullhd', {
errorThreshold: 0.2,
capture: 'viewport',
clip: balViewport['fullhd'],
})

cy.platform('highDefinition').wait(32)
cy.testVisual('menu-flyout-highDefinition')
cy.platform('highDefinition')
cy.testVisual('menu-flyout-highDefinition', {
errorThreshold: 0.2,
capture: 'viewport',
clip: balViewport['highDefinition'],
})

cy.platform('widescreen').wait(32)
cy.testVisual('menu-flyout-widescreen')
cy.platform('widescreen')
cy.testVisual('menu-flyout-widescreen', {
errorThreshold: 0.2,
capture: 'viewport',
clip: balViewport['widescreen'],
})

cy.platform('desktop').wait(32)
cy.testVisual('menu-flyout-desktop')
cy.platform('desktop')
cy.testVisual('menu-flyout-desktop', {
errorThreshold: 0.2,
capture: 'viewport',
clip: balViewport['desktop'],
})
})

it('basic component touch', () => {
cy.visit('/components/bal-nav/bal-nav-menu-flyout/test/bal-nav-menu-flyout.visual.html')
.platform('tablet')
.waitForDesignSystem()
.wait(400)
it('basic component touch', () => {
cy.visit('/components/bal-nav/bal-nav-menu-flyout/test/bal-nav-menu-flyout.visual.html')
.platform('tablet')
.waitForDesignSystem()

cy.testVisual('menu-flyout-tablet')
cy.testVisual('menu-flyout-tablet', {
errorThreshold: 0.2,
capture: 'viewport',
clip: balViewport['tablet'],
})

cy.platform('mobile').wait(400)
cy.testVisual('menu-flyout-mobile')
cy.platform('mobile')
cy.testVisual('menu-flyout-mobile', {
errorThreshold: 0.2,
capture: 'viewport',
clip: balViewport['mobile'],
})
})
})
27 changes: 16 additions & 11 deletions test/cypress/e2e/visual/bal-nav-part-1.visual.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Platforms } from '../../../src/types'
import { Platforms, balViewport } from 'support/utils'

describe('bal-nav - desktop', () => {
testNavigationOnDesktop('widescreen')
Expand All @@ -7,17 +7,23 @@ describe('bal-nav - desktop', () => {

function testNavigationOnDesktop(platform: Platforms) {
describe(platform, () => {
const visualOptions: any = {
errorThreshold: 0.2,
capture: 'viewport',
clip: balViewport[platform],
}

beforeEach(() => {
cy.platform(platform).visit('/components/bal-nav/test/bal-nav.visual.html').waitForDesignSystem().wait(400)
cy.visit('/components/bal-nav/test/bal-nav.visual.html').platform(platform).waitForDesignSystem()
})

it('closed menu on top', () => {
cy.testVisual(`nav-desktop-${platform}-closed-top`, 0.2)
cy.testVisual(`nav-desktop-${platform}-closed-top`, visualOptions)
})

it('closed menu on bottom', () => {
cy.scrollTo('bottom')
cy.testVisual(`nav-desktop-${platform}-closed-bottom`, 0.2)
cy.testVisual(`nav-desktop-${platform}-closed-bottom`, visualOptions)
})

it('open menu', () => {
Expand All @@ -27,8 +33,8 @@ describe('bal-nav - desktop', () => {
.eq(0)
.find('button')
.click()
cy.wait(400)
cy.testVisual(`nav-desktop-${platform}-open`, 0.2)
.waitForComponents()
cy.testVisual(`nav-desktop-${platform}-open`, visualOptions)
})

it('open menu second tab', () => {
Expand All @@ -38,14 +44,13 @@ describe('bal-nav - desktop', () => {
.eq(1)
.find('button')
.click()
cy.wait(400)
cy.testVisual(`nav-desktop-${platform}-open-menu-second-tab`, 0.2)
.waitForComponents()
cy.testVisual(`nav-desktop-${platform}-open-menu-second-tab`, visualOptions)
})

it('open search popoup', () => {
cy.getByTestId('basic').find('#bal-nav__meta-buttons').eq(0).click()
cy.wait(400)
cy.testVisual(`nav-desktop-${platform}-open-search-popup`, 0.2)
cy.getByTestId('basic').find('#bal-nav__meta-buttons').eq(0).click().waitForComponents()
cy.testVisual(`nav-desktop-${platform}-open-search-popup`, visualOptions)
})
})
}
Expand Down
26 changes: 18 additions & 8 deletions test/cypress/e2e/visual/bal-nav-part-2.visual.cy.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
import { Platforms } from '../../../src/types'
import { Platforms, balViewport } from 'support/utils'

describe('bal-nav - touch', () => {
testNavigationOnTouch('tablet')
testNavigationOnTouch('mobile')

function testNavigationOnTouch(platform: Platforms) {
describe(platform, () => {
const visualOptions: any = {
errorThreshold: 0.2,
capture: 'viewport',
clip: balViewport[platform],
}

beforeEach(() => {
cy.platform(platform).visit('/components/bal-nav/test/bal-nav.visual.html').waitForDesignSystem().wait(400)
cy.visit('/components/bal-nav/test/bal-nav.visual.html').platform(platform).waitForDesignSystem()
})

it('closed menu on top', () => {
cy.testVisual(`nav-touch-${platform}-closed-top`, 0.2)
cy.testVisual(`nav-touch-${platform}-closed-top`, visualOptions)
})

it('closed menu on bottom', () => {
cy.scrollTo('bottom')
cy.wait(400)
cy.testVisual(`nav-touch-${platform}-closed-bottom`, 0.2)
cy.waitForBrowser()
cy.testVisual(`nav-touch-${platform}-closed-bottom`, visualOptions)
})

it('open menu', () => {
cy.scrollTo('top')
cy.getByTestId('basic').find('.bal-nav-meta-bar').find('bal-stack > bal-button').eq(1).click()
cy.wait(400)
cy.testVisual(`nav-touch-${platform}-open`, 0.2)
cy.getByTestId('basic')
.find('.bal-nav-meta-bar')
.find('bal-stack > bal-button')
.eq(1)
.click()
.waitForComponents()
cy.testVisual(`nav-touch-${platform}-open`, visualOptions)
})
})
}
Expand Down
Loading

0 comments on commit 8480c46

Please sign in to comment.