diff --git a/public/app/features/search/components/SearchCard.tsx b/public/app/features/search/components/SearchCard.tsx
index f9b77ac4302..a095f31cd5d 100644
--- a/public/app/features/search/components/SearchCard.tsx
+++ b/public/app/features/search/components/SearchCard.tsx
@@ -122,7 +122,7 @@ export function SearchCard({ editable, item, onTagSelected, onToggleChecked }: P
{
+ const dashboardsData: DataFrame = {
+ fields: [
+ {
+ name: 'kind',
+ type: FieldType.string,
+ config: {},
+ values: new ArrayVector([DashboardSearchItemType.DashDB]),
+ },
+ { name: 'name', type: FieldType.string, config: {}, values: new ArrayVector(['My dashboard 1', 'dash2']) },
+ { name: 'uid', type: FieldType.string, config: {}, values: new ArrayVector(['my-dashboard-1', 'dash-2']) },
+ { name: 'url', type: FieldType.string, config: {}, values: new ArrayVector(['/my-dashbaord-1', '/dash-2']) },
+ ],
+ length: 2,
+ };
+ const mockSearchResult: QueryResponse = {
+ isItemLoaded: jest.fn(),
+ loadMoreItems: jest.fn(),
+ totalRows: dashboardsData.length,
+ view: new DataFrameView(dashboardsData),
+ };
+
+ const baseProps = {
+ response: mockSearchResult,
+ width: 800,
+ height: 600,
+ clearSelection: jest.fn(),
+ onTagSelected: jest.fn(),
+ keyboardEvents: new Observable(),
+ };
+
+ it('should render grid of dashboards', () => {
+ render();
+ expect(screen.getByTestId(selectors.components.Search.dashboardCard('My dashboard 1'))).toBeInTheDocument();
+ expect(screen.getByTestId(selectors.components.Search.dashboardCard('dash2'))).toBeInTheDocument();
+ });
+
+ it('should not render checkboxes for non-editable results', async () => {
+ render();
+ expect(screen.queryByRole('checkbox')).toBeNull();
+ await waitFor(() => expect(screen.queryAllByRole('checkbox')).toHaveLength(0));
+ });
+
+ it('should render checkboxes for editable results ', async () => {
+ const mockSelectionToggle = jest.fn();
+ const mockSelection = jest.fn();
+ render();
+
+ await waitFor(() => expect(screen.queryAllByRole('checkbox')).toHaveLength(2));
+ fireEvent.click(await screen.findByRole('checkbox', { name: /Select dashboard dash2/i }));
+ expect(mockSelectionToggle).toHaveBeenCalledWith('dashboard', 'dash-2');
+ expect(mockSelectionToggle).toHaveBeenCalledTimes(1);
+ });
+});