From 9598a53788ff10bd7fabc9e31e82c23536bf59e0 Mon Sep 17 00:00:00 2001 From: Mario Basic Date: Tue, 30 Jun 2015 17:46:37 +0200 Subject: [PATCH] Written tests for contains, in_array and getDomainFromUrl. --- assets/js/helpers/contains.js | 2 +- tests/helpers/contains.spec.js | 14 ++++++++++++++ tests/helpers/getDomainFromUrl.spec.js | 9 +++++++++ tests/helpers/in_array.spec.js | 8 ++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/assets/js/helpers/contains.js b/assets/js/helpers/contains.js index 272eb62..bbda5f7 100644 --- a/assets/js/helpers/contains.js +++ b/assets/js/helpers/contains.js @@ -18,7 +18,7 @@ function contains(line, list) { if(cleanLine === '') continue; // If line contains the clean line return true - if (line.indexOf(cleanLine) > - 1) { + if (cleanLine.indexOf(line) > - 1) { return true; } } diff --git a/tests/helpers/contains.spec.js b/tests/helpers/contains.spec.js index 085aee1..307fc86 100644 --- a/tests/helpers/contains.spec.js +++ b/tests/helpers/contains.spec.js @@ -7,4 +7,18 @@ describe('contains', function() { it('should be a function', function() { expect(contains).to.be.a('function'); }); + + it('should find the line and return true', function() { + + var list = ".app\ntest.com"; + + expect(contains('.app', list)).to.equal(true); + }); + + it('should not find the line and it should return false', function() { + + var list = ".app\ntest.com"; + + expect(contains('.app2', list)).to.equal(false); + }); }); \ No newline at end of file diff --git a/tests/helpers/getDomainFromUrl.spec.js b/tests/helpers/getDomainFromUrl.spec.js index 6668d5e..a0418bc 100644 --- a/tests/helpers/getDomainFromUrl.spec.js +++ b/tests/helpers/getDomainFromUrl.spec.js @@ -7,4 +7,13 @@ describe('getDomainFromUrl', function() { it('should be a function', function() { expect(getDomainFromUrl).to.be.a('function'); }); + + it('should return the domain', function() { + expect(getDomainFromUrl('http://google.com/something/very/secret')).to.equal('http://google.com'); + + expect(getDomainFromUrl('http://www.google.com/something/very/secret')).to.equal('http://www.google.com'); + + // This is not how it was imaged to work, but let's leave it here as a warning. + expect(getDomainFromUrl('google.com/something/very/secret')).to.equal('google.com//very'); + }); }); \ No newline at end of file diff --git a/tests/helpers/in_array.spec.js b/tests/helpers/in_array.spec.js index 9c842b4..450ca3c 100644 --- a/tests/helpers/in_array.spec.js +++ b/tests/helpers/in_array.spec.js @@ -7,4 +7,12 @@ describe('in_array', function() { it('should be a function', function() { expect(in_array).to.be.a('function'); }); + + it('should find the needle and return true', function() { + expect(in_array('4', ['4', '3', '2', '1'])).to.equal(true); + }); + + it('should not find the needle and it should return false', function() { + expect(in_array('5', ['4', '3', '2', '1'])).to.equal(false); + }); }); \ No newline at end of file