-
Notifications
You must be signed in to change notification settings - Fork 751
feat(amazonq): grouping options for code issues #6330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
9dc7087
987082e
58e4aa9
2858195
04ff05a
4452ab0
1df881b
26c558c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "type": "Feature", | ||
| "description": "/review: Code issues can be grouped by file location or severity" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,12 @@ | |
| */ | ||
| import assert from 'assert' | ||
| import sinon from 'sinon' | ||
| import { SecurityIssueFilters, SecurityTreeViewFilterState } from 'aws-core-vscode/codewhisperer' | ||
| import { | ||
| CodeIssueGroupingStrategy, | ||
| CodeIssueGroupingStrategyState, | ||
| SecurityIssueFilters, | ||
| SecurityTreeViewFilterState, | ||
| } from 'aws-core-vscode/codewhisperer' | ||
| import { globals } from 'aws-core-vscode/shared' | ||
|
|
||
| describe('model', function () { | ||
|
|
@@ -70,4 +75,113 @@ describe('model', function () { | |
| assert.deepStrictEqual(hiddenSeverities, ['High', 'Low']) | ||
| }) | ||
| }) | ||
|
|
||
| describe('CodeIssueGroupingStrategyState', function () { | ||
| let sandbox: sinon.SinonSandbox | ||
| let state: CodeIssueGroupingStrategyState | ||
|
|
||
| beforeEach(function () { | ||
| sandbox = sinon.createSandbox() | ||
| // Reset the singleton instance before each test | ||
| // @ts-ignore - accessing private static for testing | ||
| CodeIssueGroupingStrategyState['#instance'] = undefined | ||
| state = CodeIssueGroupingStrategyState.instance | ||
| }) | ||
|
|
||
| afterEach(function () { | ||
| sandbox.restore() | ||
| }) | ||
|
|
||
| describe('instance', function () { | ||
| it('should return the same instance when called multiple times', function () { | ||
| const instance1 = CodeIssueGroupingStrategyState.instance | ||
| const instance2 = CodeIssueGroupingStrategyState.instance | ||
| assert.strictEqual(instance1, instance2) | ||
| }) | ||
| }) | ||
|
|
||
| describe('getState', function () { | ||
| it('should return fallback when no state is stored', function () { | ||
| const tryGetStub = sandbox.stub(globals.globalState, 'tryGet').returns(undefined) | ||
| const result = state.getState() | ||
|
|
||
| sinon.assert.calledWith(tryGetStub, 'aws.amazonq.codescan.groupingStrategy', String) | ||
| assert.equal(result, CodeIssueGroupingStrategy.Severity) | ||
| }) | ||
|
|
||
| it('should return stored state when valid', function () { | ||
| const validStrategy = CodeIssueGroupingStrategy.Severity | ||
| sandbox.stub(globals.globalState, 'tryGet').returns(validStrategy) | ||
|
|
||
| const result = state.getState() | ||
|
|
||
| assert.equal(result, validStrategy) | ||
| }) | ||
|
|
||
| it('should return fallback when stored state is invalid', function () { | ||
| const invalidStrategy = 'invalid' | ||
| sandbox.stub(globals.globalState, 'tryGet').returns(invalidStrategy) | ||
|
||
|
|
||
| const result = state.getState() | ||
|
|
||
| assert.equal(result, CodeIssueGroupingStrategy.Severity) | ||
| }) | ||
| }) | ||
|
|
||
| describe('setState', function () { | ||
| it('should update state and fire change event for valid strategy', async function () { | ||
| const validStrategy = CodeIssueGroupingStrategy.FileLocation | ||
| const updateStub = sandbox.stub(globals.globalState, 'update').resolves() | ||
|
|
||
| // Create a spy to watch for event emissions | ||
| const eventSpy = sandbox.spy() | ||
| state.onDidChangeState(eventSpy) | ||
|
|
||
| await state.setState(validStrategy) | ||
|
|
||
| sinon.assert.calledWith(updateStub, 'aws.amazonq.codescan.groupingStrategy', validStrategy) | ||
| sinon.assert.calledWith(eventSpy, validStrategy) | ||
| }) | ||
|
|
||
| it('should use fallback and fire change event for invalid strategy', async function () { | ||
| const invalidStrategy = 'invalid' | ||
| const updateStub = sandbox.stub(globals.globalState, 'update').resolves() | ||
|
|
||
| // Create a spy to watch for event emissions | ||
| const eventSpy = sandbox.spy() | ||
| state.onDidChangeState(eventSpy) | ||
|
|
||
| await state.setState(invalidStrategy) | ||
|
|
||
| sinon.assert.calledWith( | ||
| updateStub, | ||
| 'aws.amazonq.codescan.groupingStrategy', | ||
| CodeIssueGroupingStrategy.Severity | ||
| ) | ||
| sinon.assert.calledWith(eventSpy, CodeIssueGroupingStrategy.Severity) | ||
| }) | ||
| }) | ||
|
|
||
| describe('reset', function () { | ||
| it('should set state to fallback value', async function () { | ||
| const setStateStub = sandbox.stub(state, 'setState').resolves() | ||
|
|
||
| await state.reset() | ||
|
|
||
| sinon.assert.calledWith(setStateStub, CodeIssueGroupingStrategy.Severity) | ||
| }) | ||
| }) | ||
|
|
||
| describe('onDidChangeState', function () { | ||
| it('should allow subscribing to state changes', async function () { | ||
| const listener = sandbox.spy() | ||
| const disposable = state.onDidChangeState(listener) | ||
|
|
||
| await state.setState(CodeIssueGroupingStrategy.Severity) | ||
|
|
||
| sinon.assert.calledWith(listener, CodeIssueGroupingStrategy.Severity) | ||
| disposable.dispose() | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| import { createQuickPickPrompterTester, QuickPickPrompterTester } from 'aws-core-vscode/test' | ||
| import { | ||
| CodeIssueGroupingStrategy, | ||
| CodeIssueGroupingStrategyState, | ||
| createCodeIssueGroupingStrategyPrompter, | ||
| } from 'aws-core-vscode/codewhisperer' | ||
| import sinon from 'sinon' | ||
|
|
||
| const severity = { label: 'Severity', data: CodeIssueGroupingStrategy.Severity } | ||
| const fileLocation = { label: 'File Location', data: CodeIssueGroupingStrategy.FileLocation } | ||
|
|
||
| describe('createCodeIssueGroupingStrategyPrompter', function () { | ||
| let tester: QuickPickPrompterTester<CodeIssueGroupingStrategy> | ||
|
|
||
| beforeEach(function () { | ||
| tester = createQuickPickPrompterTester(createCodeIssueGroupingStrategyPrompter()) | ||
| }) | ||
|
|
||
| it('should list grouping strategies', function () { | ||
| tester.assertItems([severity, fileLocation]) | ||
| }) | ||
|
|
||
| it('should update state on selection', async function () { | ||
| const spy = sinon.spy(CodeIssueGroupingStrategyState.instance, 'setState') | ||
|
||
|
|
||
| tester.selectItems(fileLocation) | ||
| tester.assertSelectedItems(fileLocation) | ||
|
|
||
| spy.calledWith(CodeIssueGroupingStrategy.FileLocation) | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these kinds of tests are very fragile. can you assert the actual state instead of using stubs/mocks?