Skip to content

Commit cf3f025

Browse files
committed
test(ui-i18n): migrate old i18n tests
1 parent fed526c commit cf3f025

File tree

9 files changed

+426
-89
lines changed

9 files changed

+426
-89
lines changed

packages/ui-i18n/src/__tests__/getTextDirection.test.tsx renamed to cypress/component/i18n.cy.tsx

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2018 - present Instructure, Inc.
4+
* Copyright (c) 2015 - present Instructure, Inc.
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -21,43 +21,57 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
import { getTextDirection } from '@instructure/ui'
25+
import '../support/component'
26+
import 'cypress-real-events'
2427

25-
import { expect, mount } from '@instructure/ui-test-utils'
26-
import { getTextDirection } from '../getTextDirection'
27-
28-
describe('getTextDirection', async () => {
28+
describe('getTextDirection', () => {
2929
it('defaults the dir of <html>', async () => {
30-
expect(getTextDirection()).to.equal(
31-
document.documentElement.getAttribute('dir')
32-
)
30+
const expectedDir = getComputedStyle(document.documentElement).direction
31+
const actualDir = getTextDirection()
32+
33+
expect(actualDir).to.equal(expectedDir)
3334
})
3435

3536
it('defaults to the dir of <html> when passed an element', async () => {
36-
const subject = await mount(
37-
<div>
37+
cy.mount(
38+
<div data-testid="test">
3839
<h1>Hello</h1>
3940
</div>
4041
)
41-
expect(getTextDirection(subject.getDOMNode())).to.equal('ltr')
42+
43+
cy.get('[data-testid="test"]').then(($el) => {
44+
const actualDir = getTextDirection($el[0])
45+
46+
expect(actualDir).to.equal('ltr')
47+
})
4248
})
4349

4450
it('returns "rtl" if the `dir` of the element is "rtl"', async () => {
45-
const subject = await mount(
46-
<div dir="rtl">
51+
cy.mount(
52+
<div data-testid="test" dir="rtl">
4753
<h1>Hello</h1>
4854
</div>
4955
)
50-
expect(getTextDirection(subject.getDOMNode())).to.equal('rtl')
56+
57+
cy.get('[data-testid="test"]').then(($el) => {
58+
const actualDir = getTextDirection($el[0])
59+
60+
expect(actualDir).to.equal('rtl')
61+
})
5162
})
5263

5364
it('inherits value set by ancestor', async () => {
54-
const subject = await mount(
55-
<div dir="rtl">
65+
cy.mount(
66+
<div data-testid="test" dir="rtl">
5667
<h1>Hello</h1>
5768
</div>
5869
)
59-
expect(
60-
getTextDirection(subject.getDOMNode().firstChild as Element)
61-
).to.equal('rtl')
70+
71+
cy.get('h1').then(($el) => {
72+
const actualDir = getTextDirection($el[0])
73+
74+
expect(actualDir).to.equal('rtl')
75+
})
6276
})
6377
})

package-lock.json

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

0 commit comments

Comments
 (0)