Skip to content

Commit c1015c4

Browse files
committed
test: fix Tray test and other small fixes
1 parent bc028c8 commit c1015c4

16 files changed

Lines changed: 136 additions & 70 deletions

cypress/component/DateInput.cy.tsx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -617,27 +617,29 @@ describe('<DateInput/>', () => {
617617

618618
cy.get('table').should('be.visible')
619619

620-
cy.contains('button', dayForSelect)
621-
.should('be.enabled')
622-
.click()
623-
.wait(500)
624-
625-
cy.get('input')
626-
.invoke('val')
627-
.then((inputValue) => {
628-
const inputValueRTLFree = removeRtlMarkers(inputValue)
629-
const hasCorrectDirection =
630-
(textDirection === 'rtl') === hasRtlMarkers(inputValue as string)
631-
632-
cy.wrap(hasCorrectDirection).should('be.true')
633-
cy.wrap(inputValueRTLFree).should('equal', expectedFormattedValue)
634-
cy.wrap(onChange).should(
635-
'have.been.calledWith',
636-
Cypress.sinon.match.any,
637-
expectedOnChangeValue,
638-
expectedDateIsoString
639-
)
640-
})
620+
cy.contains('button', dayForSelect).should('be.enabled').click()
621+
622+
// Retryable assertion instead of a fixed `.wait(500)` + one-shot
623+
// `.then()` read: Cypress re-runs this callback until the input value
624+
// settles after the click-driven onChange/state update.
625+
cy.get('input').should(($input) => {
626+
const inputValue = $input.val() as string
627+
const inputValueRTLFree = removeRtlMarkers(inputValue)
628+
const hasCorrectDirection =
629+
(textDirection === 'rtl') === hasRtlMarkers(inputValue)
630+
631+
expect(hasCorrectDirection, 'text direction matches locale').to.equal(
632+
true
633+
)
634+
expect(inputValueRTLFree).to.equal(expectedFormattedValue)
635+
})
636+
637+
cy.wrap(onChange).should(
638+
'have.been.calledWith',
639+
Cypress.sinon.match.any,
640+
expectedOnChangeValue,
641+
expectedDateIsoString
642+
)
641643
})
642644
})
643645
})

