Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'most-popular-pages' into staging
Conflicts: public/index.html
- Loading branch information
Showing
7 changed files
with
213 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
window.dataHelper = { | ||
findWithUrl: function(data, url) { | ||
var i, dataLength = data.length; | ||
for(i=0;i<dataLength;i++) { | ||
result = data[i]; | ||
if(result.url === url) { | ||
return result; | ||
} | ||
} | ||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
describe('traffic', function() { | ||
beforeEach(function() { | ||
window.matrix.settings = { | ||
profileId: '' | ||
}; | ||
subject = window.matrix.content; | ||
sandbox = sinon.sandbox.create(); | ||
server = sinon.fakeServer.create(); | ||
}); | ||
afterEach(function() { | ||
sandbox.restore(); | ||
server.restore(); | ||
}); | ||
it('empty pages', function() { | ||
expect(subject.pages).to.eql([]); | ||
}); | ||
describe('#init', function() { | ||
it("calls reload", function() { | ||
mock = sandbox.mock(subject).expects("reload").once(); | ||
subject.init(); | ||
mock.verify(); | ||
}); | ||
it("calls reload with interval of 30 minute", function() { | ||
clock = sinon.useFakeTimers(Date.now()); | ||
mock = sandbox.mock(subject).expects("reload").twice(); | ||
subject.init(); | ||
clock.tick(1800000); | ||
mock.verify(); | ||
clock.restore(); | ||
}); | ||
}); | ||
describe('#reload', function() { | ||
it("calls endpoint", function() { | ||
sandbox.stub(d3, "json"); | ||
mock = sandbox.mock(subject).expects("endpoint").once(); | ||
subject.reload(); | ||
mock.verify(); | ||
}); | ||
context('json returned', function(){ | ||
beforeEach(function() { | ||
stub = sandbox.stub(d3, 'json'); | ||
}); | ||
it("calls parseResponse", function() { | ||
mock = sandbox.mock(subject).expects("parseResponse").once(); | ||
subject.reload(); | ||
stub.callArgWith(1, {}, {}); | ||
mock.verify(); | ||
}); | ||
}); | ||
}); | ||
describe('#parseResponse', function() { | ||
context("error parsing json", function() { | ||
it("does not display the results", function() { | ||
mock = sandbox.mock(subject).expects("displayResults").never(); | ||
subject.parseResponse({}, null); | ||
mock.verify(); | ||
}); | ||
}); | ||
context("no error parsing json", function() { | ||
context("has data from GA", function() { | ||
it("displays the results", function() { | ||
mock = sandbox.mock(subject).expects("displayResults").once(); | ||
subject.parseResponse(null, {rows: []}); | ||
mock.verify(); | ||
}); | ||
it("parses the data", function() { | ||
data = {rows: []}; | ||
sandbox.stub(subject, "displayResults"); | ||
mock = sandbox.mock(subject).expects("parseData").withArgs(data).once(); | ||
subject.parseResponse(null, data); | ||
mock.verify(); | ||
}); | ||
}); | ||
context("no rows (no data from GA)", function() { | ||
it("does not call parseData", function() { | ||
sandbox.stub(subject, "displayResults"); | ||
mock = sandbox.mock(subject).expects("parseData").never(); | ||
subject.parseResponse(null, {}); | ||
mock.verify(); | ||
}); | ||
it("does not parse data", function() { | ||
sandbox.stub(subject, "displayResults"); | ||
expect(function() { | ||
return subject.pages.length; | ||
}).to.not.change.when(function() { subject.parseResponse(null, {})}); | ||
}); | ||
}); | ||
}); | ||
it("calls the template rendering", function() { | ||
templateSpy = sandbox.spy(); | ||
window.matrix.template = templateSpy; | ||
subject.displayResults(); | ||
expect(templateSpy).to.have.been.calledOnce | ||
}); | ||
}); | ||
describe('#parseData', function() { | ||
beforeEach(function() { | ||
data = { rows: [["Titel 1","url 1","DESKTOP","1"]] }; | ||
subject.pages = []; | ||
}); | ||
it("adds new items to pages", function() { | ||
expect(function() { | ||
return subject.pages.length; | ||
}).to.change.by(1).when(function() { subject.parseData(data)}); | ||
}); | ||
it("adds new items to pages", function() { | ||
result = { title: 'Titel 1', url: "url 1", visits: { desktop: 1, mobile: 0 } }; | ||
subject.parseData(data); | ||
expect(subject.pages[0]).to.eql(result); | ||
}); | ||
it("updates items for the same url", function() { | ||
data = { rows: [["Titel 1","url 1","DESKTOP","1"], ["Titel 1","url 1","MOBILE","1"]] }; | ||
result = { title: 'Titel 1', url: "url 1", visits: { desktop: 1, mobile: 1 } }; | ||
subject.parseData(data); | ||
expect(subject.pages[0]).to.eql(result); | ||
}); | ||
}); | ||
describe('#endpoint', function() { | ||
it('returns the path to the servers realtime endpoint', function() { | ||
expect(subject.endpoint()).to.eql('/historic?ids=ga:&metrics=ga:pageviews&dimensions=ga:pageTitle,ga:pagePath,ga:deviceCategory&start-date=today&end-date=today&max-results=1000&sort=-ga%3Apageviews'); | ||
}); | ||
context('with profileId', function() { | ||
beforeEach(function() { | ||
window.matrix.settings = { | ||
profileId: 'Test' | ||
}; | ||
}); | ||
it('returns correct profile Id in the endpoint path', function() { | ||
expect(subject.endpoint()).to.eql('/historic?ids=ga:Test&metrics=ga:pageviews&dimensions=ga:pageTitle,ga:pagePath,ga:deviceCategory&start-date=today&end-date=today&max-results=1000&sort=-ga%3Apageviews'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
describe('dataHelper', function() { | ||
beforeEach(function() { | ||
subject = window.dataHelper; | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
afterEach(function() { | ||
sandbox.restore(); | ||
server.restore(); | ||
}); | ||
describe('findWithUrl', function() { | ||
beforeEach(function() { | ||
entry1 = { url: "test.de", title: "Test" }; | ||
entry2 = { url: "test2.de", title: "Test 2" }; | ||
data = [entry1, entry2]; | ||
}); | ||
it("returns object with the same url", function() { | ||
expect(subject.findWithUrl(data, "test.de")).to.eql(entry1); | ||
}); | ||
it("returns undefined if url not found", function() { | ||
expect(subject.findWithUrl(data, "tost.de")).to.eql(undefined); | ||
}); | ||
it("returns the first result not every", function() { | ||
entry2 = { url: "test.de", title: "Test 2" }; | ||
data = [entry1, entry2]; | ||
expect(subject.findWithUrl(data, "test.de")).to.eql(entry1); | ||
}); | ||
}); | ||
}); |