Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4033 [bug] Dont reset downloadcounter when editting files #4074

Merged
merged 7 commits into from
Jan 16, 2025
44 changes: 44 additions & 0 deletions packages/cypress/src/integration/research/write.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ describe('[Research]', () => {
.type(updateVideoUrl)
.blur({ force: true })


cy.step('Add file to update')

// click the "Upload Files" button to show the uppy dashboard modal
cy.get('[data-cy=file-input-field]').click()

// set the file input value to our test fixture file, and click upload button
cy.get('.uppy-Dashboard-input:first').as('file-input')
cy.get('@file-input').selectFile('src/fixtures/files/Example.pdf', { force: true })
cy.get('.uppy-StatusBar-actionBtn--upload').as('upload-button')
cy.get('@upload-button').click()

cy.step('Published when fields are populated correctly')
cy.get('[data-cy=errors-container]').should('not.exist')
cy.get('[data-cy=submit]').click()
Expand All @@ -146,6 +158,38 @@ describe('[Research]', () => {

cy.contains(updateTitle).should('be.visible')
cy.contains(updateDescription).should('be.visible')
cy.get('[data-cy=file-download-counter]').should("have.text", "0 downloads")

// download the file then check the counter
cy.step('Download counter increments')
cy.get('[data-cy=downloadButton]').click()
cy.get('[data-cy=DonationRequestSkip]').invoke('removeAttr', 'target').click()
cy.go('back')
cy.reload()
cy.get('[data-cy=file-download-counter]').should("have.text", "1 download")

cy.step('Download count is preserved when replacing file')
cy.get('[data-cy=edit-update]').click()
cy.get('[data-cy=delete-file]').click()

// click the "Upload Files" button to show the uppy dashboard modal
cy.get('[data-cy=file-input-field]').click()

// set the file input value to our test fixture file, and click upload button
cy.get('.uppy-Dashboard-input:first').as('file-input')
cy.get('@file-input').selectFile('src/fixtures/files/Example.pdf', { force: true })
cy.get('.uppy-StatusBar-actionBtn--upload').as('upload-button')
cy.get('@upload-button').click()

cy.get('[data-cy=errors-container]').should('not.exist')
cy.get('[data-cy=submit]').click()

cy.step('Open the research update')
cy.get('[data-cy=view-research]:enabled', { timeout: 20000 })
.click()
.url()

cy.get('[data-cy=file-download-counter]').should("have.text", "1 download")
})

it('[By Anonymous]', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/cypress/src/support/commandsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ Cypress.Commands.add('setSettingImage', (image, selector) => {
.attachFile(`images/${image}.jpg`)
})

Cypress.Commands.add('setFile', (filePath, selector) => {
cy.get(`[data-cy=${selector}]`)
.find(':file')
.attachFile(filePath)
})

Cypress.Commands.add('setSettingImpactData', (year: number, fields) => {
cy.step('Save impact data')
cy.get('[data-cy="tab-Impact"]').click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const AlreadyAddedFiles = ({ formValues, setFileEditMode }) => {
type="button"
variant="outline"
icon="delete"
data-cy="delete-file"
onClick={deleteFile}
>
{buttons.files}
Expand Down Expand Up @@ -86,6 +87,7 @@ const UploadNewFiles = () => {
<Field
hasText={false}
name={'files'}
data-cy="file-input-field"
component={FileInputField}
/>
<Text color={'grey'} mt={4} sx={{ fontSize: 1 }}>
Expand All @@ -98,6 +100,7 @@ const UploadNewFiles = () => {
<Field
hasText={false}
name={'files'}
data-cy="file-input-field"
admin={true}
component={FileInputField}
/>
Expand Down
9 changes: 5 additions & 4 deletions src/stores/Research/research.store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ export class ResearchStore extends ModuleStore {
logger.debug('upload images ok')
this.updateUpdateUploadStatus('Images')

if ((update.files && update.files.length) || update.fileLink) {
updateWithMeta.downloadCount = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhhhh nice find!!!!!

}

if (update.files && update.files.length) {
const fileMeta = await this.uploadCollectionBatch(
update.files as File[],
Expand All @@ -256,6 +252,11 @@ export class ResearchStore extends ModuleStore {
logger.debug('upload files ok')
this.updateUpdateUploadStatus('Files')

// give downloadCount an initial value of 0 whether we're adding a file or not
if(updateWithMeta.downloadCount == undefined) {
updateWithMeta.downloadCount = 0;
}

// populate DB
const existingUpdateIndex = item.updates.findIndex(
(upd) => upd._id === (update as IResearch.UpdateDB)._id,
Expand Down
Loading