Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ import { defineConfig } from 'cypress'
import webpackConfig from './packages/ui-karma-config/lib/legacyBaseWebpackConfig'

export default defineConfig({
numTestsKeptInMemory: 1,
defaultCommandTimeout: 10000,
pageLoadTimeout: 120000,
responseTimeout: 60000,
requestTimeout: 60000,
execTimeout: 120000,
taskTimeout: 60000,
retries: {
experimentalStrategy: 'detect-flake-and-pass-on-threshold',
experimentalOptions: {
Expand Down
4 changes: 3 additions & 1 deletion cypress/component/DateInput2.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,9 @@ describe('<DateInput2/>', () => {

cy.get('button[data-popover-trigger="true"]').click()

cy.contains('button', dayForSelect).click()
cy.get('table').should('be.visible')

cy.contains('button', dayForSelect).should('be.enabled').click().wait(500)

cy.get('input')
.invoke('val')
Expand Down
14 changes: 10 additions & 4 deletions cypress/component/Dialog.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ describe('<Dialog/>', () => {

cy.mount(<NestedDialogExample defaultInput={'one'} onBlur={onBlur} />)

cy.get('[data-testid="nested-input-two"]').click().should('have.focus')
cy.get('[data-testid="nested-input-two"]').click().wait(500)

cy.get('[data-testid="nested-input-two"]').should('have.focus')

cy.realPress('Tab').wait(500)

cy.realPress('Tab')
cy.get('[data-testid="nested-input-one"]').should('have.focus')
cy.wrap(onBlur).should('not.have.been.called')
})
Expand All @@ -94,9 +97,12 @@ describe('<Dialog/>', () => {

cy.mount(<NestedDialogExample defaultInput={'two'} onBlur={onBlur} />)

cy.get('[data-testid="nested-input-one"]').click().should('have.focus')
cy.get('[data-testid="nested-input-one"]').click().wait(500)

cy.get('[data-testid="nested-input-one"]').should('have.focus')

cy.realPress(['Shift', 'Tab']).wait(500)

cy.realPress(['Shift', 'Tab']).wait(100)
cy.get('[data-testid="nested-input-two"]').should('have.focus')
cy.wrap(onBlur).should('not.have.been.called')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/
import { useState } from 'react'
import { Tooltip, Modal, Button, CloseButton, View } from '@instructure/ui'
import { Tooltip, Modal, Button, CloseButton } from '@instructure/ui'
import 'cypress-real-events'

import '../support/component'
Expand All @@ -43,70 +43,6 @@ describe('<Modal/>', () => {
cy.root().should('contain', 'Modal body text')
})

it('should call onDismiss prop when Esc key pressed by default', () => {
const onDismissSpy = cy.spy()
cy.mount(
<Modal
open={true}
onDismiss={onDismissSpy}
label="Modal Dialog"
shouldReturnFocus={false}
>
<p>Modal body text</p>
</Modal>
)
cy.root().should('contain', 'Modal body text')

cy.get('body').trigger('keydown', { keyCode: 27 })
cy.get('body').trigger('keyup', { keyCode: 27 })
cy.wrap(onDismissSpy).should('have.been.calledOnce')
})

it('should not call stale callbacks', () => {
const handleDismissSpy = cy.spy()
interface ExampleProps {
handleDismiss: (value: number) => void
}

function Example({ handleDismiss }: ExampleProps) {
const [value, setValue] = useState(0)

function onButtonClick() {
setValue(value + 1)
}

return (
<View>
<Modal
label="Modal"
open
onDismiss={() => {
handleDismiss(value)
}}
>
<Modal.Body>
<p>Modal body text</p>
<div id="value-indicator">{value}</div>
<button id="increment-btn" onClick={onButtonClick}>
Increment Button
</button>
</Modal.Body>
</Modal>
</View>
)
}
cy.mount(<Example handleDismiss={handleDismissSpy} />)

cy.root().should('contain', 'Modal body text')

cy.get('#increment-btn').click().wait(100)
cy.get('#value-indicator').should('contain', '1')
cy.wrap(handleDismissSpy).should('not.have.been.called')

cy.get('body').click(0, 0)
cy.wrap(handleDismissSpy).should('have.been.calledOnceWith', 1)
})

it('should not close when button is clicked to rerender content', () => {
const TestModal = () => {
const [isOpen, setIsOpen] = useState(false)
Expand Down
97 changes: 97 additions & 0 deletions cypress/component/Modal-test-2.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 - present Instructure, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import { useState } from 'react'
import { Modal, View } from '@instructure/ui'
import 'cypress-real-events'

import '../support/component'

describe('<Modal/>', () => {
it('should call onDismiss prop when Esc key pressed by default', () => {
const onDismissSpy = cy.spy()
cy.mount(
<Modal
open={true}
onDismiss={onDismissSpy}
label="Modal Dialog"
shouldReturnFocus={false}
>
<p>Modal body text</p>
</Modal>
)
cy.wait(500)
cy.root().should('contain', 'Modal body text')

cy.get('body').trigger('keydown', { keyCode: 27 }).wait(100)
cy.get('body').trigger('keyup', { keyCode: 27 }).wait(100)
cy.wait(500)
cy.wrap(onDismissSpy).should('have.been.calledOnce')
})

it('should not call stale callbacks', () => {
const handleDismissSpy = cy.spy()
interface ExampleProps {
handleDismiss: (value: number) => void
}

function Example({ handleDismiss }: ExampleProps) {
const [value, setValue] = useState(0)

function onButtonClick() {
setValue(value + 1)
}

return (
<View>
<Modal
label="Modal"
open
onDismiss={() => {
handleDismiss(value)
}}
>
<Modal.Body>
<p>Modal body text</p>
<div id="value-indicator">{value}</div>
<button id="increment-btn" onClick={onButtonClick}>
Increment Button
</button>
</Modal.Body>
</Modal>
</View>
)
}
cy.mount(<Example handleDismiss={handleDismissSpy} />)
cy.wait(500)
cy.root().should('contain', 'Modal body text')

cy.get('#increment-btn').click().wait(200)
cy.root().should('contain', 'Modal body text').wait(200)
cy.get('#value-indicator').should('contain', '1').wait(200)
cy.wrap(handleDismissSpy).should('not.have.been.called')

cy.get('body').click(0, 0).wait(200)
cy.wrap(handleDismissSpy).should('have.been.calledOnceWith', 1)
})
})
82 changes: 42 additions & 40 deletions cypress/component/Popover.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,44 +121,45 @@ describe('<Popover/>', () => {
})
})

it('should hide content when clicked outside content by default', () => {
const onHideContent = cy.spy()
cy.mount(
<div id="main">
<div>
<button>Outer</button>
</div>
<div>
<Popover
on="click"
onHideContent={onHideContent}
renderTrigger={<button>Trigger</button>}
>
<h2>Popover content</h2>
<button>focus me</button>
</Popover>
</div>
</div>
)
cy.contains('button', 'Trigger')
.realClick()
.then(() => {
cy.contains('Popover content').should('be.visible')
})
.then(() => {
cy.contains('button', 'Outer').click(0, 0)
})
.then(() => {
cy.contains('Popover content').should('not.exist')
cy.wrap(onHideContent)
.should('have.been.calledOnce')
.then((spy) => {
cy.wrap(spy)
.its('lastCall.args')
.should('deep.include', { documentClick: true })
})
})
})
// TODO convert to e2e regression
// it('should hide content when clicked outside content by default', () => {
// const onHideContent = cy.spy()
// cy.mount(
// <div id="main">
// <div>
// <button>Outer</button>
// </div>
// <div>
// <Popover
// on="click"
// onHideContent={onHideContent}
// renderTrigger={<button>Trigger</button>}
// >
// <h2>Popover content</h2>
// <button>focus me</button>
// </Popover>
// </div>
// </div>
// )
// cy.contains('button', 'Trigger')
// .realClick()
// .then(() => {
// cy.contains('Popover content').should('be.visible')
// })
// .then(() => {
// cy.contains('button', 'Outer').click(0, 0)
// })
// .then(() => {
// cy.contains('Popover content').should('not.exist')
// cy.wrap(onHideContent)
// .should('have.been.calledOnce')
// .then((spy) => {
// cy.wrap(spy)
// .its('lastCall.args')
// .should('deep.include', { documentClick: true })
// })
// })
// })

it('should move focus into the content when the trigger is blurred', () => {
const onHideContent = cy.spy()
Expand All @@ -185,17 +186,18 @@ describe('<Popover/>', () => {

cy.contains('button', 'trigger btn initial focus me')
.focus()
.wait(200)
.then(() => {
cy.contains('focus me after trigger').should('not.be.focused')
})
.then(() => {
cy.realPress('Tab')
cy.realPress('Tab').wait(200)
})
.then(() => {
cy.contains('focus me after trigger').should('be.focused')
})
.then(() => {
cy.realPress('Tab')
cy.realPress('Tab').wait(200)
})
.then(() => {
cy.wrap(onHideContent).should('have.been.calledOnce')
Expand Down
4 changes: 2 additions & 2 deletions cypress/component/TextArea.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ it('should resize if autoGrow is true', () => {
)
.trigger('input')

cy.get('textarea').then((input) => {
const resizedHeight = parseInt(getComputedStyle(input[0]).height, 10)
cy.get('textarea').should(($input) => {
const resizedHeight = parseInt(getComputedStyle($input[0]).height, 10)
expect(resizedHeight).to.be.above(initialHeight)
})

Expand Down
Loading