Skip to content

Commit

Permalink
refactor: Migrate visual regression tests to Playwright
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Jul 17, 2024
1 parent a097c54 commit cca921d
Show file tree
Hide file tree
Showing 188 changed files with 191 additions and 184 deletions.
1 change: 1 addition & 0 deletions .github/workflows/server-styling-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
curl https://nextcloud.github.io/server/apps/theming/css/default.css | sed 's|/apps/theming/img|./img|g' > default.css
# Fix icons and img css import
curl https://nextcloud.github.io/server/core/css/server.css | sed 's|../../dist/icons.css|./icons.css|g' | sed 's|../img|./img|g' > server.css
curl https://nextcloud.github.io/server/core/css/apps.css | sed 's|../img|./img|g' > apps.css
curl https://nextcloud.github.io/server/dist/icons.css --output icons.css
- name: Create Pull Request
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
68 changes: 0 additions & 68 deletions cypress/visual/AppNavigationItem.cy.ts

This file was deleted.

7 changes: 0 additions & 7 deletions cypress/visual/NcAppSidebar/NcAppSidebar-compact.cy.js

This file was deleted.

7 changes: 0 additions & 7 deletions cypress/visual/NcAppSidebar/NcAppSidebar.cy.js

This file was deleted.

94 changes: 0 additions & 94 deletions cypress/visual/NcAppSidebar/NcAppSidebarMixin.js

This file was deleted.

8 changes: 0 additions & 8 deletions cypress/visual/NcAppSidebar/style.css

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template>
<NcContent app-name="testing">
<NcAppNavigation aria-label="In-app navigation">
<template #list>
<NcAppNavigationItem name="Home" to="/" :editable="true" />
<NcAppNavigationItem name="Foo" to="/foo" :editable="true" />
<NcAppNavigationItem name="Back" active :editable="true" />
<NcAppNavigationItem name="Bar" :editable="true" />
</template>
</NcAppNavigation>
<NcAppContent />
</NcContent>
</template>

