-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45205 from code-dot-org/staging
DTT (Staging > Test) [robo-dtt]
- Loading branch information
Showing
206 changed files
with
10,626 additions
and
712 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, {useState} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Button from '@cdo/apps/templates/Button'; | ||
import StylizedBaseDialog from '@cdo/apps/componentLibrary/StylizedBaseDialog'; | ||
import UploadImageDialog from '@cdo/apps/lib/levelbuilder/lesson-editor/UploadImageDialog'; | ||
|
||
export default function ImageInput({updateImageUrl, imageUrl}) { | ||
const [removeImageDialogOpen, setRemoveImageDialogOpen] = useState(false); | ||
const [uploadImageDialogOpen, setUploadImageDialogOpen] = useState(false); | ||
return ( | ||
<div> | ||
<label> | ||
Image | ||
<Button | ||
onClick={() => setUploadImageDialogOpen(true)} | ||
text={!!imageUrl ? 'Replace Image' : 'Choose Image'} | ||
color="gray" | ||
icon="plus-circle" | ||
/> | ||
{imageUrl && <span>{imageUrl}</span>} | ||
{imageUrl && ( | ||
<Button | ||
text="Remove Image" | ||
color="red" | ||
icon="trash" | ||
onClick={() => setRemoveImageDialogOpen(true)} | ||
/> | ||
)} | ||
</label> | ||
{removeImageDialogOpen && ( | ||
<StylizedBaseDialog | ||
body="Are you sure you want to remove this image?" | ||
handleConfirmation={() => { | ||
updateImageUrl(null); | ||
setRemoveImageDialogOpen(false); | ||
}} | ||
handleClose={() => setRemoveImageDialogOpen(false)} | ||
isOpen | ||
/> | ||
)} | ||
<UploadImageDialog | ||
isOpen={uploadImageDialogOpen} | ||
handleClose={() => setUploadImageDialogOpen(false)} | ||
uploadImage={imgUrl => updateImageUrl(imgUrl)} | ||
allowExpandable={false} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
ImageInput.propTypes = { | ||
updateImageUrl: PropTypes.func.isRequired, | ||
imageUrl: PropTypes.string | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
apps/test/unit/lib/levelbuilder/code-docs-editor/ImageInputText.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import {shallow} from 'enzyme'; | ||
import {expect} from '../../../../util/reconfiguredChai'; | ||
import ImageInput from '@cdo/apps/lib/levelbuilder/code-docs-editor/ImageInput'; | ||
|
||
describe('ImageInput', () => { | ||
it('displays image upload dialog when upload image button is pressed', () => { | ||
const wrapper = shallow(<ImageInput updateImageUrl={() => {}} />); | ||
const uploadButton = wrapper.find('Button').first(); | ||
expect(uploadButton).to.not.be.null; | ||
uploadButton.simulate('click'); | ||
expect(wrapper.find('UploadImageDialog').length).to.equal(1); | ||
}); | ||
|
||
it('shows imageUrl if one is provided', () => { | ||
const wrapper = shallow( | ||
<ImageInput | ||
updateImageUrl={() => {}} | ||
imageUrl="code.org/images/spritelab.png" | ||
/> | ||
); | ||
expect(wrapper.text().includes('code.org/images/spritelab.png')).to.be.true; | ||
}); | ||
|
||
it('shows confirmation dialog if remove image button is pressed', () => { | ||
const wrapper = shallow( | ||
<ImageInput | ||
updateImageUrl={() => {}} | ||
imageUrl="code.org/images/spritelab.png" | ||
/> | ||
); | ||
expect(wrapper.find('Button').length).to.equal(2); | ||
const removeButton = wrapper.find('Button').last(); | ||
removeButton.simulate('click'); | ||
expect(wrapper.find('StylizedBaseDialog').length).to.equal(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.