Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Unit tests for opening multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
smashwilson committed Nov 13, 2018
1 parent c068bbf commit b653c0f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
5 changes: 3 additions & 2 deletions lib/views/multi-file-patch-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,10 @@ export default class MultiFilePatchView extends React.Component {
return null;
});

return Promise.all(Array.from(cursorsByFilePatch).map(value => {
const pending = cursorsByFilePatch.size === 1;
return Promise.all(Array.from(cursorsByFilePatch, value => {
const [filePatch, cursors] = value;
return this.props.openFile(filePatch, cursors);
return this.props.openFile(filePatch, cursors, pending);
}));

}
Expand Down
58 changes: 41 additions & 17 deletions test/views/multi-file-patch-view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1293,24 +1293,32 @@ describe('MultiFilePatchView', function() {
});
});

describe('opening the file when there is only one file patch', function() {
describe('jump to file', function() {
let mfp, fp;

beforeEach(function() {
const {multiFilePatch} = multiFilePatchBuilder().addFilePatch(filePatch => {
filePatch.setOldFile(f => f.path('path.txt'));
filePatch.addHunk(h => {
h.oldRow(2);
h.unchanged('0000').added('0001').unchanged('0002');
});
filePatch.addHunk(h => {
h.oldRow(10);
h.unchanged('0003').added('0004', '0005').deleted('0006').unchanged('0007').added('0008').deleted('0009').unchanged('0010');
});
}).build();
const {multiFilePatch} = multiFilePatchBuilder()
.addFilePatch(filePatch => {
filePatch.setOldFile(f => f.path('path.txt'));
filePatch.addHunk(h => {
h.oldRow(2);
h.unchanged('0000').added('0001').unchanged('0002');
});
filePatch.addHunk(h => {
h.oldRow(10);
h.unchanged('0003').added('0004', '0005').deleted('0006').unchanged('0007').added('0008').deleted('0009').unchanged('0010');
});
})
.addFilePatch(filePatch => {
filePatch.setOldFile(f => f.path('other.txt'));
filePatch.addHunk(h => {
h.oldRow(10);
h.unchanged('0011').added('0012').unchanged('0013');
});
})
.build();

mfp = multiFilePatch;
assert.lengthOf(mfp.getFilePatches(), 1);
fp = mfp.getFilePatches()[0];
});

Expand All @@ -1322,7 +1330,7 @@ describe('MultiFilePatchView', function() {
editor.setCursorBufferPosition([7, 2]);

atomEnv.commands.dispatch(wrapper.getDOMNode(), 'github:jump-to-file');
assert.isTrue(openFile.calledWith(fp, [[13, 2]]));
assert.isTrue(openFile.calledWith(fp, [[13, 2]], true));
});

it('opens the file at a current added row', function() {
Expand All @@ -1334,7 +1342,7 @@ describe('MultiFilePatchView', function() {

atomEnv.commands.dispatch(wrapper.getDOMNode(), 'github:jump-to-file');

assert.isTrue(openFile.calledWith(fp, [[14, 3]]));
assert.isTrue(openFile.calledWith(fp, [[14, 3]], true));
});

it('opens the file at the beginning of the previous added or unchanged row', function() {
Expand All @@ -1346,7 +1354,7 @@ describe('MultiFilePatchView', function() {

atomEnv.commands.dispatch(wrapper.getDOMNode(), 'github:jump-to-file');

assert.isTrue(openFile.calledWith(fp, [[15, 0]]));
assert.isTrue(openFile.calledWith(fp, [[15, 0]], true));
});

it('preserves multiple cursors', function() {
Expand All @@ -1369,7 +1377,23 @@ describe('MultiFilePatchView', function() {
[11, 2],
[2, 3],
[15, 0],
]));
], true));
});

it('opens non-pending editors when opening multiple', function() {
const openFile = sinon.spy();
const wrapper = mount(buildApp({multiFilePatch: mfp, openFile}));

const editor = wrapper.find('AtomTextEditor').instance().getModel();
editor.setSelectedBufferRanges([
[[4, 0], [4, 0]],
[[12, 0], [12, 0]],
]);

atomEnv.commands.dispatch(wrapper.getDOMNode(), 'github:jump-to-file');

assert.isTrue(openFile.calledWith(mfp.getFilePatches()[0], [[11, 0]], false));
assert.isTrue(openFile.calledWith(mfp.getFilePatches()[1], [[10, 0]], false));
});
});
});
Expand Down

0 comments on commit b653c0f

Please sign in to comment.