forked from antonioru/beautiful-react-diagrams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkColorProp.js
39 lines (30 loc) · 1.16 KB
/
checkColorProp.js
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
import React from 'react';
import { render } from '@testing-library/react';
import { expect } from 'chai';
const defaultOptions = {
colorProp: 'color',
defaultColor: 'default',
defaultColorClass: 'default',
checkColor: 'primary',
checkColorClass: 'primary',
};
/* eslint-disable no-unused-expressions */
const checkColorProp = (Component, defaultProps = {}, options = defaultOptions, elementQuery = null) => {
const opts = { ...defaultOptions, ...options };
const query = elementQuery || '* > *';
it('should allow to change color', () => {
const props = {
...defaultProps,
[opts.colorProp]: opts.defaultColor,
};
const { container, rerender } = render(<Component {...props} />);
const nodeEl = container.querySelector(query);
expect(nodeEl.classList.contains(opts.defaultColorClass)).to.be.true;
const nextProps = { [opts.colorProp]: opts.checkColor };
rerender(<Component {...nextProps} />);
expect(nodeEl.classList.contains(opts.checkColorClass)).to.be.true;
expect(nodeEl.classList.contains(opts.defaultColorClass)).to.be.false;
});
};
/* eslint-enable no-unused-expressions */
export default checkColorProp;