Skip to content

Commit

Permalink
DCAT-2: Fix the usage score order
Browse files Browse the repository at this point in the history
DCAT-2: Trying to ensure test passing

DCAT-2: Test removing the waitFor

DCAT-2: Use env var for more consistency

DCAT-2: Increase timeout that available to the waitFor

DCAT-2: Fix the usage score order
  • Loading branch information
eudoroolivares2016 committed Jan 28, 2025
1 parent 1920e11 commit a9081fa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/ts/component/SearchResultsList/SearchResultsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ export const SearchResultsList: React.FC<SearchResultsListProps> = ({

const rows = [10, 20, 50, 100]

const descUsageScore = '-usage_score'

const sortKeys: SortKey[] = [
{
key: 'relevance',
value: 'Relevance'
},
{
key: 'usage_score',
key: descUsageScore,
value: 'Usage'
},
{
Expand Down Expand Up @@ -255,7 +257,7 @@ export const SearchResultsList: React.FC<SearchResultsListProps> = ({
<Dropdown className="search-result-sort__dropdown">
<Dropdown.Toggle variant="none">
<span className="search-result-sort__label">SORT:</span>
<span className="search-result-sort__value">{currentSortKey === 'usage_score' ? 'usage' : currentSortKey }</span>
<span className="search-result-sort__value">{currentSortKey === descUsageScore ? 'usage' : currentSortKey }</span>
<svg className="search-result-sort__svg-icon" width="10" height="10" viewBox="0 0 8 6" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fillRule="evenodd" clipRule="evenodd" d="M4 3.855L7.233.6 8 1.372 4 5.4 0 1.372.767.6 4 3.855z" fill="black" />
</svg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ describe('SearchResultList', () => {

describe('Sort key', () => {
describe('when selecting a sort key', () => {
test('calls setQuerySort with usage_score', async () => {
test('calls setQuerySort with -usage_score', async () => {
const { props, user } = setup()

await waitFor(async () => {
Expand All @@ -275,7 +275,7 @@ describe('SearchResultList', () => {
})

expect(props.setQuerySort).toHaveBeenCalledTimes(1)
expect(props.setQuerySort).toHaveBeenCalledWith('usage_score')
expect(props.setQuerySort).toHaveBeenCalledWith('-usage_score')
})

test('calls setQuerySort with start_data', async () => {
Expand Down
8 changes: 4 additions & 4 deletions src/ts/pages/DataCatalog/__tests__/DataCatalog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ describe('DataCatalog', () => {

// Click the Next button
await waitFor(async () => {
await user.click(screen.getByRole('button', { name: 'Next' }))
})
await user.click(await screen.findByRole('button', { name: 'Next' }))
}, { timeout: 5000 })

const pagination = await screen.findByRole('list', { name: /pagination/i })
const pageItems = within(pagination).getAllByRole('listitem')
Expand Down Expand Up @@ -462,7 +462,7 @@ describe('DataCatalog', () => {

expect(await screen.findByText('Found collection 1')).toBeTruthy()

setupMockResponse('page_num=1&sort_key=usage_score')
setupMockResponse('page_num=1&sort_key=-usage_score')

await waitFor(async () => {
await user.click(screen.getByRole('button', { name: /SORT:/ }))
Expand All @@ -477,7 +477,7 @@ describe('DataCatalog', () => {

describe('when loading a URL containing a sort_key', () => {
test('loads the page, using and displaying the appropriate sort key', async () => {
const params = 'sort_key=usage_score'
const params = 'sort_key=-usage_score'

setupMockResponse(params, 1, 1, 'Found ')

Expand Down

0 comments on commit a9081fa

Please sign in to comment.