Skip to content

Commit 2dbb9fe

Browse files
committed
test(ui-range-input): migrate old RangeInput tests
1 parent e37aee9 commit 2dbb9fe

File tree

9 files changed

+400
-413
lines changed

9 files changed

+400
-413
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2015 - present Instructure, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
import React from 'react'
25+
import { expect } from 'chai'
26+
import { RangeInput } from '@instructure/ui'
27+
28+
import '../support/component'
29+
import 'cypress-real-events'
30+
31+
describe('<RangeInput/>', () => {
32+
it('should update the value displayed', async () => {
33+
cy.mount(
34+
<RangeInput
35+
label="Opacity"
36+
name="opacity"
37+
max={100}
38+
min={0}
39+
defaultValue={50}
40+
/>
41+
)
42+
cy.get('input[name="opacity"]').as('rangeInput')
43+
cy.get('[class$="-rangeInput__value"]').as('output')
44+
45+
cy.get('@rangeInput').invoke('val', '30').trigger('input')
46+
47+
cy.get('@output').should('have.text', '30')
48+
})
49+
50+
it('should call the onChange prop', async () => {
51+
const onChange = cy.spy()
52+
53+
cy.mount(
54+
<RangeInput
55+
label="Opacity"
56+
name="opacity"
57+
max={100}
58+
min={0}
59+
defaultValue={50}
60+
onChange={onChange}
61+
/>
62+
)
63+
64+
cy.get('input[name="opacity"]').as('rangeInput')
65+
cy.get('@rangeInput').invoke('val', '30').trigger('input')
66+
67+
cy.wrap(onChange)
68+
.should('have.been.called')
69+
.then((spy) => {
70+
expect(spy.getCall(0).args[0]).to.equal('30')
71+
})
72+
})
73+
74+
it('should update the input value when the value prop is uncontrolled', async () => {
75+
cy.mount(
76+
<RangeInput
77+
label="Opacity"
78+
name="opacity"
79+
max={100}
80+
min={0}
81+
onChange={cy.spy()}
82+
defaultValue={50}
83+
/>
84+
)
85+
cy.get('input[name="opacity"]').as('rangeInput')
86+
cy.get('@rangeInput').should('have.value', '50')
87+
88+
cy.get('@rangeInput').realClick()
89+
cy.get('@rangeInput').realType('{rightarrow}')
90+
91+
cy.get('@rangeInput').should('have.value', '51')
92+
})
93+
94+
it('should not update the input value when the value prop is controlled', async () => {
95+
cy.mount(
96+
<RangeInput
97+
label="Opacity"
98+
name="opacity"
99+
max={100}
100+
min={0}
101+
onChange={cy.spy()}
102+
value={50}
103+
/>
104+
)
105+
cy.get('input[name="opacity"]').as('rangeInput')
106+
cy.get('@rangeInput').should('have.value', '50')
107+
108+
cy.get('@rangeInput').realClick()
109+
cy.get('@rangeInput').realType('{rightarrow}')
110+
111+
cy.get('@rangeInput').should('have.value', '50')
112+
})
113+
114+
it('should show messages', async () => {
115+
const message = 'Invalid'
116+
117+
cy.mount(
118+
<RangeInput
119+
label="Opacity"
120+
name="opacity"
121+
max={100}
122+
min={0}
123+
messages={[{ text: message, type: 'error' }]}
124+
/>
125+
)
126+
cy.get('[class$="-formFieldMessages"]').should('contain.text', message)
127+
})
128+
})

package-lock.json

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

packages/ui-range-input/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@
4040
"prop-types": "^15.8.1"
4141
},
4242
"devDependencies": {
43+
"@instructure/ui-axe-check": "10.11.0",
4344
"@instructure/ui-babel-preset": "10.11.0",
44-
"@instructure/ui-test-locator": "10.11.0",
45+
"@instructure/ui-themes": "10.11.0",
4546
"@instructure/ui-test-utils": "10.11.0",
46-
"@instructure/ui-themes": "10.11.0"
47+
"@testing-library/jest-dom": "^6.6.3",
48+
"@testing-library/react": "^16.0.1",
49+
"vitest": "^2.1.8"
4750
},
4851
"peerDependencies": {
4952
"react": ">=16.14 <=18"

packages/ui-range-input/src/RangeInput/RangeInputLocator.ts

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

0 commit comments

Comments
 (0)