mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add line diff decorations to editor gutter
Added, modified, and deleted lines will now highlighted in the gutter for files already checked in to the repository.
This commit is contained in:
63
src/packages/git-diff/spec/git-diff-spec.coffee
Normal file
63
src/packages/git-diff/spec/git-diff-spec.coffee
Normal file
@@ -0,0 +1,63 @@
|
||||
RootView = require 'root-view'
|
||||
_ = require 'underscore'
|
||||
|
||||
describe "GitDiff package", ->
|
||||
editor = null
|
||||
|
||||
beforeEach ->
|
||||
config.set('git-diff.enabled', true)
|
||||
window.rootView = new RootView
|
||||
rootView.attachToDom()
|
||||
rootView.open('sample.js')
|
||||
atom.activatePackage('git-diff')
|
||||
editor = rootView.getActiveView()
|
||||
|
||||
describe "when the editor has modified lines", ->
|
||||
it "highlights the modified lines", ->
|
||||
expect(editor.find('.git-line-modified').length).toBe 0
|
||||
editor.insertText('a')
|
||||
advanceClock(editor.getBuffer().stoppedChangingDelay)
|
||||
expect(editor.find('.git-line-modified').length).toBe 1
|
||||
expect(editor.find('.git-line-modified').attr('lineNumber')).toBe '0'
|
||||
|
||||
describe "when the editor has added lines", ->
|
||||
it "highlights the added lines", ->
|
||||
expect(editor.find('.git-line-added').length).toBe 0
|
||||
editor.moveCursorToEndOfLine()
|
||||
editor.insertNewline()
|
||||
editor.insertText('a')
|
||||
advanceClock(editor.getBuffer().stoppedChangingDelay)
|
||||
expect(editor.find('.git-line-added').length).toBe 1
|
||||
expect(editor.find('.git-line-added').attr('lineNumber')).toBe '1'
|
||||
|
||||
describe "when the editor has removed lines", ->
|
||||
it "highlights the line preceeding the deleted lines", ->
|
||||
expect(editor.find('.git-line-added').length).toBe 0
|
||||
editor.setCursorBufferPosition([5])
|
||||
editor.deleteLine()
|
||||
advanceClock(editor.getBuffer().stoppedChangingDelay)
|
||||
expect(editor.find('.git-line-removed').length).toBe 1
|
||||
expect(editor.find('.git-line-removed').attr('lineNumber')).toBe '4'
|
||||
|
||||
describe "when a modified line is restored to the HEAD version contents", ->
|
||||
it "removes the diff highlight", ->
|
||||
expect(editor.find('.git-line-modified').length).toBe 0
|
||||
editor.insertText('a')
|
||||
advanceClock(editor.getBuffer().stoppedChangingDelay)
|
||||
expect(editor.find('.git-line-modified').length).toBe 1
|
||||
editor.backspace()
|
||||
advanceClock(editor.getBuffer().stoppedChangingDelay)
|
||||
expect(editor.find('.git-line-modified').length).toBe 0
|
||||
|
||||
describe "when a modified file is opened", ->
|
||||
it "highlights the changed lines", ->
|
||||
path = project.resolve('sample.txt')
|
||||
buffer = project.buildBuffer(path)
|
||||
buffer.setText("Some different text.")
|
||||
rootView.open('sample.txt')
|
||||
nextTick = false
|
||||
_.nextTick -> nextTick = true
|
||||
waitsFor -> nextTick
|
||||
runs ->
|
||||
expect(editor.find('.git-line-modified').length).toBe 1
|
||||
expect(editor.find('.git-line-modified').attr('lineNumber')).toBe '0'
|
||||
Reference in New Issue
Block a user