import { resolveCaptureUrl } from './captureUrl';

describe('resolveCaptureUrl', () => {
  test('reads the bookmarklet add param', () => {
    expect(resolveCaptureUrl('?add=https%3A%2F%2Fexample.com%2Fjob')).toBe('https://example.com/job');
  });

  test('extracts a url embedded in shared text', () => {
    expect(resolveCaptureUrl('?addtext=' + encodeURIComponent('Cool role here https://example.com/job/42 apply now')))
      .toBe('https://example.com/job/42');
  });

  test('prefers add over addtext', () => {
    expect(resolveCaptureUrl('?add=https%3A%2F%2Fa.com&addtext=' + encodeURIComponent('https://b.com')))
      .toBe('https://a.com');
  });

  test('returns null when there is no url', () => {
    expect(resolveCaptureUrl('')).toBeNull();
    expect(resolveCaptureUrl('?addtext=' + encodeURIComponent('just some text, no link'))).toBeNull();
  });
});