cypress/component/Emotion-useStyle.cy.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const grey1111 = 'rgb(0, 128, 0)'
5858
const green4570 = 'rgb(10, 10, 10)'
5959
const blue4570 = 'rgb(255, 255, 0)'
6060
const exampleTheme: Theme = {
61+
// TODO update to the new theme syntax
6162
key: 'exampleTheme',
6263
colors: {
6364
contrasts: {

cypress/component/Modal-test-1.cy.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ import 'cypress-real-events'
2828
import '../support/component'
2929

3030
describe('<Modal/>', () => {
31-
// cypress-real-events keeps the real cursor where the previous test left it,
32-
// so a test that ends hovering a Tooltip trigger leaves the next test's
33-
// tooltip already visible (breaking its initial `not.be.visible` assertion).
31+
// cypress-real-events keeps the real cursor where the previous test left it.
3432
// Park the cursor off-component (viewport bottom-right) before each test.
3533
beforeEach(() => {
3634
cy.get('body').realMouseMove(0, 0, { position: 'bottomRight' })

cypress/component/OptionsItem.cy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { Options } from '@instructure/ui/latest'
2929
import { IconCheckSolid } from '@instructure/ui-icons'
3030

3131
describe('<OptionsItem/>', () => {
32-
it('should allow label to recieve focus', () => {
32+
it('should allow label to receive focus', () => {
3333
const onFocus = cy.spy()
3434
cy.mount(
3535
<Options.Item tabIndex={-1} onFocus={onFocus}>

cypress/component/Pill.cy.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ import '../support/component'
2828
import 'cypress-real-events'
2929

3030
describe('<Pill/>', () => {
31-
// cypress-real-events keeps the real cursor where the previous test left it,
32-
// so a test that ends hovering the Pill would leave the next test's tooltip
33-
// already visible. Park the cursor away (viewport bottom-right) before each.
31+
// cypress-real-events keeps the real cursor where the previous test left it.
32+
// Park the cursor off-component (viewport bottom-right) before each test.
3433
beforeEach(() => {
3534
cy.get('body').realMouseMove(0, 0, { position: 'bottomRight' })
3635
})

cypress/component/SideNavBarItem.cy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { IconAdminLine } from '@instructure/ui/latest'
2929
import '../support/component'
3030

3131
describe('<SideNavBarItem/>', () => {
32-
it('should show a tooltip when the nav is minimized ', () => {
32+
it('should show a tooltip when the nav is minimized', () => {
3333
const onClick = cy.spy()
3434
cy.mount(
3535
<div data-testid="navBarItemWrapper" style={{ width: 300 }}>

cypress/component/TimeSelect.cy.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,14 @@ describe('<TimeSelect/>', () => {
354354
renderLabel="Choose a time"
355355
allowNonStepInput={true}
356356
locale="en_AU"
357-
format="LTS" // shows seconds
357+
format="LTS" // `h:mm:ss A`
358358
timezone="US/Eastern"
359359
onChange={onChange}
360360
/>
361361
)
362362
cy.get('input[id^="Select_"]').as('input')
363363
cy.get('@input').should('have.value', '')
364364

365-
// Hour must not be zero-padded: `format="LTS"` is `h:mm:ss A` (single `h`)
366-
// and the input is parsed in moment strict mode, so `04:...` would be
367-
// rejected and cleared on blur. See INSTUI leading-zero note.
368365
cy.get('@input').realClick().realType('4:45:55 AM')
369366
cy.get('@input').blur() // sends onChange event
370367

cypress/component/Tooltip.cy.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ import '../support/component'
3030

3131
describe('<Tooltip/>', () => {
3232
// cypress-real-events keeps the real cursor where the previous test left it.
33-
// A test that ends hovering the trigger would leave the next freshly-mounted
34-
// tooltip already visible, breaking its initial `not.be.visible` assertion.
35-
// Park the cursor in the viewport's bottom-right (away from the top-left
36-
// mounted trigger) before each test.
33+
// Park the cursor in the viewport's bottom-right before each test.
3734
beforeEach(() => {
3835
cy.get('body').realMouseMove(0, 0, { position: 'bottomRight' })
3936
})

cypress/component/Tray.cy.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ describe('<Tray />', () => {
3636
open
3737
size="small"
3838
placement="start"
39-
themeOverride={{ smallWidth: '10em' }}
39+
themeOverride={{ widthSm: '165px' }}
4040
>
4141
<div>Hello</div>
4242
</Tray>
4343
)
4444

4545
cy.get('[aria-label="Tray Example"]')
4646
.should('have.attr', 'role', 'dialog')
47-
.and('have.css', 'width', '160px')
47+
.parent()
48+
.should('have.css', 'width', '165px')
4849
})
4950

5051
it('should call onDismiss prop when Esc key pressed', () => {
@@ -68,7 +69,7 @@ describe('<Tray />', () => {
6869
cy.wrap(onDismiss).should('have.been.called')
6970
})
7071

71-
it.only('should handle focus properly in complex cases', () => {
72+
it('should handle focus properly in complex cases', () => {
7273
const Example = () => {
7374
const [showTray, setShowTray] = React.useState(false)
7475
const [showOverlay, setShowOverlay] = React.useState(false)

cypress/component/TruncateList.cy.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { expect } from 'chai'
2727

2828
import '../support/component'
2929
import 'cypress-real-events'
30+
import type { TruncateListProps } from '@instructure/ui-truncate-list'
3031

3132
describe('<TruncateList />', () => {
3233
it('should pass how many items should be visible with `onUpdate` prop', () => {
@@ -240,13 +241,17 @@ describe('<TruncateList />', () => {
240241
})
241242

242243
it('should resize list when fixMenuTriggerWidth changed in runtime', () => {
243-
const Example = ({ fixMenuTriggerWidth }) => {
244-
const [itemsCount, setItemsCount] = useState(Number)
244+
const Example = ({
245+
fixMenuTriggerWidth
246+
}: {
247+
fixMenuTriggerWidth: TruncateListProps['fixMenuTriggerWidth']
248+
}) => {
249+
const [itemsCount, setItemsCount] = useState(0)
245250

246251
return (
247252
<TruncateList
248253
fixMenuTriggerWidth={fixMenuTriggerWidth}
249-
onUpdate={({ visibleItemsCount }) => {
254+
onUpdate={({ visibleItemsCount }: { visibleItemsCount: number }) => {
250255
setItemsCount(visibleItemsCount)
251256
}}
252257
visibleItemsCount={itemsCount}

0 commit comments

Comments
 (0)