2 Copyright 2014 The Chromium Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file.
7 <link rel="import" href="../ct-commit-log.html">
9 <link rel="import" href="../ct-commit-mock.html">
14 var assert = chai.assert;
16 describe('ct-commit-log model', function() {
17 it('handles response', function() {
18 var commit = new CTCommitMock();
19 var exampleCommitData = ')]}\n' +
23 "commit": "068885c2c5fda617e634bb73a107a0285af470ff",
24 "tree": "750c92f0fe1294bdddbf00cc14378d0d440290cb",
26 "e6ba81e00ae835946e069e5bd80bd533b11d8442"
29 "name": commit.author,
30 "email": commit.author,
31 "time": "Tue Jul 17 17:10:47 2012"
34 "name": commit.author,
35 "email": commit.author,
36 "time": "Tue Jul 17 17:10:47 2012"
38 "message": commit.message,
43 var repositoryUrl = 'https://mockurl/?{revision}';
44 var repository = 'blink';
46 var log = new CTCommitLog();
47 log._handleResponse(repositoryUrl, repository, exampleCommitData);
49 var expectedCommits = {};
50 log._repositories.names.forEach(function(name) {
51 expectedCommits[name] = {};
53 expectedCommits[repository][commit.revision] = commit;
54 assert.deepEqual(log.commits, expectedCommits);
56 var revisions = [commit.revision];
57 assert.deepEqual(log.range(repository, revisions), [commit]);
59 // This url is different than the one above because CTCommitLog gets the url
60 // from CTRepositories.
61 var incompleteRepositoryUrl = log._repositories.repositories[repository].repositoryUrl;
63 var nextRev = String(commit.revision + 1);
64 var incompleteCommitAfter =
65 CTCommit.createIncomplete(incompleteRepositoryUrl, nextRev, repository);
66 revisions.push(nextRev);
67 // Expect an incomplete commit for revision + 1.
68 assert.deepEqual(log.range(repository, revisions), [commit, incompleteCommitAfter]);
70 // Expect two incomplete commits: one before and one after.
71 var prevRev = String(commit.revision - 1);
72 var incompleteCommitBefore =
73 CTCommit.createIncomplete(incompleteRepositoryUrl, prevRev, repository);
74 // Inserting at the beginning of the list.
75 revisions.splice(0, 0, prevRev);
76 assert.deepEqual(log.range(repository, revisions),
77 [incompleteCommitBefore, commit, incompleteCommitAfter]);