Skip to content

Commit

Permalink
Merge pull request #226 from IQSS/fix/220-filtering-on-files-tab-and-…
Browse files Browse the repository at this point in the history
…there-is-only-one-file

220 - Fix: Filters disappear when the filters results is 1 file
  • Loading branch information
GPortas authored Dec 11, 2023
2 parents 333c7c6 + 240a4fc commit 9f73f62
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/files/domain/models/FileCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ export class FileCriteria {
searchText
)
}

get someFilterApplied(): boolean {
return (
this.filterByType !== undefined ||
this.filterByAccess !== undefined ||
this.filterByTag !== undefined ||
this.searchText !== undefined
)
}
}

export enum FileSortByOption {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function FileCriteriaForm({
filesCountInfo
}: FileCriteriaInputsProps) {
const showFileCriteriaInputs =
filesCountInfo && filesCountInfo.total >= MINIMUM_FILES_TO_SHOW_CRITERIA_INPUTS
filesCountInfo &&
(filesCountInfo.total >= MINIMUM_FILES_TO_SHOW_CRITERIA_INPUTS || criteria.someFilterApplied)
return (
<div className={styles['criteria-section']}>
<Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,23 @@ describe('FileCriteriaForm', () => {

cy.findByLabelText('Search').should('have.value', 'test')
})

it('renders the file criteria if there are less than 2 files but there is a filter applied', () => {
const criteria = new FileCriteria()
.withFilterByTag('document')
.withFilterByAccess(FileAccessOption.PUBLIC)
.withFilterByType('image/png')

cy.customMount(
<FileCriteriaForm
criteria={criteria}
onCriteriaChange={onCriteriaChange}
filesCountInfo={FilesCountInfoMother.create({ total: 1 })}
/>
)

cy.findByRole('button', { name: 'File Type: PNG Image' }).should('exist')
cy.findByRole('button', { name: 'Access: Public' }).should('exist')
cy.findByRole('button', { name: 'File Tags: Document' }).should('exist')
})
})
21 changes: 20 additions & 1 deletion tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ describe('Dataset', () => {
})
})

it('applies filters to the Files Table in the correct order', () => {
it.only('applies filters to the Files Table in the correct order', () => {
const files = [
FileHelper.create('csv', {
description: 'Some description',
Expand Down Expand Up @@ -470,6 +470,25 @@ describe('Dataset', () => {
cy.findByText('blob-3').should('not.exist')
cy.get('table > tbody > tr').eq(0).should('contain', 'blob-5')
cy.get('table > tbody > tr').eq(1).should('contain', 'blob-4')

cy.findByLabelText('Search').clear().type('blob-5{enter}', { force: true })

cy.findByText('1 to 1 of 1 Files').should('exist')
cy.findByText('blob').should('not.exist')
cy.findByText('blob-1').should('not.exist')
cy.findByText('blob-2').should('not.exist')
cy.findByText('blob-3').should('not.exist')
cy.findByText('blob-4').should('not.exist')
cy.findByText('blob-5').should('exist')

cy.findByLabelText('Search').clear().type('{enter}', { force: true })
cy.findByText('1 to 3 of 3 Files').should('exist')
cy.findByText('blob').should('exist')
cy.findByText('blob-1').should('not.exist')
cy.findByText('blob-2').should('not.exist')
cy.findByText('blob-3').should('not.exist')
cy.findByText('blob-4').should('exist')
cy.findByText('blob-5').should('exist')
})
})

Expand Down

0 comments on commit 9f73f62

Please sign in to comment.