add follow tests

jh-changes
Shin'ya Ueoka 7 years ago
parent d4d54ca496
commit c50f463bc1
  1. 16
      src/content/follow.js
  2. 9
      test/content/follow.html
  3. 11
      test/content/follow.test.js

@ -105,6 +105,20 @@ export default class Follow {
}
static getTargetElements(doc) {
return doc.querySelectorAll('a')
let all = doc.querySelectorAll('a');
let filtered = Array.prototype.filter.call(all, (e) => {
return Follow.isVisibleElement(e);
});
return filtered;
}
static isVisibleElement(element) {
var style = window.getComputedStyle(element);
if (style.display === 'none') {
return false;
} else if (style.visibility === 'hidden') {
return false;
}
return true;
}
}

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<body>
<a href='#' >link</a>
<a href='#' style='display:none'>invisible 1</a>
<a href='#' style='visibility:hidden'>invisible 2</a>
<i>not link<i>
</body>
</html>

@ -11,4 +11,15 @@ describe('Follow class', () => {
expect(Follow.codeChars([])).to.be.equal('');
});
});
describe('#getTargetElements', () => {
beforeEach(() => {
document.body.innerHTML = __html__['test/content/follow.html'];
});
it('returns visible links', () => {
let links = Follow.getTargetElements(window.document);
expect(links).to.have.lengthOf(1);
});
});
});