<script setup lang="ts">
/*!
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import NcAppContent from '../../../../src/components/NcAppContent/NcAppContent.vue'
import NcAppNavigation from '../../../../src/components/NcAppNavigation/NcAppNavigation.vue'
import NcAppNavigationItem from '../../../../src/components/NcAppNavigationItem/NcAppNavigationItem.vue'
import NcContent from '../../../../src/components/NcContent/NcContent.vue'
</script>
78 changes: 78 additions & 0 deletions tests/component/components/NcAppNavigationItem/visual.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { HooksConfig } from '../../setup/index'
import { expect, test } from '@playwright/experimental-ct-vue'

import AppNavigation from './AppNavigation.story.vue'

// A little bit hacky but we test a wrapper element so we need to use the real NcContent and NcAppNavigation
test.beforeEach(async ({ mount, page }) => {
const handle = await page.locator('#content').elementHandle()
expect(handle).not.toBeNull()
await handle!.evaluate((node) => { node.innerHTML = ''; node.id = 'root' })

await mount<HooksConfig>(AppNavigation, {
hooksConfig: {
routes: [
{ path: '/', component: AppNavigation },
{ path: '/foo', component: AppNavigation },
]
}
})
})

test('has primary styling on active route', { tag: '@visual' }, async ({ page }) => {
const navigation = page.getByRole('navigation', { name: 'In-app navigation'})

await expect(navigation).toBeVisible()
await expect(navigation.getByRole('listitem', { name: 'Home' })).toHaveScreenshot()
})

test('has primary button styling on active route with editing=true', { tag: '@visual' }, async ({ page }) => {
const navigation = page.getByRole('navigation', { name: 'In-app navigation'})
const item = navigation.getByRole('listitem', { name: 'Home' })

await expect(navigation).toBeVisible()
await expect(item).toBeVisible()

await item.getByRole('button', { name: 'Edit item' }).click()
await expect(item.getByRole('textbox')).toBeVisible()

await expect(item).toHaveScreenshot()
})

test('has tertiary styling on non active route', { tag: '@visual' }, async ({ page }) => {
const navigation = page.getByRole('navigation', { name: 'In-app navigation'})

await expect(navigation).toBeVisible()
await expect(navigation.getByRole('listitem', { name: 'Foo'})).toHaveScreenshot()
})

test('has primary styling on active entry', { tag: '@visual' }, async ({ page }) => {
const navigation = page.getByRole('navigation', { name: 'In-app navigation'})

await expect(navigation).toBeVisible()
await expect(navigation.getByRole('listitem', { name: 'Back' })).toHaveScreenshot()
})

test('has primary button styling on active entry with editing=true', { tag: '@visual' }, async ({ page }) => {
const navigation = page.getByRole('navigation', { name: 'In-app navigation'})
const item = navigation.getByRole('listitem', { name: 'Back' })

await expect(navigation).toBeVisible()
await expect(item).toBeVisible()

await item.getByRole('button', { name: 'Edit item' }).click()
await expect(item.getByRole('textbox')).toBeVisible()

await expect(item).toHaveScreenshot()
})

test('has tertiary styling on non active entry', { tag: '@visual' }, async ({ page }) => {
const navigation = page.getByRole('navigation', { name: 'In-app navigation'})

await expect(navigation).toBeVisible()
await expect(navigation.getByRole('listitem', { name: 'Bar' })).toHaveScreenshot()
})
50 changes: 50 additions & 0 deletions tests/component/components/NcAppSidebar/AppSidebar.story.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<template>
<NcContent app-name="testing">
<NcAppContent>
App content
</NcAppContent>
<NcAppSidebar :compact="compact"
name="Very long title that will certainly overflow the sidebar width"
:subname="subname ? 'Very long subtitle what will certainly overflow the sidebar width' : ''"
:name-editable="nameEditable"
>
<template v-if="header" #header>
<div style="background-color: gold; height: 100%; width: 100%"></div>
</template>
<template v-if="secondaryActions" #secondary-actions>
<NcActionButton>
<template #icon>
<IconDelete :size="20" />
</template>
Action1
</NcActionButton>
<NcActionButton>
Action2
</NcActionButton>
</template>
<div>Sidebar content</div>
</NcAppSidebar>
</NcContent>
</template>

<script setup lang="ts">
/*!
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import NcAppContent from '../../../../src/components/NcAppContent/NcAppContent.vue'
import NcAppSidebar from '../../../../src/components/NcAppSidebar/NcAppSidebar.vue'
import NcActionButton from '../../../../src/components/NcActionButton/NcActionButton.vue'
import NcContent from '../../../../src/components/NcContent/NcContent.vue'
import IconDelete from 'vue-material-design-icons/Delete.vue'
defineProps<{
compact: boolean
subname: boolean
nameEditable: boolean
header: boolean
secondaryActions: boolean
}>()
</script>
37 changes: 37 additions & 0 deletions tests/component/components/NcAppSidebar/visual.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { expect, test } from '@playwright/experimental-ct-vue'

import AppSidebar from './AppSidebar.story.vue'

// A little bit hacky but we test a wrapper element so we need to use the real NcContent and NcAppNavigation
test.beforeEach(async ({ mount, page }) => {
const handle = await page.locator('#content').elementHandle()
expect(handle).not.toBeNull()
await handle!.evaluate((node) => { node.innerHTML = ''; node.id = 'root' })
})

new Array(2**5)
.fill('')
.map((_, index) => ({
compact: Boolean(index&16),
subname: Boolean(index&8),
nameEditable: Boolean(index&4),
header: Boolean(index&2),
secondaryActions: Boolean(index&1),
}))
.forEach((props, index) => {
test(
`Sidebar header${props.compact ? ': compact ' : (index > 0 ? ': ' : '')}${props.subname ? 'subname ' : ''}${props.nameEditable ? 'editable ' : ''}${props.header ? 'header ' : ''}${props.secondaryActions ? 'actions' : ''}`,
{ tag: '@visual' },
async ({ mount },
) => {
const component = await mount(AppSidebar, {
props,
})
await expect(component).toBeVisible()
await expect(component.locator('header')).toHaveScreenshot({ caret: 'hide' })
})
})

0 comments on commit cca921d

Please sign in to comment.