2018-09-18 15:43:46 -04:00
|
|
|
import findAndFollowLink from '~/lib/utils/navigation_utility';
|
2018-04-13 11:45:26 -04:00
|
|
|
|
|
|
|
describe('findAndFollowLink', () => {
|
|
|
|
it('visits a link when the selector exists', () => {
|
|
|
|
const href = '/some/path';
|
2018-04-16 14:40:30 -04:00
|
|
|
const visitUrl = spyOnDependency(findAndFollowLink, 'visitUrl');
|
2018-04-13 11:45:26 -04:00
|
|
|
|
|
|
|
setFixtures(`<a class="my-shortcut" href="${href}">link</a>`);
|
|
|
|
|
|
|
|
findAndFollowLink('.my-shortcut');
|
|
|
|
|
2018-04-16 14:40:30 -04:00
|
|
|
expect(visitUrl).toHaveBeenCalledWith(href);
|
2018-04-13 11:45:26 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not throw an exception when the selector does not exist', () => {
|
2018-04-16 14:40:30 -04:00
|
|
|
const visitUrl = spyOnDependency(findAndFollowLink, 'visitUrl');
|
2018-04-13 11:45:26 -04:00
|
|
|
|
|
|
|
// this should not throw an exception
|
|
|
|
findAndFollowLink('.this-selector-does-not-exist');
|
|
|
|
|
2018-04-16 14:40:30 -04:00
|
|
|
expect(visitUrl).not.toHaveBeenCalled();
|
2018-04-13 11:45:26 -04:00
|
|
|
});
|
|
|
|
});
|