forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff-selection-spec.js
More file actions
72 lines (65 loc) · 2.35 KB
/
Copy pathdiff-selection-spec.js
File metadata and controls
72 lines (65 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/** @babel */
import DiffSelection from '../lib/diff-selection'
import DiffViewModel from '../lib/diff-view-model'
import FileList from '../lib/file-list'
import {createFileDiffsFromPath} from './helpers'
function createDiffs(filePath) {
let fileDiffs = createFileDiffsFromPath(filePath)
return new DiffViewModel({fileList: new FileList(fileDiffs)})
}
describe("DiffSelection", function() {
let viewModel
beforeEach(function() {
viewModel = createDiffs('fixtures/two-file-diff.txt')
})
it("can be created without options", function() {
let selection = new DiffSelection(viewModel)
expect(selection.getMode()).toEqual('hunk')
expect(selection.getHeadPosition()).toEqual([0, 0])
expect(selection.getTailPosition()).toEqual([0, 0])
})
it("can be created with options", function() {
let selection = new DiffSelection(viewModel, {
mode: 'line',
headPosition: [0, 1, 1],
tailPosition: [0, 1, 3]
})
expect(selection.getMode()).toEqual('line')
expect(selection.getHeadPosition()).toEqual([0, 1, 1])
expect(selection.getTailPosition()).toEqual([0, 1, 3])
})
describe("sorting selections", function() {
it("::sortSelectionsAscending()", function() {
let selectionBottom = new DiffSelection(viewModel, {
mode: 'line',
headPosition: [0, 1, 3],
tailPosition: [0, 1, 1]
})
let selectionTop = new DiffSelection(viewModel, {
mode: 'line',
headPosition: [0, 2, 3],
tailPosition: [0, 1, 0],
})
let selections = [selectionBottom, selectionTop]
let sortedSelections = DiffSelection.sortSelectionsAscending(selections)
expect(sortedSelections[0]).toBe(selectionTop)
expect(sortedSelections[1]).toBe(selectionBottom)
})
it("::sortSelectionsDescending()", function() {
let selectionTop = new DiffSelection(viewModel, {
mode: 'line',
headPosition: [0, 1, 3],
tailPosition: [0, 0, 1]
})
let selectionBottom = new DiffSelection(viewModel, {
mode: 'line',
headPosition: [0, 2, 3],
tailPosition: [0, 1, 0],
})
let selections = [selectionTop, selectionBottom]
let sortedSelections = DiffSelection.sortSelectionsDescending(selections)
expect(sortedSelections[0]).toBe(selectionBottom)
expect(sortedSelections[1]).toBe(selectionTop)
})
})
})