grafana/public/app/core/utils/shortLinks.test.ts
Ivana Huckova a0932f4d2a
Shorten url: Unification across Explore and Dashboards (#28434)
* WIP: Unify short url for dashboards and explore

* Add tests

* Update

* Address feedback, move createShortUrl to buildUrl
2020-10-22 10:31:58 +02:00

30 lines
776 B
TypeScript

import { createShortLink, createAndCopyShortLink } from './shortLinks';
jest.mock('@grafana/runtime', () => ({
getBackendSrv: () => {
return {
post: () => {
return Promise.resolve({ url: 'www.short.com' });
},
};
},
config: {
appSubUrl: '',
},
}));
describe('createShortLink', () => {
it('creates short link', async () => {
const shortUrl = await createShortLink('www.verylonglinkwehavehere.com');
expect(shortUrl).toBe('www.short.com');
});
});
describe('createAndCopyShortLink', () => {
it('copies short link to clipboard', async () => {
document.execCommand = jest.fn();
await createAndCopyShortLink('www.verylonglinkwehavehere.com');
expect(document.execCommand).toHaveBeenCalledWith('copy');
});
});