Skip to content

Commit 5eb694e

Browse files
committed
test: add visual regression tests for Tooltip
1 parent 7d8cc62 commit 5eb694e

File tree

11 files changed

+335
-82
lines changed

11 files changed

+335
-82
lines changed

regression-test/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
# debug
2626
npm-debug.log*
27+
build-archive.log
2728

2829
# local env files
2930
.env*.local

regression-test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This is a simple Next.js app importing (locally) @instructure/ui. This allows us
1313
2. Then open the regression test folder: `cd regression-test`
1414
3. Run the dev server with `npm run dev`
1515
4. The dev server will be accessible at `localhost:3000`
16-
5. Once the dev server is running you can start the Cypress e2e tests with the `npm run cypress` command
16+
5. Once the dev server is running you can start the Cypress e2e tests with the `npm run cypress` command. Run `npm run cypress-chrome` to open the Cypress GUI where you can see detailed error logs, snapshots etc.
1717

1818
### To add a new component
1919

regression-test/cypress.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import { defineConfig } from 'cypress'
2525
import { installPlugin } from '@chromatic-com/cypress'
2626

2727
export default defineConfig({
28+
env: {
29+
delay: 100
30+
},
2831
e2e: {
2932
setupNodeEvents(on, config) {
3033
installPlugin(on, config)

regression-test/cypress/e2e/spec.cy.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function terminalLog(violations: Result[]) {
6565
const axeOptions: { runOnly: RunOnly } = {
6666
runOnly: {
6767
type: 'tag',
68-
values: ['wcag2a', 'wcag2aa', 'section508', 'best-practice']
68+
values: ['wcag2a', 'wcag2aa', 'section508']
6969
}
7070
}
7171

@@ -84,6 +84,14 @@ describe('visual regression test', () => {
8484

8585
it('check avatar', () => {
8686
cy.visit('http://localhost:3000/avatar')
87+
cy.wait(300) // images render a frame later, Chromatic needs a bit more delay
88+
cy.injectAxe()
89+
cy.checkA11y('.axe-test', axeOptions, terminalLog)
90+
})
91+
92+
it('check tooltip', () => {
93+
cy.visit('http://localhost:3000/tooltip')
94+
cy.wait(300) // tooltips render a frame later, Chromatic needs a bit more delay
8795
cy.injectAxe()
8896
cy.checkA11y('.axe-test', axeOptions, terminalLog)
8997
})

regression-test/next.config.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*//** @type {import('next').NextConfig} */
24-
const nextConfig = {}
24+
const nextConfig = {
25+
// strict mode needs to be disabled, so deterministic ID generation
26+
// works. If its enabled, client side double rendering causes IDs to
27+
// come out of sync. TODO fix
28+
reactStrictMode: false
29+
}
2530

2631
export default nextConfig

regression-test/package-lock.json

Lines changed: 51 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

regression-test/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@
88
"build": "next build",
99
"start": "next start",
1010
"lint": "next lint",
11-
"cypress": "ELECTRON_EXTRA_LAUNCH_ARGS=--remote-debugging-port=9222 cypress run"
11+
"cypress": "ELECTRON_EXTRA_LAUNCH_ARGS=--remote-debugging-port=9222 cypress run",
12+
"cypress-chrome": "cypress open --browser chrome"
1213
},
1314
"keywords": [],
1415
"devDependencies": {
1516
"@chromatic-com/cypress": "^0.11.0",
1617
"@instructure/browserslist-config-instui": "10.14.0",
1718
"@tailwindcss/postcss": "^4.1.4",
1819
"@types/node": "^20",
19-
"@types/react": "^18",
20-
"@types/react-dom": "^18",
2120
"autoprefixer": "^10.0.1",
2221
"axe-core": "^4.10.3",
23-
"chromatic": "^11.27.0",
22+
"chromatic": "^13.1.3",
2423
"cypress": "^14.4.1",
2524
"cypress-axe": "^1.6.0",
2625
"eslint": "^8",
@@ -32,8 +31,8 @@
3231
"dependencies": {
3332
"instructure-ui": "file:../packages",
3433
"next": "14.2.31",
35-
"react": "^18.3.1",
36-
"react-dom": "^18"
34+
"react": "18.3.1",
35+
"react-dom": "^18.3.1"
3736
},
3837
"//dependency-comments": {
3938
"next": "NextJS 15 uses React 19, this is not overrideable"

regression-test/src/app/avatar/page.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@
2323
*/
2424
'use client'
2525
import React from 'react'
26-
import { Avatar } from 'instructure-ui/ui-avatar/es/index'
27-
import { IconGroupLine, IconAiSolid } from 'instructure-ui/ui-icons/es/index'
26+
import { Avatar as avv } from 'instructure-ui/ui-avatar/es/index'
27+
import {
28+
IconGroupLine as igl,
29+
IconAiSolid
30+
} from 'instructure-ui/ui-icons/es/index'
31+
32+
const Avatar = avv as any
33+
const IconGroupLine = igl as any
2834

2935
export default function AvatarPage() {
3036
return (
@@ -255,7 +261,7 @@ export default function AvatarPage() {
255261
name="David Herbert"
256262
hasInverseColor
257263
color="fire"
258-
themeOverride={{ colorFire: '#efb410' }}
264+
themeOverride={{ colorFire: '#013410' }}
259265
/>
260266
</div>
261267
<div>

regression-test/src/app/layout.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,26 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
'use client'
2425
import React from 'react'
25-
import type { Metadata } from 'next'
2626
import { Inter } from 'next/font/google'
2727
import './globals.css'
28+
import { InstUISettingsProvider } from '@instructure/emotion'
2829

2930
const inter = Inter({ subsets: ['latin'] })
3031

31-
export const metadata: Metadata = {
32-
title: 'InstUI Visual Regression Test Suite'
33-
}
34-
3532
export default function RootLayout({
3633
children
3734
}: Readonly<{
3835
children: React.ReactNode
3936
}>) {
4037
return (
38+
// we need to make a new Map to reset counting on the server side
39+
// on each page refresh TODO fix
4140
<html lang="en">
42-
<body className={inter.className}>{children}</body>
41+
<InstUISettingsProvider instanceCounterMap={new Map()}>
42+
<body className={inter.className}>{children}</body>
43+
</InstUISettingsProvider>
4344
</html>
4445
)
4546
}

regression-test/src/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
'use client'
2626
import { Link } from 'instructure-ui/ui-link/es/index'
2727

28-
const components = ['button', 'alert', 'avatar']
28+
const components = ['button', 'alert', 'avatar', 'tooltip']
2929

3030
export default function Home() {
3131
return (

0 commit comments

Comments
 (0)