Skip to content

Commit b94c875

Browse files
committed
test: add more regression tests. Fix SSR error in Calendar
in Calendar the weekday header IDs were getting out of sync because they were not deterministically generated
1 parent af10476 commit b94c875

File tree

44 files changed

+4436
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4436
-62
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@types/react-dom": "^18.3.0",
6565
"@vitejs/plugin-react": "^4.5.1",
6666
"@vitest/eslint-plugin": "^1.2.1",
67+
"@types/node": "^22",
6768
"chai": "^4.4.1",
6869
"chalk": "^4.1.2",
6970
"commitizen": "^4.3.1",
@@ -101,7 +102,7 @@
101102
"@types/jest": "needed because https://github.com/testing-library/jest-dom/issues/544 recheck if fixed"
102103
},
103104
"engines": {
104-
"node": ">=18",
105+
"node": ">=22",
105106
"yarn": "YARN NO LONGER USED - use npm instead."
106107
},
107108
"config": {

packages/ui-calendar/src/Calendar/index.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import { View } from '@instructure/ui-view'
2828
import {
2929
safeCloneElement,
3030
callRenderProp,
31-
omitProps
31+
omitProps,
32+
withDeterministicId
3233
} from '@instructure/ui-react-utils'
3334
import { createChainedFunction } from '@instructure/ui-utils'
3435
import { logError as error } from '@instructure/console'
35-
import { uid } from '@instructure/uid'
3636
import { AccessibleContent } from '@instructure/ui-a11y-content'
3737

3838
import { testable } from '@instructure/ui-testable'
@@ -64,6 +64,7 @@ import { SimpleSelect } from '@instructure/ui-simple-select'
6464
category: components
6565
---
6666
**/
67+
@withDeterministicId()
6768
@withStyle(generateStyle, generateComponentTheme)
6869
@testable()
6970
class Calendar extends Component<CalendarProps, CalendarState> {
@@ -82,14 +83,15 @@ class Calendar extends Component<CalendarProps, CalendarState> {
8283
}
8384

8485
ref: Element | null = null
85-
private _weekdayHeaderIds = (
86-
this.props.renderWeekdayLabels || this.defaultWeekdays
87-
).reduce((ids: Record<number, string>, _label, i) => {
88-
return { ...ids, [i]: uid(`weekday-header-${i}`) }
89-
}, {})
86+
private _weekdayHeaderIds
87+
9088
constructor(props: CalendarProps) {
9189
super(props)
92-
90+
this._weekdayHeaderIds = (
91+
this.props.renderWeekdayLabels || this.defaultWeekdays
92+
).reduce((ids: Record<number, string>, _label, i) => {
93+
return { ...ids, [i]: this.props.deterministicId!('weekday-header') }
94+
}, {})
9395
this.state = this.calculateState(
9496
this.locale(),
9597
this.timezone(),

packages/ui-calendar/src/Calendar/props.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { ReactElement } from 'react'
3838
import type { CalendarDayProps } from './Day/props'
3939
import { Renderable } from '@instructure/shared-types'
4040
import type { Moment } from '@instructure/ui-i18n'
41+
import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
4142

4243
type CalendarOwnProps = {
4344
/**
@@ -178,7 +179,8 @@ type AllowedPropKeys = Readonly<Array<PropKeys>>
178179

179180
type CalendarProps = CalendarOwnProps &
180181
WithStyleProps<CalendarTheme, CalendarStyle> &
181-
OtherHTMLAttributes<CalendarOwnProps>
182+
OtherHTMLAttributes<CalendarOwnProps> &
183+
WithDeterministicIdProps
182184

183185
type CalendarStyle = ComponentStyle<
184186
'navigation' | 'navigationWithButtons' | 'weekdayHeader' | 'yearPicker'

packages/ui-codemods/lib/__node_tests__/runTest.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ export function runTest(codemod: Transform) {
4545
entries.forEach((entry) => {
4646
if (entry.isFile() && entry.name.includes('input')) {
4747
const isWarningTest = entry.name.includes('.warning.input')
48-
const inputPath = path.join(entry.path, entry.name)
48+
const inputPath = path.join(entry.parentPath, entry.name)
4949
const input = fs.readFileSync(inputPath, 'utf8')
5050
const expectedName = entry.name.replace('input', 'output')
51-
const expectedPath = path.join(entry.path, expectedName)
51+
const expectedPath = path.join(entry.parentPath, expectedName)
5252
const expected = fs.readFileSync(expectedPath, 'utf8')
5353

5454
// eslint-disable-next-line no-console
@@ -61,12 +61,17 @@ export function runTest(codemod: Transform) {
6161
)
6262

6363
if (isWarningTest) {
64-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => { })
64+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
6565

6666
try {
6767
const j = jscodeshift.withParser('tsx')
6868
const fileInfo = { path: inputPath, source: input }
69-
const api = { jscodeshift: j, j: j, stats: () => { }, report: () => { } }
69+
const api = {
70+
jscodeshift: j,
71+
j: j,
72+
stats: () => {},
73+
report: () => {}
74+
}
7075
const options = {}
7176

7277
// Run codemod withouth comparison

packages/ui-drilldown/src/Drilldown/DrilldownOption/__tests__/DrilldownOption.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ describe('<Drilldown.Option />', () => {
211211
)
212212
const option = screen.getByLabelText('Option')
213213

214-
expect(option).toHaveAttribute('role', 'button')
214+
expect(option).toHaveAttribute('role', 'menuitem')
215215
expect(option).toHaveAttribute('aria-haspopup', 'true')
216216
})
217217
})

packages/ui-drilldown/src/Drilldown/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ class Drilldown extends Component<DrilldownProps, DrilldownState> {
11261126
if (subPageId) {
11271127
optionProps.renderAfterLabel = <IconArrowOpenEndSolid />
11281128
optionProps['aria-haspopup'] = true
1129-
optionProps.role = customRole || 'button'
1129+
optionProps.role = customRole || 'menuitem'
11301130
warn(
11311131
!renderAfterLabel,
11321132
`The prop "renderAfterLabel" is reserved on item with id: "${id}". When it has "subPageId" provided, a navigation arrow will render after the label.`

packages/ui-heading/src/Heading/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ Pre-configured and with unique styles, the `ai-headings` are used for standardiz
4949
type: example
5050
---
5151
<div style={{display: 'flex', flexDirection: 'column', gap: '24px'}}>
52-
<Heading aiVariant="stacked">Nutrition Facts</Heading>
53-
<Heading aiVariant="horizontal">Nutrition Facts</Heading>
54-
<Heading aiVariant="iconOnly">Nutrition Facts</Heading>
52+
<Heading aiVariant="stacked" level="h2">Nutrition Facts</Heading>
53+
<Heading aiVariant="horizontal" level="h3">Nutrition Facts</Heading>
54+
<Heading aiVariant="iconOnly" level="h4">Nutrition Facts</Heading>
5555
</div>
5656
```
5757

packages/ui-options/src/Options/Item/styles.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ const generateStyle = (
6363
background: componentTheme.selectedBackground,
6464
color: componentTheme.highlightedLabelColor
6565
},
66-
disabled: { cursor: 'not-allowed', opacity: 0.5 },
66+
disabled: { cursor: 'not-allowed', opacity: 0.68 },
6767
'highlighted-disabled': {
6868
background: componentTheme.highlightedBackground,
6969
color: componentTheme.highlightedLabelColor,
70-
cursor: 'not-allowed',
71-
opacity: 0.5
70+
cursor: 'not-allowed'
7271
},
7372
'selected-highlighted': {
7473
background: componentTheme.selectedHighlightedBackground,

packages/ui-select/src/Select/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,14 @@ class Select extends Component<SelectProps> {
780780
onBlur: utils.createChainedFunction(onBlur, onRequestHideOptions),
781781
...overrideProps
782782
}
783-
784-
return <TextInput {...triggerProps} {...getInputProps(inputProps)} />
783+
// suppressHydrationWarning is needed because `role` depends on the browser type
784+
return (
785+
<TextInput
786+
{...triggerProps}
787+
{...getInputProps(inputProps)}
788+
suppressHydrationWarning
789+
/>
790+
)
785791
}
786792

787793
render() {

0 commit comments

Comments
 (0)