2020-08-30 10:59:14 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2021-09-24 20:10:03 +03:00
|
|
|
import { DropdownItem } from 'reactstrap';
|
2020-08-30 10:59:14 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2019-01-13 15:08:47 +03:00
|
|
|
import createShortUrlsRowMenu from '../../../src/short-urls/helpers/ShortUrlsRowMenu';
|
2020-08-30 10:59:14 +03:00
|
|
|
import { ReachableServer } from '../../../src/servers/data';
|
|
|
|
import { ShortUrl } from '../../../src/short-urls/data';
|
2021-09-24 20:10:03 +03:00
|
|
|
import { DropdownBtnMenu } from '../../../src/utils/DropdownBtnMenu';
|
2019-01-13 15:08:47 +03:00
|
|
|
|
|
|
|
describe('<ShortUrlsRowMenu />', () => {
|
2020-08-30 10:59:14 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
|
|
|
const DeleteShortUrlModal = () => null;
|
2021-01-24 19:37:31 +03:00
|
|
|
const QrCodeModal = () => null;
|
2020-08-30 10:59:14 +03:00
|
|
|
const selectedServer = Mock.of<ReachableServer>({ id: 'abc123' });
|
|
|
|
const shortUrl = Mock.of<ShortUrl>({
|
2019-01-13 15:08:47 +03:00
|
|
|
shortCode: 'abc123',
|
|
|
|
shortUrl: 'https://doma.in/abc123',
|
2020-08-30 10:59:14 +03:00
|
|
|
});
|
2020-01-28 21:46:36 +03:00
|
|
|
const createWrapper = () => {
|
2021-03-27 12:49:23 +03:00
|
|
|
const ShortUrlsRowMenu = createShortUrlsRowMenu(DeleteShortUrlModal, QrCodeModal);
|
2019-01-13 15:08:47 +03:00
|
|
|
|
2020-08-30 10:59:14 +03:00
|
|
|
wrapper = shallow(<ShortUrlsRowMenu selectedServer={selectedServer} shortUrl={shortUrl} />);
|
2019-01-13 15:08:47 +03:00
|
|
|
|
2020-01-11 16:12:58 +03:00
|
|
|
return wrapper;
|
|
|
|
};
|
|
|
|
|
2020-08-30 10:59:14 +03:00
|
|
|
afterEach(() => wrapper?.unmount());
|
2019-01-13 15:08:47 +03:00
|
|
|
|
|
|
|
it('renders modal windows', () => {
|
2020-01-11 16:12:58 +03:00
|
|
|
const wrapper = createWrapper();
|
2019-01-13 15:08:47 +03:00
|
|
|
const deleteShortUrlModal = wrapper.find(DeleteShortUrlModal);
|
|
|
|
const qrCodeModal = wrapper.find(QrCodeModal);
|
|
|
|
|
|
|
|
expect(deleteShortUrlModal).toHaveLength(1);
|
|
|
|
expect(qrCodeModal).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
2020-01-28 21:46:36 +03:00
|
|
|
it('renders correct amount of menu items', () => {
|
|
|
|
const wrapper = createWrapper();
|
2019-01-13 15:08:47 +03:00
|
|
|
const items = wrapper.find(DropdownItem);
|
|
|
|
|
2021-03-27 12:49:23 +03:00
|
|
|
expect(items).toHaveLength(5);
|
2020-03-06 23:22:07 +03:00
|
|
|
expect(items.find('[divider]')).toHaveLength(1);
|
2019-01-13 15:08:47 +03:00
|
|
|
});
|
|
|
|
|
2020-08-30 10:59:14 +03:00
|
|
|
describe('toggles state when toggling modals or the dropdown', () => {
|
|
|
|
const assert = (modalComponent: Function) => {
|
2020-01-11 16:12:58 +03:00
|
|
|
const wrapper = createWrapper();
|
2019-01-13 15:08:47 +03:00
|
|
|
|
2020-03-30 22:01:01 +03:00
|
|
|
expect(wrapper.find(modalComponent).prop('isOpen')).toEqual(false);
|
2021-02-28 19:43:41 +03:00
|
|
|
(wrapper.find(modalComponent).prop('toggle') as Function)();
|
2020-03-30 22:01:01 +03:00
|
|
|
expect(wrapper.find(modalComponent).prop('isOpen')).toEqual(true);
|
2019-01-13 15:08:47 +03:00
|
|
|
};
|
|
|
|
|
2020-03-30 22:01:01 +03:00
|
|
|
it('DeleteShortUrlModal', () => assert(DeleteShortUrlModal));
|
|
|
|
it('QrCodeModal', () => assert(QrCodeModal));
|
2021-09-24 20:10:03 +03:00
|
|
|
it('ShortUrlRowMenu', () => assert(DropdownBtnMenu));
|
2019-01-13 15:08:47 +03:00
|
|
|
});
|
|
|
|
});
|