Skip to content

Commit

Permalink
feat: allow deletion of all activities independent of status and dist…
Browse files Browse the repository at this point in the history
…inguish between hard and soft deletion in backend (#4294)
  • Loading branch information
sjschlapbach authored Oct 5, 2024
1 parent a99c2be commit 6d47105
Show file tree
Hide file tree
Showing 15 changed files with 452 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ function GroupActivityElement({
),
}

const deletionItem = {
label: (
<div className="flex cursor-pointer flex-row items-center gap-1 text-red-600">
<FontAwesomeIcon icon={faTrashCan} className="w-[1.1rem]" />
<div>{t('manage.course.deleteGroupActivity')}</div>
</div>
),
onClick: () => setDeletionModal(true),
data: {
cy: `delete-groupActivity-${groupActivity.name}`,
},
}

return (
<div
className="border-uzh-grey-80 flex w-full flex-row justify-between rounded border border-solid p-2"
Expand Down Expand Up @@ -221,21 +234,7 @@ function GroupActivityElement({
}),
data: { cy: `edit-groupActivity-${groupActivity.name}` },
},
{
label: (
<div className="flex cursor-pointer flex-row items-center gap-1 text-red-600">
<FontAwesomeIcon
icon={faTrashCan}
className="w-[1.1rem]"
/>
<div>{t('manage.course.deleteGroupActivity')}</div>
</div>
),
onClick: () => setDeletionModal(true),
data: {
cy: `delete-groupActivity-${groupActivity.name}`,
},
},
deletionItem,
]}
triggerIcon={faHandPointer}
/>
Expand Down Expand Up @@ -287,6 +286,16 @@ function GroupActivityElement({
</div>
</Button>
)}
<Dropdown
data={{ cy: `groupActivity-actions-${groupActivity.name}` }}
className={{
item: 'p-1 hover:bg-gray-200',
viewport: 'bg-white',
}}
trigger={t('manage.course.otherActions')}
items={[deletionItem]}
triggerIcon={faHandPointer}
/>
</>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ function MicroLearningElement({
),
}

const deletionElement = {
label: (
<div className="flex cursor-pointer flex-row items-center gap-1 text-red-600">
<FontAwesomeIcon icon={faTrashCan} className="w-4" />
<div>{t('manage.course.deleteMicrolearning')}</div>
</div>
),
onClick: () => setDeletionModal(true),
data: { cy: `delete-microlearning-${microLearning.name}` },
}

return (
<div
className="border-uzh-grey-80 flex w-full flex-row justify-between rounded border border-solid p-2"
Expand Down Expand Up @@ -218,16 +229,7 @@ function MicroLearningElement({
cy: `duplicate-microlearning-${microLearning.name}`,
},
}),
{
label: (
<div className="flex cursor-pointer flex-row items-center gap-1 text-red-600">
<FontAwesomeIcon icon={faTrashCan} className="w-4" />
<div>{t('manage.course.deleteMicrolearning')}</div>
</div>
),
onClick: () => setDeletionModal(true),
data: { cy: `delete-microlearning-${microLearning.name}` },
},
deletionElement,
].flat()}
triggerIcon={faHandPointer}
/>
Expand Down Expand Up @@ -286,6 +288,7 @@ function MicroLearningElement({
cy: `unpublish-microlearning-${microLearning.name}`,
},
},
deletionElement,
].flat()}
triggerIcon={faHandPointer}
/>
Expand Down Expand Up @@ -389,6 +392,7 @@ function MicroLearningElement({
},
]
: []),
deletionElement,
].flat()}
triggerIcon={faHandPointer}
/>
Expand Down
29 changes: 15 additions & 14 deletions apps/frontend-manage/src/components/courses/PracticeQuizElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Dropdown } from '@uzh-bf/design-system'
import dayjs from 'dayjs'
import { useTranslations } from 'next-intl'
import { useRouter } from 'next/router'
import { useState } from 'react'
import React, { useState } from 'react'
import { WizardMode } from '../sessions/creation/ElementCreation'
import CopyConfirmationToast from '../toasts/CopyConfirmationToast'
import StatusTag from './StatusTag'
Expand Down Expand Up @@ -164,6 +164,17 @@ function PracticeQuizElement({
),
}

