mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
* WIP: Unify short url for dashboards and explore * Add tests * Update * Address feedback, move createShortUrl to buildUrl
30 lines
776 B
TypeScript
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');
|
|
});
|
|
});
|