diff --git a/src/components/ChallengeEditor/MaximumSubmissions-Field/index.js b/src/components/ChallengeEditor/MaximumSubmissions-Field/index.js index 03d0fc88..d35f972e 100644 --- a/src/components/ChallengeEditor/MaximumSubmissions-Field/index.js +++ b/src/components/ChallengeEditor/MaximumSubmissions-Field/index.js @@ -34,24 +34,6 @@ class MaximumSubmissionsField extends Component { {!readOnly && (
-
-
-
- onUpdateMetadata('submissionLimit', e.target.checked, 'unlimited')} - /> - -
-
-
diff --git a/src/components/ChallengeEditor/MaximumSubmissions-Field/index.test.js b/src/components/ChallengeEditor/MaximumSubmissions-Field/index.test.js new file mode 100644 index 00000000..c484d044 --- /dev/null +++ b/src/components/ChallengeEditor/MaximumSubmissions-Field/index.test.js @@ -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( + {}} + {...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') + }) +}) diff --git a/src/components/ChallengeEditor/index.js b/src/components/ChallengeEditor/index.js index 3d21e062..73a97a4f 100644 --- a/src/components/ChallengeEditor/index.js +++ b/src/components/ChallengeEditor/index.js @@ -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') {