diff-list-view-spec.js
1 const path = require('path'); 2 const fs = require('fs-plus'); 3 const temp = require('temp'); 4 5 describe('git-diff:toggle-diff-list', () => { 6 let diffListView, editor; 7 8 beforeEach(() => { 9 const projectPath = temp.mkdirSync('git-diff-spec-'); 10 fs.copySync(path.join(__dirname, 'fixtures', 'working-dir'), projectPath); 11 fs.moveSync( 12 path.join(projectPath, 'git.git'), 13 path.join(projectPath, '.git') 14 ); 15 atom.project.setPaths([projectPath]); 16 17 jasmine.attachToDOM(atom.workspace.getElement()); 18 19 waitsForPromise(() => atom.packages.activatePackage('git-diff')); 20 21 waitsForPromise(() => atom.workspace.open('sample.js')); 22 23 runs(() => { 24 editor = atom.workspace.getActiveTextEditor(); 25 editor.setCursorBufferPosition([8, 30]); 26 editor.insertText('a'); 27 atom.commands.dispatch(editor.getElement(), 'git-diff:toggle-diff-list'); 28 }); 29 30 waitsFor(() => { 31 diffListView = document.querySelector('.diff-list-view'); 32 return diffListView && diffListView.querySelectorAll('li').length > 0; 33 }); 34 }); 35 36 it('shows a list of all diff hunks', () => { 37 diffListView = document.querySelector('.diff-list-view ol'); 38 expect(diffListView.textContent).toBe( 39 'while (items.length > 0) {a-9,1 +9,1' 40 ); 41 }); 42 43 it('moves the cursor to the selected hunk', () => { 44 editor.setCursorBufferPosition([0, 0]); 45 atom.commands.dispatch( 46 document.querySelector('.diff-list-view'), 47 'core:confirm' 48 ); 49 expect(editor.getCursorBufferPosition()).toEqual([8, 4]); 50 }); 51 });