Skip to content
Closed
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

This file was deleted.

99 changes: 0 additions & 99 deletions src/components/ChallengeEditor/MaximumSubmissions-Field/index.js

This file was deleted.

6 changes: 0 additions & 6 deletions src/components/ChallengeEditor/TextEditor-Field/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import SkillsField from '../SkillsField'
import FinalDeliverablesField from '../FinalDeliverables-Field'
import StockArtsField from '../StockArts-Field'
import SubmssionVisibility from '../SubmissionVisibility-Field'
import MaximumSubmissionsField from '../MaximumSubmissions-Field'
import { CHALLENGE_TRACKS } from '../../../config/constants'
import styles from './TextEditor-Field.module.scss'
import PropTypes from 'prop-types'
Expand Down Expand Up @@ -123,11 +122,6 @@ class TextEditorField extends Component {
onUpdateCheckbox={onUpdateMetadata}
readOnly={readOnly}
/>
<MaximumSubmissionsField
challenge={challenge}
onUpdateMetadata={onUpdateMetadata}
readOnly={readOnly}
/>
</React.Fragment>
)}
</div>
Expand Down
75 changes: 75 additions & 0 deletions src/components/ChallengeEditor/TextEditor-Field/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* global describe, it, expect, beforeEach, afterEach, jest */

import React from 'react'
import ReactDOM from 'react-dom'
import { act } from 'react-dom/test-utils'
import TextEditorField from './index'
import { CHALLENGE_TRACKS } from '../../../config/constants'

jest.mock('../SpecialChallengeField', () => () => null)
jest.mock('../TagsField', () => () => null)
jest.mock('../SkillsField', () => () => null)
jest.mock('../FinalDeliverables-Field', () => () => null)
jest.mock('../StockArts-Field', () => () => null)
jest.mock('../SubmissionVisibility-Field', () => () => null)
jest.mock('../Description-Field', () => () => null)
jest.mock('../ChallengeReviewer-Field', () => () => null)
jest.mock('../../Buttons', () => ({
PrimaryButton: () => null
}))

describe('TextEditorField', () => {
let container

const renderComponent = (props = {}) => {
act(() => {
ReactDOM.render(
<TextEditorField
challenge={{ trackId: CHALLENGE_TRACKS.DESIGN, metadata: [] }}
shouldShowPrivateDescription={false}
{...props}
/>,
container
)
})
}

beforeEach(() => {
container = document.createElement('div')
document.body.appendChild(container)
})

afterEach(() => {
ReactDOM.unmountComponentAtNode(container)
container.remove()
container = null
jest.clearAllMocks()
})

it('does not render submission limit controls for design challenges while editing', () => {
renderComponent()

expect(container.textContent).not.toContain('Maximum Number of Submissions')
expect(container.textContent).not.toContain('Unlimited')
expect(container.querySelector('#limit')).toBeNull()
expect(container.querySelector('#count')).toBeNull()
})

it('does not render a submission limit summary for design challenges in read-only mode', () => {
renderComponent({
readOnly: true,
challenge: {
trackId: CHALLENGE_TRACKS.DESIGN,
metadata: [
{
name: 'submissionLimit',
value: '{"unlimited":"true","limit":"false","count":""}'
}
]
}
})

expect(container.textContent).not.toContain('Maximum Number of Submissions')
expect(container.textContent).not.toContain('Unlimited')
})
})
21 changes: 1 addition & 20 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,27 +622,8 @@ class ChallengeEditor extends Component {
if (!existingMetadata) {
existingMetadata = { name }
newChallenge.metadata.push(existingMetadata)
if (name === 'submissionLimit') {
existingMetadata.value = '{}'
}
}
if (existingMetadata.name === 'submissionLimit') {
const submissionLimit = JSON.parse(existingMetadata.value)
_.forOwn(submissionLimit, (value, key) => {
if (value === 'true') {
submissionLimit[key] = 'false'
}
})
submissionLimit[path] = `${value}`
if (path === 'count') {
submissionLimit.limit = 'true'
submissionLimit.unlimited = 'false'
} else if (path === 'unlimited' && value) {
submissionLimit.limit = 'false'
submissionLimit.count = ''
}
existingMetadata.value = JSON.stringify(submissionLimit)
} else if (existingMetadata.name === 'show_data_dashboard') {
if (existingMetadata.name === 'show_data_dashboard') {
existingMetadata.value = Boolean(value)
} else {
existingMetadata.value = `${value}`
Expand Down
Loading