Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bdcb741
Feat(work-items): Initial Boilerplate
shivanshu-ni Aug 12, 2026
769e5fb
Added workitems in example.yaml
shivanshu-ni Aug 12, 2026
a3b89df
feat(work-items): add SystemLink Work Items datasource configuration …
shivanshu-ni Aug 12, 2026
e28b279
feat(work-items): enhance WorkItemsDataSource and QueryEditor with de…
shivanshu-ni Aug 16, 2026
f287de3
feat(work-items): update datasource connection method to use POST for…
shivanshu-ni Aug 19, 2026
bb25723
refactor(work-items): remove unused WorkItemsConfigEditor and clean u…
shivanshu-ni Aug 19, 2026
fa68b82
refactor(work-items): remove Work Items datasource configuration from…
shivanshu-ni Aug 19, 2026
cd898db
Merge branch 'users/shivanshu/feat/workitem-initial' of https://githu…
shivanshu-ni Aug 19, 2026
efbfdfc
feat(work-items): refactor query editor and data source logic, add co…
shivanshu-ni Aug 19, 2026
ed599a2
feat(work-items): update take value handling in query editor and data…
shivanshu-ni Aug 19, 2026
ea014e8
feat(work-items): implement take value normalization and validation i…
shivanshu-ni Aug 19, 2026
7b0dd78
feat(work-items): enhance take value handling in query editor and dat…
shivanshu-ni Aug 19, 2026
08a6d2f
feat(docs): add README for SystemLink Work Items Data Source plugin
shivanshu-ni Aug 20, 2026
15cdb5f
feat(work-items): add initial README for SystemLink Work Items dataso…
shivanshu-ni Aug 24, 2026
29587bd
refactor(work-items): simplify WorkItemsDataSource and update query e…
shivanshu-ni Aug 24, 2026
10b0041
Merge branch 'users/shivanshu/feat/workitem-initial' of https://githu…
shivanshu-ni Aug 24, 2026
51cf0bf
refactor(work-items): remove unused import from WorkItemsDataSource
shivanshu-ni Aug 24, 2026
32294b0
refactor(work-items): extract query editor labels into constants file
shivanshu-ni Aug 27, 2026
20bbb26
Merge branch 'main' of https://github.com/ni/systemlink-grafana-plugi…
shivanshu-ni Aug 28, 2026
7c79ab4
refactor(tests): consolidate imports in WorkItemsQueryEditor test file
shivanshu-ni Aug 28, 2026
91938ef
feat(work-items): add properties selection to WorkItemsQueryEditor an…
shivanshu-ni Aug 28, 2026
1b41eb9
fix(work-items): disambiguate Properties label lookup in query editor…
shivanshu-ni Aug 28, 2026
e7494ab
Add work-items acceptance test placeholder
Copilot Aug 28, 2026
7c05a1a
fix(work-items): address review feedback
shivanshu-ni Aug 29, 2026
f8c782e
fix(work-items): enhance WorkItemsQueryEditor with validation and que…
shivanshu-ni Aug 31, 2026
713f5e7
fix(work-items): Group order by and decending in one group
shivanshu-ni Sep 1, 2026
9f11b72
fix(work-items): replace hardcoded take value with DEFAULT_TAKE const…
shivanshu-ni Sep 1, 2026
d05b387
feat(work-items): update default query properties (#738)
shivanshu-ni Sep 2, 2026
d0afbcb
fix(work-items): streamline WorkItemsQueryEditor layout and remove un…
shivanshu-ni Sep 2, 2026
785eea3
Merge branch 'users/shivanshu/feat/workitem-query-editor' of https://…
shivanshu-ni Sep 2, 2026
11f8c61
fix(tests): adjust offsetHeight mock and enhance properties output va…
shivanshu-ni Sep 2, 2026
7023866
fix(tests): update userEvent usage in WorkItemsQueryEditor tests for …
shivanshu-ni Sep 2, 2026
45adbd1
fix(tests): remove unnecessary typing in WorkItemsQueryEditor test fo…
shivanshu-ni Sep 2, 2026
3c0f23d
fix(tests): simplify user interactions in WorkItemsQueryEditor tests …
shivanshu-ni Sep 2, 2026
f6c46f4
fix(tests): update WorkItemsQueryEditor tests to use new combobox and…
shivanshu-ni Sep 2, 2026
85d20e8
fix(tests): update WorkItemsQueryEditor and WorkItemsDataSource tests…
shivanshu-ni Sep 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
32 changes: 24 additions & 8 deletions src/datasources/work-items/WorkItemsDataSource.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { WorkItemsDataSource } from './WorkItemsDataSource';
import { setupDataSource } from 'test/fixtures';
import { OrderByOptions, OutputType, WorkItemPropertiesOptions, WorkItemTypeOptions } from './types';

describe('WorkItemsDataSource', () => {
it('returns an empty placeholder frame', async () => {
it('applies expected default query values', () => {
const [datasource] = setupDataSource(WorkItemsDataSource);

const result = await datasource.runQuery({ refId: 'A' }, { scopedVars: {} } as any);
expect(result).toEqual({ refId: 'A', name: 'A', fields: [] });
const query = datasource.prepareQuery({ refId: 'A' });

expect(query.outputType).toBe(OutputType.Properties);
expect(query.types).toEqual(Object.values(WorkItemTypeOptions));
expect(query.properties).toEqual([
WorkItemPropertiesOptions.NAME,
WorkItemPropertiesOptions.STATE,
WorkItemPropertiesOptions.ASSIGNED_TO,
WorkItemPropertiesOptions.PLANNED_START_DATE,
WorkItemPropertiesOptions.DUE_DATE,
]);
expect(query.orderBy).toBe(OrderByOptions.UPDATED_AT);
expect(query.descending).toBe(true);
expect(query.take).toBe(1000);
});

it('tests datasource connection against the work-items service endpoint', async () => {
Expand All @@ -15,11 +28,14 @@ describe('WorkItemsDataSource', () => {

const result = await datasource.testDatasource();

expect(postSpy).toHaveBeenCalledWith(
'/niworkitem/v1/query-workitems',
{ take: 1 },
{ showErrorAlert: false }
);
expect(postSpy).toHaveBeenCalledWith('/niworkitem/v1/query-workitems', { take: 1 }, { showErrorAlert: false });
expect(result.status).toBe('success');
});

it('bubbles up exception when datasource connectivity check fails', async () => {
const [datasource] = setupDataSource(WorkItemsDataSource);
jest.spyOn(datasource, 'post').mockRejectedValue(new Error('Failed'));

await expect(datasource.testDatasource()).rejects.toThrow('Failed');
});
});
25 changes: 23 additions & 2 deletions src/datasources/work-items/WorkItemsDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import {
} from '@grafana/data';
import { BackendSrv, TemplateSrv, getBackendSrv, getTemplateSrv } from '@grafana/runtime';
import { DataSourceBase } from 'core/DataSourceBase';
import { WorkItemsQuery } from './types';
import {
OrderByOptions,
OutputType,
WorkItemPropertiesOptions,
WorkItemsQuery,
WorkItemTypeOptions,
} from './types';
import { DEFAULT_TAKE } from './constants';

export class WorkItemsDataSource extends DataSourceBase<WorkItemsQuery> {
constructor(
Expand All @@ -20,8 +27,22 @@ export class WorkItemsDataSource extends DataSourceBase<WorkItemsQuery> {
baseUrl = `${this.instanceSettings.url}/niworkitem/v1`;
queryWorkItemsUrl = `${this.baseUrl}/query-workitems`;

defaultQuery = {};
defaultQuery = {
outputType: OutputType.Properties,
types: Object.values(WorkItemTypeOptions),
Comment thread
richie-ni marked this conversation as resolved.
properties: [
WorkItemPropertiesOptions.NAME,
WorkItemPropertiesOptions.STATE,
WorkItemPropertiesOptions.ASSIGNED_TO,
WorkItemPropertiesOptions.PLANNED_START_DATE,
WorkItemPropertiesOptions.DUE_DATE,
],
orderBy: OrderByOptions.UPDATED_AT,
descending: true,
take: DEFAULT_TAKE,
};

// TODO: AB#3923375 - Query work items and return the requested properties instead of an empty frame.
async runQuery(query: WorkItemsQuery, _options: DataQueryRequest<WorkItemsQuery>): Promise<DataFrameDTO> {
return {
Comment thread
shivanshu-ni marked this conversation as resolved.
refId: query.refId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { fireEvent, screen } from '@testing-library/react';
import { OutputType } from '../types';
import { labels } from '../constants/QueryEditor.constants';

/**
* Page object collecting the DOM selectors used by WorkItemsQueryEditor.test.tsx,
* so the test file only reads intent, not query-library boilerplate.
*/
export const workItemsQueryEditorPage = {
outputTypeRadioButton: (value: OutputType) => screen.getByRole('radio', { name: value }),

// MultiCombobox (used for Types/Properties) doesn't forward its id to the underlying
// downshift input, so it has no accessible name; select by position among comboboxes instead.
typesMultiCombobox: () => screen.queryAllByRole('combobox')[0] ?? null,
propertiesMultiCombobox: () => screen.queryAllByRole('combobox')[1] ?? null,
orderByCombobox: () => screen.queryByRole('combobox', { name: labels.orderBy }),
descendingSwitch: () => screen.queryByRole('switch', { name: labels.descending }),
takeLimitInput: () => screen.getByRole('spinbutton'),
optionalTakeLimitInput: () => screen.queryByRole('spinbutton'),
setTakeLimit: (value: string) => {
const takeLimitInput = screen.getByRole('spinbutton');
fireEvent.change(takeLimitInput, { target: { value } });
fireEvent.blur(takeLimitInput);
},

removeOptionButton: (name: string) => screen.getByRole('button', { name: `Remove ${name}` }),
typeSelectOption: (name: string) => screen.findByRole('option', { name }),
propertySelectOption: (name: string) => screen.findByRole('option', { name }),
propertyOptionCheckbox: (name: string) => screen.getByRole('checkbox', { name }),

getErrorByMessage: (message: string) => screen.queryByText(message),
};
159 changes: 156 additions & 3 deletions src/datasources/work-items/components/WorkItemsQueryEditor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,167 @@
import { screen } from '@testing-library/react';
import { fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { setupRenderer } from 'test/fixtures';
import { propertiesErrorMessages, takeErrorMessages, typesErrorMessages } from '../constants/QueryEditor.constants';
import { TAKE_LIMIT } from '../constants';
import { WorkItemsDataSource } from '../WorkItemsDataSource';
import { OutputType, WorkItemPropertiesOptions, WorkItemTypeOptions } from '../types';
import { WorkItemsQueryEditor } from './WorkItemsQueryEditor';
import { workItemsQueryEditorPage as page } from './WorkItemsQueryEditor.page';

describe('WorkItemsQueryEditor', () => {
it('shows placeholder message', () => {
it('should show all controls when the editor renders', () => {
const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource);

render({});

expect(screen.getByText('Work Items datasource query controls will be added in follow-up stories.')).toBeInTheDocument();
expect(page.outputTypeRadioButton(OutputType.Properties)).toBeInTheDocument();
expect(page.outputTypeRadioButton(OutputType.TotalCount)).toBeInTheDocument();
expect(page.typesMultiCombobox()).toBeVisible();
expect(page.propertiesMultiCombobox()).toBeVisible();
expect(page.orderByCombobox()).toBeVisible();
expect(page.descendingSwitch()).toBeInTheDocument();
expect(page.optionalTakeLimitInput()).toBeVisible();
});

it('should hide properties-only controls when the output type is total count', async () => {
const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource);

render({});
await userEvent.click(page.outputTypeRadioButton(OutputType.TotalCount));

expect(page.propertiesMultiCombobox()).toBeNull();
expect(page.orderByCombobox()).toBeNull();
expect(page.descendingSwitch()).toBeNull();
expect(page.optionalTakeLimitInput()).toBeNull();
});

it('should show default selected properties when the output type is properties', async () => {
const offsetHeightSpy = jest.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(30);

try {
const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource);
render({});

const propertiesCombobox = page.propertiesMultiCombobox()!;
const checkedLabels = ['Work item name', 'State', 'Assigned to', 'Planned start date', 'Due date'];

fireEvent.click(propertiesCombobox);
for (const label of checkedLabels) {
Comment thread
shivanshu-ni marked this conversation as resolved.
// fireEvent.change is used here to filter/search the dropdown options; it does not select or deselect them.
fireEvent.change(propertiesCombobox, { target: { value: label } });
expect(page.propertyOptionCheckbox(label)).toBeChecked();
}

fireEvent.change(propertiesCombobox, { target: { value: 'Work item ID' } });
expect(page.propertyOptionCheckbox('Work item ID')).not.toBeChecked();
} finally {
offsetHeightSpy.mockRestore();
}
});

describe('validation error', () => {
it('should not show types, properties, or take validation errors when the editor renders', () => {
const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource);

render({});

expect(page.getErrorByMessage(typesErrorMessages.atLeastOneRequired)).toBeNull();
expect(page.getErrorByMessage(propertiesErrorMessages.atLeastOneRequired)).toBeNull();
expect(page.getErrorByMessage(takeErrorMessages.greaterOrEqualToZero)).toBeNull();
expect(page.getErrorByMessage(takeErrorMessages.lessOrEqualToTenThousand)).toBeNull();
});

it('should clear the types validation error when a type is re-added after all types are removed', async () => {
const offsetHeightSpy = jest.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(30);

try {
const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource);
const [onChange, onRunQuery] = render({ types: [WorkItemTypeOptions.WorkOrders] });

await userEvent.click(page.removeOptionButton('Work orders'));

expect(page.getErrorByMessage(typesErrorMessages.atLeastOneRequired)).toBeVisible();
expect(onChange).toHaveBeenLastCalledWith(expect.objectContaining({ types: [] }));
expect(onRunQuery).not.toHaveBeenCalled();

const typesCombobox = page.typesMultiCombobox()!;
await userEvent.click(typesCombobox);
await userEvent.click(await page.typeSelectOption('Work orders'));

expect(page.getErrorByMessage(typesErrorMessages.atLeastOneRequired)).toBeNull();
expect(onChange).toHaveBeenLastCalledWith(
expect.objectContaining({ types: [WorkItemTypeOptions.WorkOrders] })
);
expect(onRunQuery).toHaveBeenCalled();
} finally {
offsetHeightSpy.mockRestore();
}
});

it('should clear the properties validation error when a property is re-added after all properties are removed', async () => {
const offsetHeightSpy = jest.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(30);

try {
const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource);
const [onChange, onRunQuery] = render({ properties: [WorkItemPropertiesOptions.ID] });

await userEvent.click(page.removeOptionButton('Work item ID'));

expect(page.getErrorByMessage(propertiesErrorMessages.atLeastOneRequired)).toBeVisible();
expect(onChange).toHaveBeenLastCalledWith(expect.objectContaining({ properties: [] }));
expect(onRunQuery).not.toHaveBeenCalled();

const propertiesCombobox = page.propertiesMultiCombobox()!;
await userEvent.click(propertiesCombobox);
await userEvent.click(await page.propertySelectOption('Work item name'));

expect(page.getErrorByMessage(propertiesErrorMessages.atLeastOneRequired)).toBeNull();
expect(onChange).toHaveBeenLastCalledWith(
expect.objectContaining({ properties: [WorkItemPropertiesOptions.NAME] })
);
expect(onRunQuery).toHaveBeenCalled();
} finally {
offsetHeightSpy.mockRestore();
}
});

it('should show a take validation error and suppress query execution when take input is invalid', () => {
const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource);

const [onChange, onRunQuery] = render({});

page.setTakeLimit('-5');

expect(page.getErrorByMessage(takeErrorMessages.greaterOrEqualToZero)).toBeVisible();
expect(onChange).not.toHaveBeenCalled();
expect(onRunQuery).not.toHaveBeenCalled();
});

it('should show a take validation error and suppress query execution when take exceeds the maximum limit', () => {
const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource);

const [onChange, onRunQuery] = render({});

page.setTakeLimit(`${TAKE_LIMIT + 1}`);

expect(page.getErrorByMessage(takeErrorMessages.lessOrEqualToTenThousand)).toBeVisible();
expect(onChange).not.toHaveBeenCalled();
expect(onRunQuery).not.toHaveBeenCalled();
});

it('should clear the take validation error and run the query when a valid take value is entered', () => {
const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource);

const [onChange, onRunQuery] = render({});

page.setTakeLimit('-5');
expect(page.getErrorByMessage(takeErrorMessages.greaterOrEqualToZero)).toBeVisible();

page.setTakeLimit('500');

expect(page.getErrorByMessage(takeErrorMessages.greaterOrEqualToZero)).toBeNull();
expect(onChange).toHaveBeenLastCalledWith(expect.objectContaining({ take: 500 }));
expect(onRunQuery).toHaveBeenCalled();
});
});
});
Loading
Loading