2020-08-30 10:59:14 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2020-01-15 20:16:12 +03:00
|
|
|
import { ExternalLink } from 'react-external-link';
|
2021-01-21 18:51:54 +03:00
|
|
|
import { ModalHeader } from 'reactstrap';
|
2020-08-30 10:59:14 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2018-11-01 14:35:51 +03:00
|
|
|
import QrCodeModal from '../../../src/short-urls/helpers/QrCodeModal';
|
2020-08-30 10:59:14 +03:00
|
|
|
import { ShortUrl } from '../../../src/short-urls/data';
|
2021-01-21 18:51:54 +03:00
|
|
|
import { ReachableServer } from '../../../src/servers/data';
|
2018-11-01 14:35:51 +03:00
|
|
|
|
|
|
|
describe('<QrCodeModal />', () => {
|
2020-08-30 10:59:14 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
|
|
|
const shortUrl = 'https://doma.in/abc123';
|
2021-01-21 18:51:54 +03:00
|
|
|
const createWrapper = (version = '2.5.0') => {
|
|
|
|
const selectedServer = Mock.of<ReachableServer>({ version });
|
2018-11-01 14:35:51 +03:00
|
|
|
|
2021-01-21 18:51:54 +03:00
|
|
|
wrapper = shallow(
|
|
|
|
<QrCodeModal
|
|
|
|
shortUrl={Mock.of<ShortUrl>({ shortUrl })}
|
|
|
|
isOpen={true}
|
|
|
|
toggle={() => {}}
|
|
|
|
selectedServer={selectedServer}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => wrapper?.unmount());
|
2018-11-01 14:35:51 +03:00
|
|
|
|
2021-01-21 18:51:54 +03:00
|
|
|
it('shows an external link to the URL in the header', () => {
|
|
|
|
const wrapper = createWrapper();
|
|
|
|
const externalLink = wrapper.find(ModalHeader).find(ExternalLink);
|
2018-11-01 14:35:51 +03:00
|
|
|
|
|
|
|
expect(externalLink).toHaveLength(1);
|
2020-08-30 10:59:14 +03:00
|
|
|
expect(externalLink.prop('href')).toEqual(shortUrl);
|
2018-11-01 14:35:51 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays an image with the QR code of the URL', () => {
|
2021-01-21 18:51:54 +03:00
|
|
|
const wrapper = createWrapper();
|
2018-11-01 14:35:51 +03:00
|
|
|
const img = wrapper.find('img');
|
|
|
|
|
|
|
|
expect(img).toHaveLength(1);
|
2020-08-30 10:59:14 +03:00
|
|
|
expect(img.prop('src')).toEqual(`${shortUrl}/qr-code`);
|
2018-11-01 14:35:51 +03:00
|
|
|
});
|
|
|
|
});
|