From 14ad4459aa4eb7a09321d18abd0c0258dea37cda Mon Sep 17 00:00:00 2001 From: Alena Khineika Date: Fri, 16 Jul 2021 12:31:42 +0200 Subject: [PATCH] test: add code action tests --- src/test/fixture/.vscode/settings.json | 3 ++- .../suite/editors/codeActionProvider.test.ts | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/test/fixture/.vscode/settings.json b/src/test/fixture/.vscode/settings.json index a2dd2c536..be8348c0e 100644 --- a/src/test/fixture/.vscode/settings.json +++ b/src/test/fixture/.vscode/settings.json @@ -18,5 +18,6 @@ "other": true, "comments": false, "strings": true - } + }, + "security.workspace.trust.enabled": false } diff --git a/src/test/suite/editors/codeActionProvider.test.ts b/src/test/suite/editors/codeActionProvider.test.ts index cd2798b33..51aef7164 100644 --- a/src/test/suite/editors/codeActionProvider.test.ts +++ b/src/test/suite/editors/codeActionProvider.test.ts @@ -1,5 +1,5 @@ -import assert from 'assert'; import { beforeEach } from 'mocha'; +import chai from 'chai'; import ActiveDBCodeLensProvider from '../../../editors/activeConnectionCodeLensProvider'; import CodeActionProvider from '../../../editors/codeActionProvider'; @@ -14,6 +14,8 @@ import { StorageController } from '../../../storage'; import TelemetryService from '../../../telemetry/telemetryService'; import { TestExtensionContext, MockLanguageServerController } from '../stubs'; +const expect = chai.expect; + suite('Code Action Provider Test Suite', () => { const mockExtensionContext = new TestExtensionContext(); @@ -66,14 +68,22 @@ suite('Code Action Provider Test Suite', () => { const testCodeActionProvider = new CodeActionProvider(testPlaygroundController); const codeActions = testCodeActionProvider.provideCodeActions(); - assert(!codeActions); + expect(codeActions).to.be.undefined; }); test('expected provideCodeActions to return a run selected playground blocks action', () => { + testPlaygroundController._selectedText = "use('test');"; + const testCodeActionProvider = new CodeActionProvider(testPlaygroundController); const codeActions = testCodeActionProvider.provideCodeActions(); - assert(!!codeActions); - assert(codeActions.length === 1); + expect(codeActions).to.exist; + + if (codeActions) { + expect(codeActions.length).to.be.equal(1); + const actionCommand = codeActions[0].command; + expect(actionCommand?.command).to.be.equal('mdb.runSelectedPlaygroundBlocks'); + expect(actionCommand?.title).to.be.equal('Run selected playground blocks'); + } }); });