mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-20 01:25:37 -05:00
added more tests (#10161)
* added more tests * typo fixes * removed unused func * added an extra assert * fix typo
This commit is contained in:
@@ -612,17 +612,6 @@ export class NotebookFindModel extends Disposable implements INotebookFindModel
|
||||
return cellSrc.replace(/(?:__|[*#])|\[(.*?)\]\(.*?\)/gm, '$1');
|
||||
}
|
||||
|
||||
// remove /n's to calculate the line number to locate the correct element
|
||||
cleanUpCellSource(cellValue: string | string[]): string | string[] {
|
||||
let trimmedCellSrc: string[] = [];
|
||||
if (cellValue instanceof Array) {
|
||||
trimmedCellSrc = cellValue.filter(c => c !== '\n' && c !== '\r\n' && c.indexOf('|-') === -1);
|
||||
} else {
|
||||
return cellValue;
|
||||
}
|
||||
return trimmedCellSrc;
|
||||
}
|
||||
|
||||
clearFind(): void {
|
||||
this._findArray = new Array<NotebookRange>();
|
||||
this._findIndex = 0;
|
||||
|
||||
@@ -110,6 +110,20 @@ suite('Notebook Find Model', function (): void {
|
||||
await initNotebookModel(expectedNotebookContent);
|
||||
});
|
||||
|
||||
test('Should set notebook model on initialize', async function (): Promise<void> {
|
||||
//initialize find
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
assert.equal(notebookFindModel.notebookModel, model, 'Failed to set notebook model');
|
||||
});
|
||||
|
||||
test('Should have no decorations on initialize', async function (): Promise<void> {
|
||||
//initialize find
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
assert.equal(notebookFindModel.findDecorations, undefined, 'findDecorations should be undefined on initialize');
|
||||
assert.equal(notebookFindModel.getPosition(), undefined, 'currentMatch should be undefined on initialize');
|
||||
assert.equal(notebookFindModel.getLastPosition(), undefined, 'previousMatch should be undefined on initialize');
|
||||
});
|
||||
|
||||
test('Should find results in the notebook', async function (): Promise<void> {
|
||||
// Need to set rendered text content for 2nd cell
|
||||
setRenderedTextContent(1);
|
||||
@@ -119,7 +133,9 @@ suite('Notebook Find Model', function (): void {
|
||||
await notebookFindModel.find('markdown', false, false, max_find_count);
|
||||
|
||||
assert(notebookFindModel.findMatches, 'Find in notebook failed.');
|
||||
assert.equal(notebookFindModel.findMatches.length, 2, 'Find couldnt find all occurrences');
|
||||
assert.equal(notebookFindModel.findMatches.length, 2, 'Find could not find all occurrences');
|
||||
assert.equal(notebookFindModel.findArray.length, 2, 'Find could not find all occurrences');
|
||||
assert.equal(notebookFindModel.getFindCount(), 2, 'Find count do not match find results');
|
||||
});
|
||||
|
||||
test('Should not find results in the notebook', async function (): Promise<void> {
|
||||
@@ -144,6 +160,19 @@ suite('Notebook Find Model', function (): void {
|
||||
assert.deepEqual(notebookFindModel.findMatches[1].range, expectedFindRange2, 'Find in markdown range is wrong :\n' + JSON.stringify(expectedFindRange2) + '\n ' + JSON.stringify(notebookFindModel.findMatches[1].range));
|
||||
});
|
||||
|
||||
test('Should set selection when find matches results', async function (): Promise<void> {
|
||||
// Need to set rendered text content for 2nd cell
|
||||
setRenderedTextContent(1);
|
||||
|
||||
//initialize find
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
await notebookFindModel.find('markdown', false, false, max_find_count);
|
||||
|
||||
notebookFindModel.setSelection(notebookFindModel.findMatches[0].range);
|
||||
let expectedFindRange1 = new NotebookRange(model.cells[0], 2, 13, 2, 21);
|
||||
assert.deepEqual(notebookFindModel.currentMatch, expectedFindRange1, 'Find failed to set selection on finding results');
|
||||
});
|
||||
|
||||
test('Should ignore hyperlink markdown data and find correctly', async function (): Promise<void> {
|
||||
let markdownContent: nb.INotebookContents = {
|
||||
cells: [{
|
||||
@@ -245,7 +274,7 @@ suite('Notebook Find Model', function (): void {
|
||||
await notebookFindModel.find('insert', false, false, max_find_count);
|
||||
|
||||
assert(notebookFindModel.findMatches, 'Find in notebook failed.');
|
||||
assert.equal(notebookFindModel.findMatches.length, 3, 'Find couldnt find all occurances');
|
||||
assert.equal(notebookFindModel.findMatches.length, 3, 'Find couldnt find all occurrences');
|
||||
|
||||
await notebookFindModel.find('insert', true, false, max_find_count);
|
||||
assert.equal(notebookFindModel.findMatches.length, 2, 'Find failed to apply match case while searching');
|
||||
@@ -359,6 +388,38 @@ suite('Notebook Find Model', function (): void {
|
||||
assert.equal(notebookFindModel.findMatches.length, 2, 'Find failed on markdown edit');
|
||||
});
|
||||
|
||||
test('Find next/previous should return the correct find index', async function (): Promise<void> {
|
||||
// Need to set rendered text content for 2nd cell
|
||||
setRenderedTextContent(1);
|
||||
|
||||
//initialize find
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
await notebookFindModel.find('insert', false, false, max_find_count);
|
||||
|
||||
assert.equal(notebookFindModel.getFindIndex(), 1, 'Failed to get the correct find index');
|
||||
|
||||
notebookFindModel.findNext();
|
||||
assert.equal(notebookFindModel.getFindIndex(), 2, 'Failed to get the correct find index');
|
||||
|
||||
notebookFindModel.findPrevious();
|
||||
assert.equal(notebookFindModel.getFindIndex(), 1, 'Failed to get the correct find index');
|
||||
});
|
||||
|
||||
test('Should clear results on clear', async function (): Promise<void> {
|
||||
// Need to set rendered text content for 2nd cell
|
||||
setRenderedTextContent(1);
|
||||
|
||||
//initialize find
|
||||
let notebookFindModel = new NotebookFindModel(model);
|
||||
await notebookFindModel.find('insert', false, false, max_find_count);
|
||||
|
||||
assert.equal(notebookFindModel.findMatches.length, 3, 'Failed to find all occurrences');
|
||||
|
||||
notebookFindModel.clearFind();
|
||||
assert.equal(notebookFindModel.findMatches.length, 0, 'Failed to clear find results');
|
||||
assert.equal(notebookFindModel.findDecorations, undefined, 'Failed to clear find decorations on clear');
|
||||
});
|
||||
|
||||
|
||||
async function initNotebookModel(contents: nb.INotebookContents): Promise<void> {
|
||||
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
||||
|
||||
Reference in New Issue
Block a user