Skip to content
Open
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
18 changes: 0 additions & 18 deletions src/components/ChallengeEditor/MaximumSubmissions-Field/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@ class MaximumSubmissionsField extends Component {
</div>
</div>
{!readOnly && (<div className={styles.row}>
<div className={styles.subGroup}>
<div className={styles.subRow}>
<div className={styles.tcCheckbox}>
<input
name='unlimited'
id='unlimited'
type='checkbox'
checked={isUnlimited}
onChange={(e) => onUpdateMetadata('submissionLimit', e.target.checked, 'unlimited')}
/>
<label htmlFor='unlimited'>
<div className={styles.checkboxLabel}>
Unlimited
</div>
</label>
</div>
</div>
</div>
<div className={styles.subGroup}>
<div className={styles.subRow}>
<div className={styles.tcCheckbox}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* global describe, it, expect, beforeEach, afterEach, jest */

import React from 'react'
import ReactDOM from 'react-dom'
import { act, Simulate } from 'react-dom/test-utils'
import MaximumSubmissionsField from './index'

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

const renderComponent = (props = {}) => {
act(() => {
ReactDOM.render(
<MaximumSubmissionsField
challenge={{ metadata: [] }}
onUpdateMetadata={() => {}}
{...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 the unlimited option while editing', () => {
renderComponent({
challenge: {
metadata: [
{
name: 'submissionLimit',
value: '{"unlimited":"true","limit":"false","count":""}'
}
]
}
})

expect(container.querySelector('#unlimited')).toBeNull()
expect(container.querySelector('#limit')).not.toBeNull()
expect(container.textContent).not.toContain('Unlimited')
})

it('shows unlimited in read-only mode for legacy metadata', () => {
renderComponent({
readOnly: true,
challenge: {
metadata: [
{
name: 'submissionLimit',
value: '{"unlimited":"true","limit":"false","count":""}'
}
]
}
})

expect(container.textContent).toContain('Unlimited')
})

it('sanitizes the count input before updating metadata', () => {
const onUpdateMetadata = jest.fn()

renderComponent({ onUpdateMetadata })

const countInput = container.querySelector('#count')

act(() => {
Simulate.change(countInput, { target: { value: '12abc' } })
})

expect(onUpdateMetadata).toHaveBeenCalledWith('submissionLimit', '12', 'count')
})
})
3 changes: 0 additions & 3 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,6 @@ class ChallengeEditor extends Component {
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') {
Expand Down
Loading