2021-03-19 16:23:25 +08:00
|
|
|
import { SmileOutlined } from '@ant-design/icons';
|
|
|
|
import IconContext from '@ant-design/icons/lib/components/Context';
|
2022-06-22 14:57:09 +08:00
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import React from 'react';
|
2021-03-19 16:23:25 +08:00
|
|
|
import ConfigProvider from '..';
|
|
|
|
|
|
|
|
describe('ConfigProvider.Icon', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
// eslint-disable-next-line jest/no-standalone-expect
|
|
|
|
expect(document.querySelectorAll('style')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
document.querySelectorAll('style').forEach(style => {
|
|
|
|
style.parentNode.removeChild(style);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-03-08 14:01:53 +08:00
|
|
|
describe('csp', () => {
|
|
|
|
it('raw', () => {
|
|
|
|
mount(
|
|
|
|
<ConfigProvider csp={{ nonce: 'little' }}>
|
|
|
|
<SmileOutlined />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
2021-03-19 16:23:25 +08:00
|
|
|
|
2022-03-08 14:01:53 +08:00
|
|
|
const styleNode = document.querySelector('style');
|
|
|
|
expect(styleNode.nonce).toEqual('little');
|
|
|
|
});
|
2021-03-19 16:23:25 +08:00
|
|
|
|
2022-03-08 14:01:53 +08:00
|
|
|
it('mix with iconPrefixCls', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider iconPrefixCls="bamboo" csp={{ nonce: 'light' }}>
|
|
|
|
<SmileOutlined />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
const styleNode = document.querySelector('style');
|
|
|
|
|
|
|
|
expect(wrapper.exists('.bamboo-smile')).toBeTruthy();
|
|
|
|
expect(styleNode.nonce).toEqual('light');
|
|
|
|
});
|
2021-03-19 16:23:25 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('nest', () => {
|
|
|
|
const Checker = () => {
|
|
|
|
const { csp } = React.useContext(IconContext);
|
|
|
|
return <div id="csp">{csp.nonce}</div>;
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider iconPrefixCls="bamboo" csp={{ nonce: 'light' }}>
|
|
|
|
<ConfigProvider>
|
|
|
|
<SmileOutlined />
|
|
|
|
<Checker />
|
|
|
|
</ConfigProvider>
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
const styleNode = document.querySelector('style');
|
|
|
|
|
|
|
|
expect(wrapper.exists('.bamboo-smile')).toBeTruthy();
|
|
|
|
expect(styleNode.nonce).toEqual('light');
|
|
|
|
expect(wrapper.find('#csp').text()).toEqual('light');
|
|
|
|
});
|
|
|
|
});
|