Skip to content

Commit

Permalink
Merge pull request #581 from IQSS/fix/481-file-upload-test
Browse files Browse the repository at this point in the history
Fix UploadDatasetFiles Component test
  • Loading branch information
ofahimIQSS authored Jan 15, 2025
2 parents 3e7508c + 6d60da4 commit f758ee6
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export function UploadedFiles({
<div>
<Form.Group.Checkbox
label={t('restricted')}
data-testid={'restricted_checkbox_' + file.fileName}
id={'restricted-' + file.key}
checked={file.restricted}
onChange={(event: FormEvent<HTMLInputElement>) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function FilesHeader({
label={''}
aria-label={t('filesHeader.selectAll')}
id={'select-all'}
data-testid="select-all-files-checkbox"
checked={selectAllChecked}
onChange={all}
/>
Expand All @@ -96,16 +97,26 @@ export function FilesHeader({
icon={<PencilFill className={styles.icon_pencil} />}
id={'edit-files'}
title={t('filesHeader.editFiles')}>
<DropdownButtonItem onClick={showAddTagsModal} title={t('filesHeader.addTagsToSelected')}>
<DropdownButtonItem
data-testid="add-tags-selected"
onClick={showAddTagsModal}
title={t('filesHeader.addTagsToSelected')}>
{t('filesHeader.addTags')}
</DropdownButtonItem>
<DropdownButtonItem onClick={() => updateRestriction(true)}>
<DropdownButtonItem
data-testid="restrict-selected"
onClick={() => updateRestriction(true)}>
{t('filesHeader.restrict')}
</DropdownButtonItem>
<DropdownButtonItem onClick={() => updateRestriction(false)}>
<DropdownButtonItem
data-testid="unrestrict-selected"
onClick={() => updateRestriction(false)}>
{t('filesHeader.unrestrict')}
</DropdownButtonItem>
<DropdownButtonItem onClick={deleteSelected} title={t('filesHeader.deleteSelected')}>
<DropdownButtonItem
data-testid="delete-selected"
onClick={deleteSelected}
title={t('filesHeader.deleteSelected')}>
{t('delete')}
</DropdownButtonItem>
</DropdownButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function RestrictionModal({
update({ saved: saved, terms: terms, requestAccess: requestAccess })

return (
<Modal show={show} onHide={() => handleClose(false)} size="lg">
<Modal data-testid="restrictionModal" show={show} onHide={() => handleClose(false)} size="lg">
<Modal.Header>
<Modal.Title>{t('restriction.restrictAccess')}</Modal.Title>
</Modal.Header>
Expand All @@ -47,6 +47,7 @@ export function RestrictionModal({
<Col sm={9}>
<Form.Group.Checkbox
label={t('restriction.enableAccessRequest')}
data-testid="enable-access-request-checkbox"
id={'requestAccessCB'}
checked={requestAccess}
onChange={(event: FormEvent<HTMLInputElement>) =>
Expand All @@ -61,6 +62,7 @@ export function RestrictionModal({
</Form.Group.Label>
<Col sm={9}>
<Form.Group.TextArea
data-testid="terms-of-access-textarea"
defaultValue={defaultTerms}
onChange={(event: FormEvent<HTMLInputElement>) =>
setTerms(event.currentTarget.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ describe('UploadDatasetFiles', () => {
cy.get('input[value="users1.json"]').should('not.exist')
cy.get('input[value="users2.json"]').should('exist')
})

it('restrict uploaded file', () => {
it(`restrict uploaded file`, () => {
const testDataset = DatasetMother.create()

mountWithDataset(<UploadDatasetFiles fileRepository={new FileMockRepository()} />, testDataset)
Expand All @@ -353,38 +352,60 @@ describe('UploadDatasetFiles', () => {
{ action: 'drag-drop' }
)
// wait for upload to finish
// Set users2.json to restricted
cy.findByText('2 files uploaded').should('exist')
cy.get('[type="checkbox"]').last().click()
cy.findByText('Save Changes').first().click()
cy.get('[type="checkbox"]').last().should('be.checked')
cy.get('[type="checkbox"]').last().click()
cy.get('[type="checkbox"]').last().should('not.be.checked')
cy.get('[type="checkbox"]').first().click()
cy.findByText('Edit files').first().click()
cy.findByText('Restrict').first().click()
cy.findByText('Save Changes').first().click()
cy.get('[type="checkbox"]').last().should('be.checked')
cy.findByText('Edit files').first().click()
cy.findByText('Unrestrict').first().click()
cy.get('[type="checkbox"]').last().should('not.be.checked')
cy.findByText('Edit files').first().click()
cy.findByText('Restrict').first().click()
cy.findByTestId('restricted_checkbox_users2.json').click()
cy.findByText('Save Changes').click()
cy.findByTestId('restrctionModal').should('not.exist')

// Set users2.json to unrestricted
cy.findByTestId('restricted_checkbox_users2.json').should('be.checked')
cy.findByTestId('restricted_checkbox_users2.json').click()
cy.findByTestId('restricted_checkbox_users2.json').should('not.be.checked')

// Set both files to restricted
cy.findByTestId('select-all-files-checkbox').click()
cy.findByRole('button', { name: 'Edit files' }).click()
cy.findByTestId('restrict-selected').click()
cy.findByText('Save Changes').click()
cy.findByTestId('restrctionModal').should('not.exist')
cy.findByTestId('restricted_checkbox_users1.json').should('be.checked')
cy.findByTestId('restricted_checkbox_users2.json').should('be.checked')

// Set both files to unrestricted
cy.findByRole('button', { name: 'Edit files' }).click()
cy.findByTestId('unrestrict-selected').click()
cy.findByTestId('restricted_checkbox_users1.json').should('not.be.checked')
cy.findByTestId('restricted_checkbox_users2.json').should('not.be.checked')

// Select Restrict, but don't save changes in the Modal.
// The changes should not be applied.
cy.findByRole('button', { name: 'Edit files' }).click()
cy.findByTestId('restrict-selected').click()
cy.findByLabelText('Close').click()
cy.get('[type="checkbox"]').last().should('not.be.checked')
cy.findByText('Edit files').first().click()
cy.findByText('Restrict').first().click()
cy.get('[type="checkbox"]').last().click()
cy.get('textarea').last().type('Hello, World!')
cy.findByText('Save Changes').first().click()
cy.get('[type="checkbox"]').last().should('be.checked')
cy.findByText('Edit files').first().click()
cy.findByText('Restrict').first().click()
cy.findByTestId('restricted_checkbox_users1.json').should('not.be.checked')
cy.findByTestId('restricted_checkbox_users2.json').should('not.be.checked')

// Select Restrict, and add a reason,then save changes in the Modal.
cy.findByRole('button', { name: 'Edit files' }).click()
cy.findByTestId('restrict-selected').click()
cy.findByTestId('enable-access-request-checkbox').click()
cy.findByTestId('terms-of-access-textarea').type('Hello, World!')
cy.findByText('Save Changes').click()
cy.findByTestId('restricted_checkbox_users1.json').should('be.checked')
cy.findByTestId('restricted_checkbox_users2.json').should('be.checked')

// Select Restrict, cancel changes in the Modal. The changes should not be applied.
cy.findByRole('button', { name: 'Edit files' }).click()
cy.findByTestId('restrict-selected').click()
cy.findByTitle('Cancel Changes').click()
cy.get('[type="checkbox"]').last().should('be.checked')
cy.get('[type="checkbox"]').first().click()
cy.get('[type="checkbox"]').first().click()
cy.findByText('Edit files').first().click()
cy.findByTitle('Delete selected').click()
cy.findByTestId('restricted_checkbox_users1.json').should('be.checked')
cy.findByTestId('restricted_checkbox_users2.json').should('be.checked')

cy.get('input[value="users1.json"]').should('exist')
cy.get('input[value="users2.json"]').should('exist')
cy.findByRole('button', { name: 'Edit files' }).click()
cy.findByTestId('delete-selected').click()
cy.get('input[value="users1.json"]').should('not.exist')
cy.get('input[value="users2.json"]').should('not.exist')
})
Expand Down

0 comments on commit f758ee6

Please sign in to comment.