-
Notifications
You must be signed in to change notification settings - Fork 6
feat(work-items): add query editor for SystemLink Work Items data source #735
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
Draft
shivanshu-ni
wants to merge
31
commits into
main
Choose a base branch
from
users/shivanshu/feat/workitem-query-editor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
bdcb741
Feat(work-items): Initial Boilerplate
shivanshu-ni 769e5fb
Added workitems in example.yaml
shivanshu-ni a3b89df
feat(work-items): add SystemLink Work Items datasource configuration …
shivanshu-ni e28b279
feat(work-items): enhance WorkItemsDataSource and QueryEditor with de…
shivanshu-ni f287de3
feat(work-items): update datasource connection method to use POST for…
shivanshu-ni bb25723
refactor(work-items): remove unused WorkItemsConfigEditor and clean u…
shivanshu-ni fa68b82
refactor(work-items): remove Work Items datasource configuration from…
shivanshu-ni cd898db
Merge branch 'users/shivanshu/feat/workitem-initial' of https://githu…
shivanshu-ni efbfdfc
feat(work-items): refactor query editor and data source logic, add co…
shivanshu-ni ed599a2
feat(work-items): update take value handling in query editor and data…
shivanshu-ni ea014e8
feat(work-items): implement take value normalization and validation i…
shivanshu-ni 7b0dd78
feat(work-items): enhance take value handling in query editor and dat…
shivanshu-ni 08a6d2f
feat(docs): add README for SystemLink Work Items Data Source plugin
shivanshu-ni 15cdb5f
feat(work-items): add initial README for SystemLink Work Items dataso…
shivanshu-ni 29587bd
refactor(work-items): simplify WorkItemsDataSource and update query e…
shivanshu-ni 10b0041
Merge branch 'users/shivanshu/feat/workitem-initial' of https://githu…
shivanshu-ni 51cf0bf
refactor(work-items): remove unused import from WorkItemsDataSource
shivanshu-ni 32294b0
refactor(work-items): extract query editor labels into constants file
shivanshu-ni 20bbb26
Merge branch 'main' of https://github.com/ni/systemlink-grafana-plugi…
shivanshu-ni 7c79ab4
refactor(tests): consolidate imports in WorkItemsQueryEditor test file
shivanshu-ni 91938ef
feat(work-items): add properties selection to WorkItemsQueryEditor an…
shivanshu-ni 1b41eb9
fix(work-items): disambiguate Properties label lookup in query editor…
shivanshu-ni e7494ab
Add work-items acceptance test placeholder
Copilot 7c05a1a
fix(work-items): address review feedback
shivanshu-ni f8c782e
fix(work-items): enhance WorkItemsQueryEditor with validation and que…
shivanshu-ni 713f5e7
fix(work-items): Group order by and decending in one group
shivanshu-ni 9f11b72
fix(work-items): replace hardcoded take value with DEFAULT_TAKE const…
shivanshu-ni d05b387
feat(work-items): update default query properties (#738)
shivanshu-ni d0afbcb
fix(work-items): streamline WorkItemsQueryEditor layout and remove un…
shivanshu-ni 785eea3
Merge branch 'users/shivanshu/feat/workitem-query-editor' of https://…
shivanshu-ni 11f8c61
fix(tests): adjust offsetHeight mock and enhance properties output va…
shivanshu-ni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 91 additions & 3 deletions
94
src/datasources/work-items/components/WorkItemsQueryEditor.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,102 @@ | ||
| import { screen } from '@testing-library/react'; | ||
| import { fireEvent, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { setupRenderer } from 'test/fixtures'; | ||
| import { labels, propertiesErrorMessages, takeErrorMessages, typesErrorMessages } from '../constants/QueryEditor.constants'; | ||
| import { WorkItemsDataSource } from '../WorkItemsDataSource'; | ||
| import { OutputType, WorkItemPropertiesOptions, WorkItemTypeOptions } from '../types'; | ||
| import { WorkItemsQueryEditor } from './WorkItemsQueryEditor'; | ||
|
|
||
| describe('WorkItemsQueryEditor', () => { | ||
| it('shows placeholder message', () => { | ||
| it('renders controls', () => { | ||
| const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource); | ||
|
|
||
| render({}); | ||
|
|
||
| expect(screen.getByText('Work Items datasource query controls will be added in follow-up stories.')).toBeInTheDocument(); | ||
| expect(screen.getByRole('radio', { name: OutputType.Properties })).toBeTruthy(); | ||
| expect(screen.getByRole('radio', { name: OutputType.TotalCount })).toBeTruthy(); | ||
| expect(screen.getByText(labels.types)).toBeTruthy(); | ||
| expect(screen.getAllByText(labels.properties)[1]).toBeTruthy(); | ||
| expect(screen.getByText(labels.orderBy)).toBeTruthy(); | ||
| expect(screen.getByText(labels.descending)).toBeTruthy(); | ||
| expect(screen.getByText(labels.take)).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('hides properties-only controls for total count output', async () => { | ||
| const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource); | ||
|
|
||
| render({}); | ||
| await userEvent.click(screen.getByRole('radio', { name: OutputType.TotalCount })); | ||
|
|
||
| expect(screen.getAllByText(labels.properties)).toHaveLength(1); | ||
| expect(screen.queryByText(labels.orderBy)).toBeNull(); | ||
| expect(screen.queryByText(labels.descending)).toBeNull(); | ||
| expect(screen.queryByText(labels.take)).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders default selected properties for properties output', () => { | ||
| const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource); | ||
|
|
||
| render({}); | ||
|
|
||
| expect(screen.getByText('Work item ID')).toBeTruthy(); | ||
|
shivanshu-ni marked this conversation as resolved.
Outdated
|
||
| expect(screen.getAllByText(labels.properties)[1]).toBeTruthy(); | ||
|
shivanshu-ni marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| describe('validation', () => { | ||
| it('shows types validation error when all types are removed instead of restoring the default selection', async () => { | ||
| const offsetHeightSpy = jest.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(30); | ||
|
|
||
| try { | ||
| const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource); | ||
| const [onChange] = render({ types: [WorkItemTypeOptions.WorkOrders] }); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', { name: 'Remove Work orders' })); | ||
|
|
||
| expect(screen.getByText(typesErrorMessages.atLeastOneRequired)).toBeTruthy(); | ||
| expect(onChange).toHaveBeenLastCalledWith(expect.objectContaining({ types: [] })); | ||
| } finally { | ||
| offsetHeightSpy.mockRestore(); | ||
| } | ||
| }); | ||
|
|
||
| it('shows properties validation error when all properties are removed, and clears it (without restoring defaults) when a property is re-added', async () => { | ||
| const offsetHeightSpy = jest.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(30); | ||
|
|
||
| try { | ||
| const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource); | ||
| const [onChange] = render({ properties: [WorkItemPropertiesOptions.ID] }); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', { name: 'Remove Work item ID' })); | ||
|
|
||
| expect(screen.getByText(propertiesErrorMessages.atLeastOneRequired)).toBeTruthy(); | ||
| expect(onChange).toHaveBeenLastCalledWith(expect.objectContaining({ properties: [] })); | ||
|
|
||
| const propertiesCombobox = screen.getAllByRole('combobox')[1]; | ||
| await userEvent.click(propertiesCombobox); | ||
| await userEvent.type(propertiesCombobox, 'Work item name'); | ||
| await userEvent.click(await screen.findByRole('option', { name: 'Work item name' })); | ||
|
|
||
| expect(screen.queryByText(propertiesErrorMessages.atLeastOneRequired)).toBeNull(); | ||
| expect(onChange).toHaveBeenLastCalledWith( | ||
| expect.objectContaining({ properties: [WorkItemPropertiesOptions.NAME] }) | ||
| ); | ||
| } finally { | ||
| offsetHeightSpy.mockRestore(); | ||
| } | ||
| }); | ||
|
|
||
| it('shows take validation error and suppresses query execution for invalid take input', () => { | ||
| const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource); | ||
|
|
||
| const [onChange, onRunQuery] = render({}); | ||
| const takeInput = screen.getByRole('spinbutton'); | ||
|
|
||
| fireEvent.change(takeInput, { target: { value: '-5' } }); | ||
| fireEvent.blur(takeInput); | ||
|
|
||
| expect(screen.getByText(takeErrorMessages.greaterOrEqualToZero)).toBeTruthy(); | ||
| expect(onChange).not.toHaveBeenCalled(); | ||
| expect(onRunQuery).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
| }); | ||
|
shivanshu-ni marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.