Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baseline tests for image picker component #34622

Merged
merged 3 commits into from May 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/src/code-studio/components/ImagePicker.jsx
Expand Up @@ -84,7 +84,7 @@ export default class ImagePicker extends React.Component {
!this.props.typeFilter || this.props.typeFilter === 'image';
if (this.props.assetChosen && imageTypeFilter) {
modeSwitch = (
<div>
<div id="modeSwitch">
<p onClick={this.setFileMode} style={styles.fileModeToggle}>
My Files
</p>
Expand Down
41 changes: 41 additions & 0 deletions apps/test/unit/code-studio/components/ImagePickerTest.js
@@ -0,0 +1,41 @@
import {assert} from '../../../util/reconfiguredChai';
import React from 'react';
import {shallow} from 'enzyme';
import ImagePicker from '@cdo/apps/code-studio/components/ImagePicker';
import IconLibrary from '@cdo/apps/code-studio/components/IconLibrary';
import AssetManager from '@cdo/apps/code-studio/components/AssetManager';

describe('ImagePicker', () => {
const defaultProps = {
assetChosen: () => true,
typeFilter: 'image',
uploadsEnabled: false,
showUnderageWarning: false,
useFilesApi: false
};

it('shows mode switch', () => {
const wrapper = shallow(<ImagePicker {...defaultProps} />);
assert.equal(wrapper.find('#modeSwitch').length, 1);
});

it('shows icons and files as options', () => {
const wrapper = shallow(<ImagePicker {...defaultProps} />);
const tabs = wrapper.find('#modeSwitch').find('p');

assert.equal(tabs.length, 2);
assert.equal(tabs.find('p[children="Icons"]').length, 1);
assert.equal(tabs.find('p[children="My Files"]').length, 1);
});

it('initially shows file picker by default', () => {
const wrapper = shallow(<ImagePicker {...defaultProps} />);
assert.equal(wrapper.find(AssetManager).length, 1);
});

it('shows icon picker when clicked', () => {
const wrapper = shallow(<ImagePicker {...defaultProps} />);
wrapper.find('p[children="Icons"]').simulate('click');
assert.equal(wrapper.find(IconLibrary).length, 1);
});
});