Skip to content

Commit

Permalink
test(ui-text-area): migrate old TextArea tests
Browse files Browse the repository at this point in the history
Closes: INSTUI-4166
  • Loading branch information
ToMESSKa committed Sep 13, 2024
1 parent 48f7c69 commit daece8f
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 350 deletions.
97 changes: 97 additions & 0 deletions cypress/component/TextArea.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 React from 'react'
import '../support/component'
import 'cypress-real-events'

import { TextArea } from '../../packages/ui'

it('should resize if autoGrow is true', () => {
cy.mount(
<TextArea label="Name" autoGrow={true} width="500px" onChange={cy.stub()} />
)

cy.get('textarea').then((input) => {
const initialHeight = parseInt(getComputedStyle(input[0]).height, 10)

cy.get('textarea')
.invoke(
'val',
'Chartreuse celiac thundercats, distillery snackwave glossier pork belly tacos venmo fanny pack paleo portland. Migas 3 wolf moon typewriter, meditation pitchfork meh narwhal copper mug gluten-free vegan next level. Succulents keytar cronut, fanny pack kitsch hammock sustainable skateboard gochujang poutine la croix ennui cred quinoa. Fap copper mug pitchfork small batch hell of vice. Kickstarter small batch hexagon, scenester bushwick tacos cliche. Pickled flannel PBR&B, chartreuse next level vinyl echo park chambray pitchfork selfies actually tattooed blue bottle 3 wolf moon. Raw denim enamel pin tumeric retro fam scenester.'
)
.trigger('input')

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

cy.get('[class$="-textArea__layout"]').then((layout) => {
const layoutMinHeight = parseInt(
getComputedStyle(layout[0]).getPropertyValue('min-height'),
10
)
cy.get('textarea').then((input) => {
const resizedHeight = parseInt(getComputedStyle(input[0]).height, 10)
expect(resizedHeight).to.equal(layoutMinHeight)
})
})
})
})

it('should set a maxHeight', () => {
cy.mount(
<TextArea
label="Name"
autoGrow={true}
maxHeight="160px"
onChange={cy.stub()}
value={`Chartreuse celiac thundercats, distillery snackwave glossier
pork belly tacos venmo fanny pack paleo portland. Migas 3 wolf moon typewriter,
meditation pitchfork meh narwhal copper mug gluten-free vegan next level.
Succulents keytar cronut, fanny pack kitsch hammock sustainable skateboard
gochujang poutine la croix ennui cred quinoa. Fap copper mug pitchfork small
batch hell of vice. Kickstarter small batch hexagon, scenester bushwick tacos
cliche. Pickled flannel PBR&B, chartreuse next level vinyl echo park chambray
pitchfork selfies actually tattooed blue bottle 3 wolf moon. Raw denim enamel
pin tumeric retro fam scenester. Succulents keytar cronut, fanny pack kitsch
hammock sustainable skateboard gochujang poutine la croix ennui cred quinoa.
Fap copper mug pitchfork small batch hell of vice. Kickstarter small batch
hexagon, scenester bushwick tacos`}
/>
)
const input = cy.get('textarea')

input.should('have.css', 'max-height', '160px')

// ensure maxHeight is being applied to input container and not exceeded by minHeight style
cy.get('[class$=-textArea__layout]').then((layout) => {
const layoutMaxHeight = parseInt(layout.css('max-height'), 10)
const layoutMinHeight = parseInt(layout.css('min-height'), 10)

expect(layoutMaxHeight).to.equal(160)
expect(layoutMaxHeight).to.be.above(layoutMinHeight)
})
})
60 changes: 58 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions packages/ui-text-area/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@
"prop-types": "^15.8.1"
},
"devDependencies": {
"@instructure/ui-axe-check": "10.2.1",
"@instructure/ui-babel-preset": "10.2.1",
"@instructure/ui-color-utils": "10.2.1",
"@instructure/ui-test-locator": "10.2.1",
"@instructure/ui-test-utils": "10.2.1",
"@instructure/ui-themes": "10.2.1"
"@instructure/ui-themes": "10.2.1",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.2",
"vitest": "^2.0.2"
},
"peerDependencies": {
"react": ">=16.8 <=18"
Expand Down
32 changes: 0 additions & 32 deletions packages/ui-text-area/src/TextArea/TextAreaLocator.ts

This file was deleted.

Loading

0 comments on commit daece8f

Please sign in to comment.