Move MouseHelper.test into browser
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import { CompositionHelper } from './CompositionHelper';
|
import { CompositionHelper } from './CompositionHelper';
|
||||||
import { ITerminal } from './Types';
|
import { ITerminal } from './Types';
|
||||||
import { MockCharSizeService } from 'TestUtils.test';
|
import { MockCharSizeService } from 'browser/TestUtils.test';
|
||||||
|
|
||||||
describe('CompositionHelper', () => {
|
describe('CompositionHelper', () => {
|
||||||
let terminal: ITerminal;
|
let terminal: ITerminal;
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ import { BufferSet } from 'common/buffer/BufferSet';
|
|||||||
import { ITerminal } from './Types';
|
import { ITerminal } from './Types';
|
||||||
import { IBuffer } from 'common/buffer/Types';
|
import { IBuffer } from 'common/buffer/Types';
|
||||||
import { IBufferLine } from 'common/Types';
|
import { IBufferLine } from 'common/Types';
|
||||||
import { MockTerminal, MockCharSizeService } from './TestUtils.test';
|
import { MockTerminal } from './TestUtils.test';
|
||||||
import { MockOptionsService, MockBufferService } from 'common/TestUtils.test';
|
import { MockOptionsService, MockBufferService } from 'common/TestUtils.test';
|
||||||
import { BufferLine, CellData } from 'common/buffer/BufferLine';
|
import { BufferLine, CellData } from 'common/buffer/BufferLine';
|
||||||
import { IBufferService } from 'common/services/Services';
|
import { IBufferService } from 'common/services/Services';
|
||||||
|
import { MockCharSizeService } from 'browser/TestUtils.test';
|
||||||
|
|
||||||
class TestMockTerminal extends MockTerminal {
|
class TestMockTerminal extends MockTerminal {
|
||||||
emit(event: string, data: any): void {}
|
emit(event: string, data: any): void {}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import { Terminal } from './Terminal';
|
|||||||
import { AttributeData } from 'common/buffer/BufferLine';
|
import { AttributeData } from 'common/buffer/BufferLine';
|
||||||
import { IColorManager, IColorSet, IMouseHelper } from 'browser/Types';
|
import { IColorManager, IColorSet, IMouseHelper } from 'browser/Types';
|
||||||
import { IOptionsService } from 'common/services/Services';
|
import { IOptionsService } from 'common/services/Services';
|
||||||
import { ICharSizeService } from 'browser/services/Services';
|
|
||||||
|
|
||||||
export class TestTerminal extends Terminal {
|
export class TestTerminal extends Terminal {
|
||||||
writeSync(data: string): void {
|
writeSync(data: string): void {
|
||||||
@@ -428,10 +427,3 @@ export class MockCompositionHelper implements ICompositionHelper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MockCharSizeService implements ICharSizeService {
|
|
||||||
get hasValidSize(): boolean { return this.width > 0 && this.height > 0; }
|
|
||||||
onCharSizeChange: IEvent<void>;
|
|
||||||
constructor(public width: number, public height: number) {}
|
|
||||||
measure(): void {}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { IEvent, EventEmitter2 } from 'common/EventEmitter2';
|
||||||
|
import { ICharSizeService } from 'browser/services/Services';
|
||||||
|
|
||||||
|
export class MockCharSizeService implements ICharSizeService {
|
||||||
|
get hasValidSize(): boolean { return this.width > 0 && this.height > 0; }
|
||||||
|
onCharSizeChange: IEvent<void> = new EventEmitter2<void>().event;
|
||||||
|
constructor(public width: number, public height: number) {}
|
||||||
|
measure(): void {}
|
||||||
|
}
|
||||||
@@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
import jsdom = require('jsdom');
|
import jsdom = require('jsdom');
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import { MouseHelper } from './browser/input/MouseHelper';
|
import { MouseHelper } from 'browser/input/MouseHelper';
|
||||||
import { MockRenderer, MockCharSizeService } from './TestUtils.test';
|
import { MockCharSizeService } from 'browser/TestUtils.test';
|
||||||
|
|
||||||
const CHAR_WIDTH = 10;
|
const CHAR_WIDTH = 10;
|
||||||
const CHAR_HEIGHT = 20;
|
const CHAR_HEIGHT = 20;
|
||||||
@@ -17,16 +17,17 @@ describe('MouseHelper.getCoords', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
document = new jsdom.JSDOM('').window.document;
|
document = new jsdom.JSDOM('').window.document;
|
||||||
const renderer = new MockRenderer();
|
const mockRenderService = {
|
||||||
renderer.dimensions = <any>{
|
dimensions: {
|
||||||
actualCellWidth: CHAR_WIDTH,
|
actualCellWidth: CHAR_WIDTH,
|
||||||
actualCellHeight: CHAR_HEIGHT
|
actualCellHeight: CHAR_HEIGHT
|
||||||
|
}
|
||||||
};
|
};
|
||||||
mouseHelper = new MouseHelper(renderer as any, new MockCharSizeService(CHAR_WIDTH, CHAR_HEIGHT));
|
mouseHelper = new MouseHelper(mockRenderService as any, new MockCharSizeService(CHAR_WIDTH, CHAR_HEIGHT));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the cell that was clicked', () => {
|
it('should return the cell that was clicked', () => {
|
||||||
let coords: [number, number];
|
let coords: [number, number] | undefined;
|
||||||
coords = mouseHelper.getCoords({ clientX: CHAR_WIDTH / 2, clientY: CHAR_HEIGHT / 2 }, document.createElement('div'), 10, 10);
|
coords = mouseHelper.getCoords({ clientX: CHAR_WIDTH / 2, clientY: CHAR_HEIGHT / 2 }, document.createElement('div'), 10, 10);
|
||||||
assert.deepEqual(coords, [1, 1]);
|
assert.deepEqual(coords, [1, 1]);
|
||||||
coords = mouseHelper.getCoords({ clientX: CHAR_WIDTH, clientY: CHAR_HEIGHT }, document.createElement('div'), 10, 10);
|
coords = mouseHelper.getCoords({ clientX: CHAR_WIDTH, clientY: CHAR_HEIGHT }, document.createElement('div'), 10, 10);
|
||||||
@@ -38,7 +39,7 @@ describe('MouseHelper.getCoords', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should ensure the coordinates are returned within the terminal bounds', () => {
|
it('should ensure the coordinates are returned within the terminal bounds', () => {
|
||||||
let coords: [number, number];
|
let coords: [number, number] | undefined;
|
||||||
coords = mouseHelper.getCoords({ clientX: -1, clientY: -1 }, document.createElement('div'), 10, 10);
|
coords = mouseHelper.getCoords({ clientX: -1, clientY: -1 }, document.createElement('div'), 10, 10);
|
||||||
assert.deepEqual(coords, [1, 1]);
|
assert.deepEqual(coords, [1, 1]);
|
||||||
// Event are double the cols/rows
|
// Event are double the cols/rows
|
||||||
Reference in New Issue
Block a user