diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-08-21 21:01:29 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-08-21 21:32:02 +0900 |
commit | c50f463bc12da7e3a5de490b714b4ff1ea8d3e56 (patch) | |
tree | b0b731a8bbc00fb2c330497c3c088f506a08dd57 | |
parent | d4d54ca4963ef4de3e913746cdee87656dc02229 (diff) |
add follow tests
-rw-r--r-- | src/content/follow.js | 16 | ||||
-rw-r--r-- | test/content/follow.html | 9 | ||||
-rw-r--r-- | test/content/follow.test.js | 11 |
3 files changed, 35 insertions, 1 deletions
diff --git a/src/content/follow.js b/src/content/follow.js index c0b7a44..d678351 100644 --- a/src/content/follow.js +++ b/src/content/follow.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; } } diff --git a/test/content/follow.html b/test/content/follow.html new file mode 100644 index 0000000..6bd8f87 --- /dev/null +++ b/test/content/follow.html @@ -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> diff --git a/test/content/follow.test.js b/test/content/follow.test.js index eb3d679..fd4f0bc 100644 --- a/test/content/follow.test.js +++ b/test/content/follow.test.js @@ -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); + }); + }); }); |