Make process.platform easier to mock

This commit is contained in:
Antonio Scandurra
2017-04-20 15:08:17 +02:00
parent b242f034b4
commit 2f356f85d3
2 changed files with 9 additions and 16 deletions

View File

@@ -1807,10 +1807,7 @@ describe('TextEditorComponent', () => {
})
it('adds or removes cursors when holding cmd or ctrl when single-clicking', () => {
const {component, editor} = buildComponent()
spyOn(component, 'getPlatform').andCallFake(() => mockedPlatform)
let mockedPlatform = 'darwin'
const {component, editor} = buildComponent({platform: 'darwin'})
expect(editor.getCursorScreenPositions()).toEqual([[0, 0]])
// add cursor at 1, 16
@@ -1870,9 +1867,8 @@ describe('TextEditorComponent', () => {
)
expect(editor.getCursorScreenPositions()).toEqual([[1, 4]])
mockedPlatform = 'win32'
// ctrl-click adds cursors on platforms *other* than macOS
component.props.platform = 'win32'
component.didMouseDownOnContent(
Object.assign(clientPositionForCharacter(component, 1, 16), {
detail: 1,
@@ -2823,7 +2819,8 @@ function buildComponent (params = {}) {
const component = new TextEditorComponent({
model: editor,
rowsPerTile: params.rowsPerTile,
updatedSynchronously: false
updatedSynchronously: false,
platform: params.platform
})
const {element} = component
if (!editor.getAutoHeight()) {

View File

@@ -823,10 +823,6 @@ class TextEditorComponent {
)
}
getPlatform () {
return process.platform
}
queryScreenLinesToRender () {
const {model} = this.props
@@ -1474,12 +1470,12 @@ class TextEditorComponent {
}
didMouseDownOnContent (event) {
const {model} = this.props
const {model, platform} = this.props
const {target, button, detail, ctrlKey, shiftKey, metaKey} = event
// Only handle mousedown events for left mouse button (or the middle mouse
// button on Linux where it pastes the selection clipboard).
if (!(button === 0 || (this.getPlatform() === 'linux' && button === 1))) return
if (!(button === 0 || (platform === 'linux' && button === 1))) return
const screenPosition = this.screenPositionForMouseEvent(event)
@@ -1489,7 +1485,7 @@ class TextEditorComponent {
return
}
const addOrRemoveSelection = metaKey || (ctrlKey && this.getPlatform() !== 'darwin')
const addOrRemoveSelection = metaKey || (ctrlKey && platform !== 'darwin')
switch (detail) {
case 1:
@@ -1534,7 +1530,7 @@ class TextEditorComponent {
}
didMouseDownOnLineNumberGutter (event) {
const {model} = this.props
const {model, platform} = this.props
const {target, button, ctrlKey, shiftKey, metaKey} = event
// Only handle mousedown events for left mouse button
@@ -1548,7 +1544,7 @@ class TextEditorComponent {
return
}
const addOrRemoveSelection = metaKey || (ctrlKey && this.getPlatform() !== 'darwin')
const addOrRemoveSelection = metaKey || (ctrlKey && platform !== 'darwin')
const endBufferRow = model.bufferPositionForScreenPosition([clickedScreenRow, Infinity]).row
const clickedLineBufferRange = Range(Point(startBufferRow, 0), Point(endBufferRow + 1, 0))