const deletionItem = {
label: (
<div className="flex cursor-pointer flex-row items-center gap-1 text-red-600">
<FontAwesomeIcon icon={faTrashCan} className="w-[1.1rem]" />
<div>{t('manage.course.deletePracticeQuiz')}</div>
</div>
),
onClick: () => setDeletionModal(true),
data: { cy: `delete-practice-quiz-${practiceQuiz.name}` },
}

return (
<div
className="border-uzh-grey-80 flex w-full flex-row justify-between rounded border border-solid p-2"
Expand Down Expand Up @@ -259,19 +270,7 @@ function PracticeQuizElement({
cy: `duplicate-practice-quiz-${practiceQuiz.name}`,
},
}),
{
label: (
<div className="flex cursor-pointer flex-row items-center gap-1 text-red-600">
<FontAwesomeIcon
icon={faTrashCan}
className="w-[1.1rem]"
/>
<div>{t('manage.course.deletePracticeQuiz')}</div>
</div>
),
onClick: () => setDeletionModal(true),
data: { cy: `delete-practice-quiz-${practiceQuiz.name}` },
},
deletionItem,
].flat()}
triggerIcon={faHandPointer}
/>
Expand Down Expand Up @@ -319,6 +318,7 @@ function PracticeQuizElement({
cy: `unpublish-practiceQuiz-${practiceQuiz.name}`,
},
},
deletionItem,
].flat()}
triggerIcon={faHandPointer}
/>
Expand Down Expand Up @@ -371,6 +371,7 @@ function PracticeQuizElement({
cy: `duplicate-practice-quiz-${practiceQuiz.name}`,
},
}),
deletionItem,
].flat()}
triggerIcon={faHandPointer}
/>
Expand Down
104 changes: 103 additions & 1 deletion cypress/cypress/e2e/G-microlearning-workflow.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,34 @@ describe('Different microlearning workflows', () => {
)
cy.get('[data-cy="read-content-element-2"]').click()
cy.get('[data-cy="practice-quiz-stack-submit"]').click()

cy.viewport('macbook-16')

// navigate to the lecturer view and delete the microlearning
cy.clearAllCookies()
cy.loginLecturer()
cy.get('[data-cy="courses"]').click()
cy.findByText(courseName).click()
cy.get('[data-cy="tab-microLearnings"]').click()
cy.get(`[data-cy="microlearning-actions-${microLearningName}"]`).click()
cy.get(`[data-cy="delete-microlearning-${microLearningName}"]`).click()
cy.get(`[data-cy="confirm-delete-microlearning"]`).click()
cy.get(`[data-cy="microlearning-actions-${microLearningName}"]`).should(
'not.exist'
)

// make sure that the microlearning is no longer accessible to students
cy.clearAllCookies()
cy.visit(Cypress.env('URL_STUDENT'))
cy.get('[data-cy="username-field"]')
.click()
.type(Cypress.env('STUDENT_USERNAME'))
cy.get('[data-cy="password-field"]')
.click()
.type(Cypress.env('STUDENT_PASSWORD'))
cy.get('[data-cy="submit-login"]').click()
cy.contains('[data-cy="microlearnings"]', microLearningDisplayName).should(
'not.exist'
)
})

