2020-02-07 17:55:27 +08:00
|
|
|
/* eslint-disable jsx-a11y/control-has-associated-label */
|
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import notification from '..';
|
|
|
|
import ConfigProvider from '../../config-provider';
|
|
|
|
|
|
|
|
describe('notification.hooks', () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
notification.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work', () => {
|
|
|
|
const Context = React.createContext('light');
|
|
|
|
|
|
|
|
const Demo = () => {
|
|
|
|
const [api, holder] = notification.useNotification();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ConfigProvider prefixCls="my-test">
|
|
|
|
<Context.Provider value="bamboo">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => {
|
|
|
|
api.open({
|
|
|
|
description: (
|
|
|
|
<Context.Consumer>
|
|
|
|
{name => <span className="hook-test-result">{name}</span>}
|
|
|
|
</Context.Consumer>
|
|
|
|
),
|
|
|
|
duration: 0,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{holder}
|
|
|
|
</Context.Provider>
|
|
|
|
</ConfigProvider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = mount(<Demo />);
|
|
|
|
wrapper.find('button').simulate('click');
|
|
|
|
expect(document.querySelectorAll('.my-test-notification-notice').length).toBe(1);
|
|
|
|
expect(document.querySelector('.hook-test-result').innerHTML).toEqual('bamboo');
|
|
|
|
});
|
2020-05-21 10:36:18 +08:00
|
|
|
|
|
|
|
it('should be same hook', () => {
|
|
|
|
let count = 0;
|
|
|
|
|
|
|
|
const Demo = () => {
|
|
|
|
const [, forceUpdate] = React.useState({});
|
|
|
|
const [api] = notification.useNotification();
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
count += 1;
|
|
|
|
expect(count).toEqual(1);
|
|
|
|
forceUpdate();
|
|
|
|
}, [api]);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
mount(<Demo />);
|
|
|
|
});
|
2020-02-07 17:55:27 +08:00
|
|
|
});
|