|
| 1 | +/* eslint-disable global-require */ |
| 2 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +// Licensed under the MIT License. |
| 4 | + |
| 5 | +'use strict'; |
| 6 | + |
| 7 | +import * as sinon from 'sinon'; |
| 8 | +import * as fs from 'fs-extra'; |
| 9 | +import * as path from 'path'; |
| 10 | +import { expect } from 'chai'; |
| 11 | +import * as Telemetry from '../../../../../extension/telemetry/index'; |
| 12 | +import { EventName } from '../../../../../extension/telemetry/constants'; |
| 13 | +import * as vscodeapi from '../../../../../extension/common/vscodeapi'; |
| 14 | +import * as pythonApi from '../../../../../extension/common/python'; |
| 15 | +import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../../constants'; |
| 16 | +import { openReportIssue } from '../../../../../extension/common/application/commands/reportIssueCommand'; |
| 17 | +import { PythonEnvironment } from '../../../../../extension/debugger/adapter/types'; |
| 18 | + |
| 19 | +suite('Report Issue Command', () => { |
| 20 | + let executeCommandStub: sinon.SinonStub; |
| 21 | + let resolveEnvironmentStub: sinon.SinonStub; |
| 22 | + |
| 23 | + setup(async () => { |
| 24 | + executeCommandStub = sinon.stub(vscodeapi, 'executeCommand'); |
| 25 | + resolveEnvironmentStub = sinon.stub(pythonApi, 'resolveEnvironment'); |
| 26 | + const interpreter = { |
| 27 | + environment: { |
| 28 | + type: 'Venv', |
| 29 | + }, |
| 30 | + version: { |
| 31 | + major: 3, |
| 32 | + minor: 9, |
| 33 | + micro: 0, |
| 34 | + }, |
| 35 | + } as unknown as PythonEnvironment; |
| 36 | + resolveEnvironmentStub.resolves(interpreter); |
| 37 | + }); |
| 38 | + |
| 39 | + teardown(() => { |
| 40 | + sinon.restore(); |
| 41 | + }); |
| 42 | + |
| 43 | + test('Test if issue body is filled correctly when including all the settings', async () => { |
| 44 | + await openReportIssue(); |
| 45 | + |
| 46 | + const issueTemplatePath = path.join( |
| 47 | + EXTENSION_ROOT_DIR_FOR_TESTS, |
| 48 | + 'src', |
| 49 | + 'test', |
| 50 | + 'resources', |
| 51 | + 'issueTemplate.md', |
| 52 | + ); |
| 53 | + const expectedIssueBody = fs.readFileSync(issueTemplatePath, 'utf8'); |
| 54 | + |
| 55 | + const userDataTemplatePath = path.join( |
| 56 | + EXTENSION_ROOT_DIR_FOR_TESTS, |
| 57 | + 'src', |
| 58 | + 'test', |
| 59 | + 'resources', |
| 60 | + 'issueUserDataTemplate.md', |
| 61 | + ); |
| 62 | + const expectedData = fs.readFileSync(userDataTemplatePath, 'utf8'); |
| 63 | + |
| 64 | + executeCommandStub.withArgs('workbench.action.openIssueReporter', sinon.match.any).resolves(); |
| 65 | + |
| 66 | + sinon.assert.calledOnceWithExactly(executeCommandStub, 'workbench.action.openIssueReporter', sinon.match.any); |
| 67 | + |
| 68 | + const { issueBody, data } = executeCommandStub.getCall(0).args[1]; |
| 69 | + expect(issueBody).to.be.equal(expectedIssueBody); |
| 70 | + expect(data).to.be.equal(expectedData); |
| 71 | + }); |
| 72 | + |
| 73 | + test('Should send telemetry event when run Report Issue Command', async () => { |
| 74 | + const sendTelemetryStub = sinon.stub(Telemetry, 'sendTelemetryEvent'); |
| 75 | + await openReportIssue(); |
| 76 | + |
| 77 | + sinon.assert.calledWith(sendTelemetryStub, EventName.USE_REPORT_ISSUE_COMMAND); |
| 78 | + sinon.restore(); |
| 79 | + }); |
| 80 | +}); |
0 commit comments