Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ exports[`Results Table Should match snapshot 1`] = `
id="search-base-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -618,6 +619,7 @@ exports[`Results Table Should match snapshot 1`] = `
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -3089,6 +3091,7 @@ exports[`Results Table for MannWhitneyResultsItem for mann-whitney-u testVersion
id="search-base-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -3374,6 +3377,7 @@ exports[`Results Table for MannWhitneyResultsItem for mann-whitney-u testVersion
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down
126 changes: 126 additions & 0 deletions src/__tests__/Search/SearchInputAndResults.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import fetchMock from '@fetch-mock/jest';
import userEvent from '@testing-library/user-event';

import SearchInputAndResults from '../../components/Search/SearchInputAndResults';
import getTestData from '../utils/fixtures';
import { screen, render } from '../utils/test-utils';

describe('SearchInputAndResults - Auto-select full hash', () => {
const mockOnToggle = jest.fn();
const { testData } = getTestData();
const fullHash = testData[7].revision;

beforeEach(() => {
mockOnToggle.mockClear();
});

it('should auto-select when pasting a full hash for base revision', async () => {
fetchMock.get(
`glob:https://treeherder.mozilla.org/api/project/try/push/*`,
{ results: testData },
);

const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });

render(
<SearchInputAndResults
compact={false}
inputPlaceholder='Search base'
displayedRevisions={[]}
searchType='base'
repository='try'
onSearchResultsToggle={mockOnToggle}
listItemComponent='radio'
/>,
);

const input = screen.getByRole('textbox');
await user.type(input, fullHash);

// Assert auto-select happened
expect(mockOnToggle).toHaveBeenCalledWith(testData[7]);
expect(input).toHaveValue(''); // Input cleared
});

it('should auto-select when pasting a full hash for new revision (not already selected)', async () => {
fetchMock.get(
`glob:https://treeherder.mozilla.org/api/project/try/push/*`,
{ results: testData },
);

const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });

render(
<SearchInputAndResults
compact={false}
inputPlaceholder='Search new'
displayedRevisions={[]} // Not selected yet
searchType='new'
repository='try'
onSearchResultsToggle={mockOnToggle}
listItemComponent='checkbox'
/>,
);

const input = screen.getByRole('textbox');
await user.type(input, fullHash);

expect(mockOnToggle).toHaveBeenCalledWith(testData[7]);
expect(input).toHaveValue('');
});

it('should not auto-select if full hash is already selected for new revision', async () => {
fetchMock.get(
`glob:https://treeherder.mozilla.org/api/project/try/push/*`,
{ results: testData },
);

const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });

render(
<SearchInputAndResults
compact={false}
inputPlaceholder='Search new'
displayedRevisions={[testData[7]]} // Already selected
searchType='new'
repository='try'
onSearchResultsToggle={mockOnToggle}
listItemComponent='checkbox'
/>,
);

const input = screen.getByRole('textbox');
await user.type(input, fullHash);

expect(mockOnToggle).not.toHaveBeenCalled(); // No toggle
expect(input).toHaveValue(''); // Still cleared
});

it('should show dropdown for partial hash (no auto-select)', async () => {
fetchMock.get(
`glob:https://treeherder.mozilla.org/api/project/try/push/*`,
{ results: testData },
);

const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });

render(
<SearchInputAndResults
compact={false}
inputPlaceholder='Search base'
displayedRevisions={[]}
searchType='base'
repository='try'
onSearchResultsToggle={mockOnToggle}
listItemComponent='radio'
/>,
);

const input = screen.getByRole('textbox');
await user.type(input, 'coconut'); // Partial hash

expect(mockOnToggle).not.toHaveBeenCalled();
// Dropdown should appear with results
await screen.findByText(/no arms left/); // From testData
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ exports[`Compare Over Time renders correctly in Search View: Initial state for t
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -1167,6 +1168,7 @@ exports[`Compare Over Time should have an edit mode in Results View: After click
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -1957,6 +1959,7 @@ exports[`Compare Over Time should remove the checked revision once X button is c
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -2855,6 +2858,7 @@ exports[`Compare Over Time should update base repo, revisions and time-range aft
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down
17 changes: 16 additions & 1 deletion src/__tests__/Search/__snapshots__/CompareWithBase.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ exports[`Compare With Base renders correctly when there are no results: Initial
id="search-base-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -446,6 +447,7 @@ exports[`Compare With Base renders correctly when there are no results: Initial
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -941,6 +943,7 @@ exports[`Compare With Base should have an edit mode in Results View: After click
id="search-base-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -1246,6 +1249,7 @@ exports[`Compare With Base should have an edit mode in Results View: After click
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -1455,6 +1459,7 @@ exports[`Compare With Base should have an edit mode in Results View: After click
id="search-base-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -1760,6 +1765,7 @@ exports[`Compare With Base should have an edit mode in Results View: After click
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -2133,6 +2139,7 @@ exports[`Compare With Base should have an edit mode in Results View: Initial sta
id="search-base-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -2438,6 +2445,7 @@ exports[`Compare With Base should have an edit mode in Results View: Initial sta
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -2815,6 +2823,7 @@ exports[`Compare With Base should have an edit mode in Results View: after remov
id="search-base-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -2960,6 +2969,7 @@ exports[`Compare With Base should have an edit mode in Results View: after remov
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -3369,6 +3379,7 @@ exports[`Compare With Base should have an edit mode in Results View: after remov
id="search-base-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -3674,6 +3685,7 @@ exports[`Compare With Base should have an edit mode in Results View: after remov
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -4077,6 +4089,7 @@ exports[`Compare With Base should remove the checked revision once X button is c
id="search-base-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -4222,6 +4235,7 @@ exports[`Compare With Base should remove the checked revision once X button is c
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -4646,6 +4660,7 @@ exports[`Compare With Base should remove the checked revision once X button is c
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -4773,7 +4788,7 @@ exports[`Compare With Base should remove the checked revision once X button is c
exports[`Compare With Base updates the framework and url when a new one is selected: after awsy is selected 1`] = `
<ul
class="MuiList-root MuiList-padding MuiMenu-list css-1toxriw-MuiList-root-MuiMenu-list"
id="_r_5n_"
id="_r_5o_"
role="listbox"
tabindex="-1"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ exports[`Search Containter should match snapshot 1`] = `
id="search-base-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -307,6 +308,7 @@ exports[`Search Containter should match snapshot 1`] = `
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down Expand Up @@ -731,6 +733,7 @@ exports[`Search Containter should match snapshot 1`] = `
id="search-new-input"
placeholder="Search by revision ID or author email"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
Expand Down
Loading