| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 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. | |
| 5 --> | |
| 6 | |
| 7 <link rel="import" href="../ct-commit-log.html"> | |
| 8 | |
| 9 <link rel="import" href="../ct-commit-mock.html"> | |
| 10 | |
| 11 <script> | |
| 12 (function () { | |
| 13 | |
| 14 var assert = chai.assert; | |
| 15 | |
| 16 describe('ct-commit-log model', function() { | |
| 17 it('handles response', function() { | |
| 18 var commit = new CTCommitMock(); | |
| 19 var exampleCommitData = ')]}\n' + | |
| 20 JSON.stringify({ | |
| 21 "log": [ | |
| 22 { | |
| 23 "commit": "068885c2c5fda617e634bb73a107a0285af470ff", | |
| 24 "tree": "750c92f0fe1294bdddbf00cc14378d0d440290cb", | |
| 25 "parents": [ | |
| 26 "e6ba81e00ae835946e069e5bd80bd533b11d8442" | |
| 27 ], | |
| 28 "author": { | |
| 29 "name": commit.author, | |
| 30 "email": commit.author, | |
| 31 "time": "Tue Jul 17 17:10:47 2012" | |
| 32 }, | |
| 33 "committer": { | |
| 34 "name": commit.author, | |
| 35 "email": commit.author, | |
| 36 "time": "Tue Jul 17 17:10:47 2012" | |
| 37 }, | |
| 38 "message": commit.message, | |
| 39 } | |
| 40 ] | |
| 41 }); | |
| 42 | |
| 43 var repositoryUrl = 'https://mockurl/?{revision}'; | |
| 44 var repository = 'blink'; | |
| 45 | |
| 46 var log = new CTCommitLog(); | |
| 47 log._handleResponse(repositoryUrl, repository, exampleCommitData); | |
| 48 | |
| 49 var expectedCommits = {}; | |
| 50 log._repositories.names.forEach(function(name) { | |
| 51 expectedCommits[name] = {}; | |
| 52 }); | |
| 53 expectedCommits[repository][commit.revision] = commit; | |
| 54 assert.deepEqual(log.commits, expectedCommits); | |
| 55 | |
| 56 var revisions = [commit.revision]; | |
| 57 assert.deepEqual(log.range(repository, revisions), [commit]); | |
| 58 | |
| 59 // This url is different than the one above because CTCommitLog gets the url | |
| 60 // from CTRepositories. | |
| 61 var incompleteRepositoryUrl = log._repositories.repositories[repository].rep
ositoryUrl; | |
| 62 | |
| 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, incompleteCommit
After]); | |
| 69 | |
| 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]); | |
| 78 }); | |
| 79 }); | |
| 80 | |
| 81 })(); | |
| 82 </script> | |
| OLD | NEW |