Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1351,16 +1351,15 @@ describe('ChallengeEditorForm', () => {
const timelineIndex = sectionHeadings.indexOf('Timeline & Schedule')
const submissionSettingsIndex = sectionHeadings.indexOf('Submission Settings')
const reviewIndex = sectionHeadings.indexOf('Review')
const attachmentsIndex = sectionHeadings.indexOf('Attachments')

expect(timelineIndex)
.toBeGreaterThanOrEqual(0)
expect(submissionSettingsIndex)
.toBeGreaterThan(timelineIndex)
expect(reviewIndex)
.toBeGreaterThan(submissionSettingsIndex)
expect(attachmentsIndex)
.toBeGreaterThan(reviewIndex)
expect(sectionHeadings)
.not.toContain('Attachments')
expect(screen.getByTestId('reviewers-field'))
.toHaveAttribute('data-read-only', 'true')
expect(screen.getByTestId('reviewers-field')
Expand Down Expand Up @@ -1747,36 +1746,17 @@ describe('ChallengeEditorForm', () => {
.not.toHaveBeenCalledWith('Failed to save challenge')
})

it('preserves uploaded attachments after saving when the update response omits them', async () => {
const user = userEvent.setup()

mockedPatchChallenge.mockResolvedValue({
...validDraftChallenge,
attachments: undefined,
})

it('does not render the attachments section while editing a draft', () => {
render(
<MemoryRouter>
<ChallengeEditorForm challenge={validDraftChallenge} />
</MemoryRouter>,
)

expect(screen.getByText('Attachment Count: 0'))
.toBeInTheDocument()

await user.click(screen.getByRole('button', { name: 'Mock Add Attachment' }))

expect(screen.getByText('Attachment Count: 1'))
.toBeInTheDocument()

await user.click(screen.getByRole('button', { name: 'Save Challenge' }))

await waitFor(() => {
expect(mockedPatchChallenge)
.toHaveBeenCalledTimes(1)
expect(screen.getByText('Attachment Count: 1'))
.toBeInTheDocument()
})
expect(screen.queryByRole('heading', { level: 3, name: 'Attachments' }))
.not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Mock Add Attachment' }))
.not.toBeInTheDocument()
})

it('returns to view mode after saving from an edit route', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ import {
import {
AssignedMemberField,
} from './AssignedMemberField'
import {
AttachmentsField,
} from './AttachmentsField'
import {
ChallengeDescriptionField,
} from './ChallengeDescriptionField'
Expand Down Expand Up @@ -2477,14 +2474,6 @@ export const ChallengeEditorForm: FC<ChallengeEditorFormProps> = (
</section>
)
: undefined
const attachmentsSection = (
<section className={styles.section}>
<h3 className={styles.sectionTitle}>Attachments</h3>
<div className={styles.block}>
<AttachmentsField />
</div>
</section>
)
const footerSection = !isReadOnly
? (
<div className={styles.footer}>
Expand Down Expand Up @@ -2748,23 +2737,12 @@ export const ChallengeEditorForm: FC<ChallengeEditorFormProps> = (
{!isReadOnly
? reviewSection
: undefined}
{!isReadOnly
? attachmentsSection
: undefined}
{footerSection}
</fieldset>

{isReadOnly
? reviewSection
: undefined}

{isReadOnly
? (
<fieldset className={styles.formContent} disabled>
{attachmentsSection}
</fieldset>
)
: undefined}
</>
)
: undefined}
Expand Down
Loading