Add some OscLinkService unit tests

This commit is contained in:
Daniel Imms
2022-08-07 11:30:08 -07:00
parent e87e15e87b
commit 2cfbee413f
2 changed files with 48 additions and 6 deletions
+4 -6
View File
@@ -32,13 +32,11 @@ export class BufferService extends Disposable implements IBufferService {
/** An IBufferline to clone/copy from for new blank lines */
private _cachedBlankLine: IBufferLine | undefined;
constructor(
@IOptionsService private _optionsService: IOptionsService
) {
constructor(@IOptionsService optionsService: IOptionsService) {
super();
this.cols = Math.max(_optionsService.rawOptions.cols || 0, MINIMUM_COLS);
this.rows = Math.max(_optionsService.rawOptions.rows || 0, MINIMUM_ROWS);
this.buffers = new BufferSet(_optionsService, this);
this.cols = Math.max(optionsService.rawOptions.cols || 0, MINIMUM_COLS);
this.rows = Math.max(optionsService.rawOptions.rows || 0, MINIMUM_ROWS);
this.buffers = new BufferSet(optionsService, this);
}
public dispose(): void {
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2020 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { assert } from 'chai';
import { AttributeData } from 'common/buffer/AttributeData';
import { BufferService } from 'common/services/BufferService';
import { OptionsService } from 'common/services/OptionsService';
import { OscLinkService } from 'common/services/OscLinkService';
import { IBufferService, IOptionsService, IOscLinkService } from 'common/services/Services';
describe('OscLinkService', () => {
describe('constructor', () => {
let bufferService: IBufferService;
let optionsService: IOptionsService;
let oscLinkService: IOscLinkService;
beforeEach(() => {
optionsService = new OptionsService({ rows: 3, cols: 10 });
bufferService = new BufferService(optionsService);
oscLinkService = new OscLinkService(bufferService);
});
it('link IDs are created and fetched consistently', () => {
const linkId = oscLinkService.registerLink({ id: 'foo', uri: 'bar' });
assert.ok(linkId);
assert.equal(oscLinkService.registerLink({ id: 'foo', uri: 'bar' }), linkId);
});
it('should dispose the link ID when the last marker is trimmed from the buffer', () => {
// Activate the alt buffer to get 0 scrollback
bufferService.buffers.activateAltBuffer();
const linkId = oscLinkService.registerLink({ id: 'foo', uri: 'bar' });
assert.ok(linkId);
bufferService.scroll(new AttributeData());
assert.notStrictEqual(oscLinkService.registerLink({ id: 'foo', uri: 'bar' }), linkId);
});
it('should fetch link data from link id', () => {
const linkId = oscLinkService.registerLink({ id: 'foo', uri: 'bar' });
assert.deepStrictEqual(oscLinkService.getLinkData(linkId), { id: 'foo', uri: 'bar' });
});
});
});