it('creates and publishes a future micro learning that should not be visible to students and tests unpublishing it', () => {
Expand Down Expand Up @@ -434,6 +460,14 @@ describe('Different microlearning workflows', () => {
cy.get(`[data-cy="microlearning-${microLearningName}"]`).contains(
messages.shared.generic.draft
)

// delete the microlearning
cy.get(`[data-cy="microlearning-actions-${microLearningName}"]`).click()
cy.get(`[data-cy="delete-microlearning-${microLearningName}"]`).click()
cy.get(`[data-cy="confirm-delete-microlearning"]`).click()
cy.get(`[data-cy="microlearning-actions-${microLearningName}"]`).should(
'not.exist'
)
})

it('creates and publishes a past micro learning that should not be visible to students', () => {
Expand Down Expand Up @@ -533,6 +567,19 @@ describe('Different microlearning workflows', () => {
cy.contains('[data-cy="microlearnings"]', microLearningDisplayName).should(
'not.exist'
)

// navigate to the lecturer view and delete the microlearning
cy.clearAllCookies()
cy.loginLecturer()
cy.get('[data-cy="courses"]').click()
cy.findByText(courseName).click()
cy.get('[data-cy="tab-microLearnings"]').click()
cy.get(`[data-cy="microlearning-actions-${microLearningName}"]`).click()
cy.get(`[data-cy="delete-microlearning-${microLearningName}"]`).click()
cy.get(`[data-cy="confirm-delete-microlearning"]`).click()
cy.get(`[data-cy="microlearning-actions-${microLearningName}"]`).should(
'not.exist'
)
})

it('creates and edits a micro learning, which should then be accessible by students', () => {
Expand Down Expand Up @@ -804,6 +851,33 @@ describe('Different microlearning workflows', () => {
cy.get('[data-cy="practice-quiz-continue"]').click()
cy.wait(500)
cy.get('[data-cy="finish-microlearning"]').click()

// navigate to the lecturer view and delete the microlearning
cy.clearAllCookies()
cy.loginLecturer()
cy.get('[data-cy="courses"]').click()
cy.findByText(courseName).click()
cy.get('[data-cy="tab-microLearnings"]').click()
cy.get(`[data-cy="microlearning-actions-${newMicroLearningName}"]`).click()
cy.get(`[data-cy="delete-microlearning-${newMicroLearningName}"]`).click()
cy.get(`[data-cy="confirm-delete-microlearning"]`).click()
cy.get(`[data-cy="microlearning-actions-${newMicroLearningName}"]`).should(
'not.exist'
)

// make sure that the microlearning is no longer accessible to students
cy.clearAllCookies()
cy.visit(Cypress.env('URL_STUDENT'))
cy.get('[data-cy="username-field"]')
.click()
.type(Cypress.env('STUDENT_USERNAME'))
cy.get('[data-cy="password-field"]')
.click()
.type(Cypress.env('STUDENT_PASSWORD'))
cy.get('[data-cy="submit-login"]').click()
cy.contains('[data-cy="microlearnings"]', microLearningDisplayName).should(
'not.exist'
)
})

it('respond to a microlearning with all element types', () => {
Expand Down Expand Up @@ -1350,6 +1424,34 @@ describe('Different microlearning workflows', () => {
cy.get('[data-cy="practice-quiz-continue"]').click()
cy.wait(500)
cy.get('[data-cy="finish-microlearning"]').click()

// navigate to the lecturer view and delete the microlearning
cy.clearAllCookies()
cy.loginLecturer()
cy.get('[data-cy="courses"]').click()
cy.findByText(courseName).click()
cy.get('[data-cy="tab-microLearnings"]').click()
cy.get(`[data-cy="microlearning-actions-${microLearningNameDupl}"]`).click()
cy.get(`[data-cy="delete-microlearning-${microLearningNameDupl}"]`).click()
cy.get(`[data-cy="confirm-delete-microlearning"]`).click()
cy.get(`[data-cy="microlearning-actions-${microLearningNameDupl}"]`).should(
'not.exist'
)

// make sure that the microlearning is no longer accessible to students
cy.clearAllCookies()
cy.visit(Cypress.env('URL_STUDENT'))
cy.get('[data-cy="username-field"]')
.click()
.type(Cypress.env('STUDENT_USERNAME'))
cy.get('[data-cy="password-field"]')
.click()
.type(Cypress.env('STUDENT_PASSWORD'))
cy.get('[data-cy="submit-login"]').click()
cy.contains(
'[data-cy="microlearnings"]',
microLearningDisplayNameDupl
).should('not.exist')
})

it('extends a seeded and running microlearning', () => {
Expand Down
Loading

0 comments on commit 6d47105

Please sign in to comment.