Skip to content
This repository has been archived by the owner on Apr 1, 2019. It is now read-only.

Commit

Permalink
Adding some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina Samuel committed Nov 24, 2015
1 parent b2fd8d3 commit 268dae0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
// Filter blocked and pinned links and duplicate base domains.
links = links.filter(function(link) {
let site = ProviderManager.extractSite(link.url);
if (site === null || sites.has(site)) {
if (!site || sites.has(site)) {
return false;
}
sites.add(site);
Expand Down
6 changes: 6 additions & 0 deletions src/test/directoryLinksProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ describe("DirectoryLinksProvider API", function() {
it("should escape chars", function() {
assert.equal("&lt;test&gt;", DirectoryLinksProvider._escapeChars("<test>"));
});

it("should not cache links that don't have frecent_sites", function() {
DirectoryLinksProvider._suggestedLinks.clear();
DirectoryLinksProvider._cacheSuggestedLinks(directoryLinks.directory[0]);
assert.equal(DirectoryLinksProvider._suggestedLinks.size, 0);
});
});
1 change: 1 addition & 0 deletions src/test/directoryLinksWithAdgroup.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"directoryId": 2,
"title": "Private Browsing with Tracking Protection",
"type": "affiliate",
"enhancedImageURI": "pretendThisIsAnImage",
"url": "https://www.mozilla.org/firefox/private-browsing/?utm_source=directory-tiles&utm_medium=tiles&utm_content=TPV1&utm_campaign=fx-fall-15"
}],
"suggested": [{
Expand Down
23 changes: 23 additions & 0 deletions src/test/links_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ describe("Links API", function() {
"url": "http://www.test2.com/",
"frecency": 101,
"lastVisitDate": Date.now()
},
{
"title": "Test3",
"type": "history",
"url": "meep.www.test2.com/",
"frecency": 102,
"lastVisitDate": Date.now()
}
];

Expand All @@ -45,8 +52,24 @@ describe("Links API", function() {
// There are 6 links: 2 directory, 2 places, and 2 pinned
assert.equal(links.links.length, 6);

// A forced cache populate should have the same results.
yield Links.populateCache({force: true});
links = yield Links.getLinks();
assert.equal(links.links.length, 6);

// Unpin links.
yield gPinnedLinks.unpin(firstLink);
yield gPinnedLinks.unpin(secondLink);
}));

it("should throw if links don't have required attributes", function() {
expect(() => Links.compareLinks(firstLink, secondLink)).to.throw(Error);
});

it("should not increment site map for blocked links", function() {
var m = new Map();
gBlockedLinks.block(firstLink);
Links._incrementSiteMap(m, firstLink);
assert.equal(m.size, 0);
});
});

0 comments on commit 268dae0

Please sign in to comment.