Skip to content

Commit 2d144e4

Browse files
committed
test(ui-spinner): migrate old Spinner tests
1 parent 0e6e1e4 commit 2d144e4

File tree

7 files changed

+92
-155
lines changed

7 files changed

+92
-155
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ui-spinner/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"prop-types": "^15.8.1"
3737
},
3838
"devDependencies": {
39+
"@instructure/ui-axe-check": "10.10.0",
3940
"@instructure/ui-babel-preset": "10.10.0",
40-
"@instructure/ui-test-locator": "10.10.0",
4141
"@instructure/ui-test-utils": "10.10.0",
4242
"@instructure/ui-themes": "10.10.0",
4343
"@testing-library/jest-dom": "^6.6.3",

packages/ui-spinner/src/Spinner/SpinnerLocator.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/ui-spinner/src/Spinner/__new-tests__/Spinner.test.tsx

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,100 @@
2323
*/
2424
import React from 'react'
2525
import { render, waitFor, screen } from '@testing-library/react'
26+
import { runAxeCheck } from '@instructure/ui-axe-check'
27+
import { vi, expect } from 'vitest'
28+
import type { MockInstance } from 'vitest'
2629

2730
import '@testing-library/jest-dom'
31+
import { View } from '@instructure/ui-view'
2832
import Spinner from '../index'
33+
import type { SpinnerProps } from '../props'
2934

3035
describe('<Spinner />', () => {
36+
let consoleErrorMock: ReturnType<typeof vi.spyOn>
37+
38+
beforeEach(() => {
39+
// Mocking console to prevent test output pollution and expect for messages
40+
consoleErrorMock = vi
41+
.spyOn(console, 'error')
42+
.mockImplementation(() => {}) as MockInstance
43+
})
44+
45+
afterEach(() => {
46+
consoleErrorMock.mockRestore()
47+
})
48+
49+
it('should render', async () => {
50+
const { container } = render(<Spinner renderTitle="Loading" size="small" />)
51+
const spinner = container.querySelector('div[class$="-spinner"]')
52+
53+
expect(spinner).toBeInTheDocument()
54+
})
55+
56+
it('should render the title prop text in the SVG element title', async () => {
57+
const { container } = render(<Spinner renderTitle="Loading" size="large" />)
58+
const spinner = container.querySelector('div[class$="-spinner"]')
59+
60+
expect(spinner).toHaveTextContent('Loading')
61+
})
62+
63+
it('should meet a11y standards', async () => {
64+
const { container } = render(<Spinner renderTitle="Loading" size="small" />)
65+
const axeCheck = await runAxeCheck(container)
66+
expect(axeCheck).toBe(true)
67+
})
68+
69+
it('should render the contents of a component used in renderTitle', async () => {
70+
const Translation = ({ children }: SpinnerProps) => (
71+
<span>I have translated {children}.</span>
72+
)
73+
74+
const { container } = render(
75+
<Spinner renderTitle={<Translation>Loading</Translation>} size="small" />
76+
)
77+
78+
const spinner = container.querySelector('div[class$="-spinner"]')
79+
const axeCheck = await runAxeCheck(container)
80+
81+
expect(axeCheck).toBe(true)
82+
expect(spinner).toHaveTextContent('I have translated Loading')
83+
})
84+
85+
describe('when passing down props to View', () => {
86+
const allowedProps: { [key: string]: any } = {
87+
margin: 'small',
88+
elementRef: () => {},
89+
as: 'div'
90+
}
91+
92+
View.allowedProps
93+
.filter((prop) => prop !== 'children')
94+
.forEach((prop) => {
95+
if (Object.keys(allowedProps).indexOf(prop) < 0) {
96+
it(`should NOT allow the '${prop}' prop`, async () => {
97+
const props = {
98+
[prop]: 'foo'
99+
}
100+
const expectedErrorMessage = `prop '${prop}' is not allowed.`
101+
102+
render(<Spinner renderTitle="Loading" {...props} />)
103+
104+
expect(consoleErrorMock).toHaveBeenCalledWith(
105+
expect.stringContaining(expectedErrorMessage),
106+
expect.any(String)
107+
)
108+
})
109+
} else {
110+
it(`should allow the '${prop}' prop`, async () => {
111+
const props = { [prop]: allowedProps[prop] }
112+
render(<Spinner renderTitle="Loading" {...props} />)
113+
114+
expect(consoleErrorMock).not.toHaveBeenCalled()
115+
})
116+
}
117+
})
118+
})
119+
31120
describe('with the delay prop', () => {
32121
it('should delay rendering', async () => {
33122
render(<Spinner renderTitle="Loading" delay={300} />)

packages/ui-spinner/src/Spinner/__tests__/Spinner.test.tsx

Lines changed: 0 additions & 96 deletions
This file was deleted.

packages/ui-spinner/src/Spinner/locator.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/ui-spinner/tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"include": ["src"],
99
"references": [
10+
{ "path": "../ui-axe-check/tsconfig.build.json" },
1011
{ "path": "../console/tsconfig.build.json" },
1112
{ "path": "../emotion/tsconfig.build.json" },
1213
{ "path": "../shared-types/tsconfig.build.json" },
@@ -17,7 +18,6 @@
1718
{ "path": "../ui-view/tsconfig.build.json" },
1819
{ "path": "../uid/tsconfig.build.json" },
1920
{ "path": "../ui-babel-preset/tsconfig.build.json" },
20-
{ "path": "../ui-test-locator/tsconfig.build.json" },
2121
{ "path": "../ui-test-utils/tsconfig.build.json" },
2222
{ "path": "../ui-themes/tsconfig.build.json" }
2323
]

0 commit comments

Comments
 (0)