all files / js/ mail.deobfuscate.module.test.js

100% Statements 31/31
100% Branches 0/0
100% Functions 6/6
100% Lines 31/31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                                 
import mailDeobfuscate from './mail.deobfuscate.module';
 
describe('mailDeobfuscate module', () => {
  it('mailDeobfuscate is function', () => {
    expect(typeof mailDeobfuscate).toBe('function');
  });
 
  it('deobfuscated mailto href is mail@example.org', () => {
    let markup =
      '<a href="mailto:znvy@rknzcyr.bet" title="mail to">' +
        'with obfuscated mail address in href' +
      '</a>';
    document.body.insertAdjacentHTML('afterbegin', markup);
    let element = document.querySelector('a');
    mailDeobfuscate(element);
    expect(element.href).toBe('mailto:mail@example.org');
    document.body.removeChild(element);
  });
 
  it('deobfuscated href is http://www.example.org/', () => {
    let markup = '<a href="http://www.example.org/" title="mail to znvy@rknzcyr.bet">with obfuscated mail address in title</a>';
    document.body.insertAdjacentHTML('afterbegin', markup);
    let element = document.querySelector('a');
    mailDeobfuscate(element);
    expect(element.href).toBe('http://www.example.org/');
    document.body.removeChild(element);
  });
 
  it('deobfuscated title is mail@example.org', () => {
    let markup =
      '<a href="mailto:znvy@rknzcyr.bet" title="mail to znvy@rknzcyr.bet">' +
        'with obfuscated mail address in href and title' +
      '</a>';
    document.body.insertAdjacentHTML('afterbegin', markup);
    let element = document.querySelector('a');
    mailDeobfuscate(element);
    expect(element.title).toBe('mail to mail@example.org');
    document.body.removeChild(element);
  });
 
  it('deobfuscated text is mail@example.org', () => {
    let markup =
      '<a href="mailto:znvy@rknzcyr.bet" title="mail to znvy@rknzcyr.bet">' +
        'znvy@rknzcyr.bet with obfuscated ' +
        'mail address in href, title and text' +
      '</a>';
    document.body.insertAdjacentHTML('afterbegin', markup);
    let element = document.querySelector('a');
    mailDeobfuscate(element);
    expect(element.text).toBe(
      'mail@example.org with obfuscated mail address in href, title and text'
    );
    document.body.removeChild(element);
  });
});