|
1 | 1 | /* |
2 | 2 | * The MIT License (MIT) |
3 | 3 | * |
4 | | - * Copyright (c) 2018 - present Instructure, Inc. |
| 4 | + * Copyright (c) 2015 - present Instructure, Inc. |
5 | 5 | * |
6 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | 7 | * of this software and associated documentation files (the "Software"), to deal |
|
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22 | 22 | * SOFTWARE. |
23 | 23 | */ |
| 24 | +import { getTextDirection } from '@instructure/ui' |
| 25 | +import '../support/component' |
| 26 | +import 'cypress-real-events' |
24 | 27 |
|
25 | | -import { expect, mount } from '@instructure/ui-test-utils' |
26 | | -import { getTextDirection } from '../getTextDirection' |
27 | | - |
28 | | -describe('getTextDirection', async () => { |
| 28 | +describe('getTextDirection', () => { |
29 | 29 | 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) |
33 | 34 | }) |
34 | 35 |
|
35 | 36 | 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"> |
38 | 39 | <h1>Hello</h1> |
39 | 40 | </div> |
40 | 41 | ) |
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 | + }) |
42 | 48 | }) |
43 | 49 |
|
44 | 50 | 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"> |
47 | 53 | <h1>Hello</h1> |
48 | 54 | </div> |
49 | 55 | ) |
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 | + }) |
51 | 62 | }) |
52 | 63 |
|
53 | 64 | 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"> |
56 | 67 | <h1>Hello</h1> |
57 | 68 | </div> |
58 | 69 | ) |
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 | + }) |
62 | 76 | }) |
63 | 77 | }) |
0 commit comments