forked from react-bootstrap/react-bootstrap
/
RatioSpec.tsx
62 lines (55 loc) · 1.97 KB
/
RatioSpec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { render } from '@testing-library/react';
import Ratio from '../src/Ratio';
describe('Ratio', () => {
it('should contain `ratio-1x1` and custom class', () => {
const { getByTestId } = render(
<Ratio data-testid="test" aspectRatio="1x1" className="custom-class">
<div />
</Ratio>,
);
const ratioElem = getByTestId('test');
ratioElem.classList.contains('custom-class').should.be.true;
ratioElem.classList.contains('ratio').should.be.true;
ratioElem.classList.contains('ratio-1x1').should.be.true;
});
it('should support custom ratios using percent for aspectRatio', () => {
const { getByTestId } = render(
<Ratio data-testid="test" aspectRatio={50}>
<div />
</Ratio>,
);
const ratioElem = getByTestId('test');
const styleAttr = ratioElem.getAttribute('style')!;
styleAttr.should.match(/--bs-aspect-ratio:[ ]*50%;/);
});
it('should support custom ratios using fraction for aspectRatio', () => {
const { getByTestId } = render(
<Ratio data-testid="test" aspectRatio={1 / 2}>
<div />
</Ratio>,
);
const ratioElem = getByTestId('test');
const styleAttr = ratioElem.getAttribute('style')!;
styleAttr.should.match(/--bs-aspect-ratio:[ ]*50%;/);
});
it('should support use 100% as custom ratio if aspectRatio is less than 0', () => {
const { getByTestId } = render(
<Ratio data-testid="test" aspectRatio={-1}>
<div />
</Ratio>,
);
const ratioElem = getByTestId('test');
const styleAttr = ratioElem.getAttribute('style')!;
styleAttr.should.match(/--bs-aspect-ratio:[ ]*100%;/);
});
it('should support aspectRatio greater than 100', () => {
const { getByTestId } = render(
<Ratio data-testid="test" aspectRatio={200}>
<div />
</Ratio>,
);
const ratioElem = getByTestId('test');
const styleAttr = ratioElem.getAttribute('style')!;
styleAttr.should.match(/--bs-aspect-ratio:[ ]*200%;/);
});
});