1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import React from 'react';
- import {shallow, mount} from 'enzyme';
- import {Client} from 'app/api';
- import PlatformPicker from 'app/components/platformPicker';
- describe('PlatformPicker', function() {
- beforeEach(function() {
- this.stubbedApiRequest = jest.spyOn(Client.prototype, 'request');
- });
- afterEach(function() {
- Client.prototype.request.mockRestore();
- });
- describe('render()', function() {
- const baseProps = {
- platform: '',
- setPlatform: () => {},
- location: {query: {}},
- };
- it('should only render Mobile platforms under Mobile tab', function() {
- const props = {
- ...baseProps,
- };
- const wrapper = shallow(<PlatformPicker {...props} />);
- wrapper.setState({category: 'mobile'});
- const filteredPlatforms = wrapper
- .find('PlatformCard')
- .map(node => node.prop('platform').id);
- expect(filteredPlatforms).not.toContain('java');
- expect(filteredPlatforms).toContain('swift');
- });
- it('should render renderPlatformList with Python when filtered with py', function() {
- const props = {
- ...baseProps,
- };
- const wrapper = shallow(<PlatformPicker {...props} />);
- wrapper.setState({category: 'all', filter: 'py'});
- const filteredPlatforms = wrapper
- .find('PlatformCard')
- .map(node => node.prop('platform').id);
- expect(filteredPlatforms).not.toContain('java');
- expect(filteredPlatforms).toContain('python-flask');
- });
- it('should render renderPlatformList with community SDKs message if platform not found', function() {
- const props = {
- ...baseProps,
- };
- const wrapper = shallow(<PlatformPicker {...props} />);
- wrapper.setState({filter: 'aaaaaa'});
- expect(wrapper.find('EmptyMessage')).toHaveLength(1);
- });
- it('should update State.tab onClick when particular tab is clicked', function() {
- const props = {
- ...baseProps,
- };
- const wrapper = mount(<PlatformPicker {...props} />, TestStubs.routerContext());
- const testListLink = wrapper
- .find('ListLink')
- .last()
- .find('a');
- expect(wrapper.state().category).toBe('popular');
- testListLink.simulate('click');
- expect(wrapper.state().category).toBe('all');
- });
- it('should clear the platform when clear is clicked', function() {
- const props = {
- ...baseProps,
- platform: 'java',
- setPlatform: jest.fn(),
- };
- const wrapper = mount(<PlatformPicker {...props} />, TestStubs.routerContext());
- wrapper.find('ClearButton').simulate('click');
- expect(props.setPlatform).toHaveBeenCalledWith('');
- });
- });
- });
|