forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-diff-spec.js
More file actions
81 lines (66 loc) · 2.89 KB
/
Copy pathfile-diff-spec.js
File metadata and controls
81 lines (66 loc) · 2.89 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
73
74
75
76
77
78
79
80
81
/** @babel */
import FileDiff from '../lib/file-diff'
import {createFileDiffsFromPath} from './helpers'
describe("FileDiff", function() {
it("roundtrips toString and fromString", function() {
let file = FileStr
let fileDiff = FileDiff.fromString(file)
expect(fileDiff.toString()).toEqual(file)
})
it("stages all hunks with ::stage() and unstages all hunks with ::unstage()", function() {
let fileDiff = createFileDiffsFromPath('fixtures/two-file-diff.txt')[0]
expect(fileDiff.getStageStatus()).toBe('unstaged')
fileDiff.stage()
expect(fileDiff.getStageStatus()).toBe('staged')
expect(fileDiff.getHunks()[0].getStageStatus()).toBe('staged')
expect(fileDiff.getHunks()[1].getStageStatus()).toBe('staged')
expect(fileDiff.getHunks()[2].getStageStatus()).toBe('staged')
fileDiff.unstage()
expect(fileDiff.getStageStatus()).toBe('unstaged')
expect(fileDiff.getHunks()[0].getStageStatus()).toBe('unstaged')
expect(fileDiff.getHunks()[1].getStageStatus()).toBe('unstaged')
expect(fileDiff.getHunks()[2].getStageStatus()).toBe('unstaged')
})
it("returns 'partial' from getStageStatus() when some of the hunks are staged", function() {
let fileDiff = createFileDiffsFromPath('fixtures/two-file-diff.txt')[0]
expect(fileDiff.getStageStatus()).toBe('unstaged')
fileDiff.getHunks()[1].stage()
expect(fileDiff.getStageStatus()).toBe('partial')
fileDiff.getHunks()[1].unstage()
expect(fileDiff.getStageStatus()).toBe('unstaged')
})
it("emits an event when FileDiff::fromString() is called", function() {
let changeHandler = jasmine.createSpy()
let file = FileStr
let fileDiff = new FileDiff
fileDiff.onDidChange(changeHandler)
fileDiff.fromString(file)
expect(changeHandler).toHaveBeenCalled()
expect(fileDiff.toString()).toEqual(file)
})
it("emits one change event when the file is staged", function() {
let changeHandler = jasmine.createSpy()
let fileDiff = createFileDiffsFromPath('fixtures/two-file-diff.txt')[0]
fileDiff.onDidChange(changeHandler)
fileDiff.stage()
expect(changeHandler.callCount).toBe(1)
})
it("emits a change event when a hunk is staged", function() {
let changeHandler = jasmine.createSpy()
let fileDiff = createFileDiffsFromPath('fixtures/two-file-diff.txt')[0]
fileDiff.onDidChange(changeHandler)
fileDiff.getHunks()[1].stage()
expect(changeHandler).toHaveBeenCalled()
})
})
FileStr = `FILE src/config.coffee - modified - unstaged
HUNK @@ -85,9 +85,6 @@ ScopeDescriptor = require './scope-descriptor'
85 85 #
86 86 # ## Config Schemas
87 87 #
88 --- - # We use [json schema](http://json-schema.org) which allows you to define your value's
89 --- - # default, the type it should be, etc. A simple example:
90 --- - #
91 88 # \`\`\`coffee
92 89 # # We want to provide an \`enableThing\`, and a \`thingVolume\`
93 90 # config:`