2016-03-11 20:09:15 +03:00
|
|
|
import * as React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
2016-04-08 14:58:55 +03:00
|
|
|
import { click } from './Helpers';
|
2016-04-19 18:50:49 +03:00
|
|
|
import { List, ListItem } from '../src/stateless/main';
|
2016-03-11 20:09:15 +03:00
|
|
|
|
|
|
|
describe('List', () => {
|
|
|
|
let result;
|
2016-03-22 19:16:06 +03:00
|
|
|
const data = [ { text: "foo", value: 1 }, { text: "bar", value: 2 } ];
|
|
|
|
const primitives = [ "foo", "bar", "baz" ];
|
2016-03-11 20:09:15 +03:00
|
|
|
|
|
|
|
it('should render a ul', () => {
|
|
|
|
result = shallow(<List data={data} />);
|
2016-03-12 20:48:33 +03:00
|
|
|
expect(result.find('ul').length).toEqual(1);
|
2016-03-11 20:09:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render ListItems', () => {
|
|
|
|
result = shallow(<List data={data} />);
|
|
|
|
expect(result.find(ListItem).length).toEqual(2);
|
|
|
|
});
|
|
|
|
|
2016-03-22 19:16:06 +03:00
|
|
|
it('should render ListItems (array of strings)', () => {
|
|
|
|
result = shallow(<List data={primitives} />);
|
|
|
|
expect(result.find(ListItem).length).toEqual(3);
|
|
|
|
});
|
|
|
|
|
2016-03-11 20:09:15 +03:00
|
|
|
it('should select', () => {
|
2016-03-24 18:09:03 +03:00
|
|
|
result = shallow(<List data={data} selected={1} textField="text" valueField="value" />);
|
2016-03-11 20:09:15 +03:00
|
|
|
const items = result.find(ListItem);
|
|
|
|
expect(items.at(0).shallow().hasClass('k-state-selected')).toBe(false);
|
|
|
|
expect(items.at(1).shallow().hasClass('k-state-selected')).toBe(true);
|
|
|
|
});
|
|
|
|
|
2016-03-22 19:16:06 +03:00
|
|
|
it('should select (array of strings)', () => {
|
2016-03-24 18:09:03 +03:00
|
|
|
result = shallow(<List data={primitives} selected={1} />);
|
2016-03-22 19:16:06 +03:00
|
|
|
const items = result.find(ListItem);
|
|
|
|
expect(items.at(0).shallow().hasClass('k-state-selected')).toBe(false);
|
|
|
|
expect(items.at(1).shallow().hasClass('k-state-selected')).toBe(true);
|
|
|
|
});
|
|
|
|
|
2016-03-11 20:09:15 +03:00
|
|
|
it('should focus', () => {
|
|
|
|
result = shallow(<List data={data} focused={0} textField="text" valueField="value" />);
|
|
|
|
const items = result.find(ListItem);
|
|
|
|
expect(items.at(0).shallow().hasClass('k-state-focused')).toBe(true);
|
|
|
|
expect(items.at(1).shallow().hasClass('k-state-focused')).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fire onClick', () => {
|
|
|
|
const spy = jasmine.createSpy('spy');
|
|
|
|
result = shallow(<List data={data} onClick={spy} textField="text" valueField="value" />);
|
|
|
|
const items = result.find(ListItem);
|
|
|
|
|
2016-04-08 14:58:55 +03:00
|
|
|
click(items.at(0).shallow());
|
2016-03-24 19:29:27 +03:00
|
|
|
expect(spy).toHaveBeenCalledWith({ text: 'foo', value: 1 }, 0);
|
2016-03-11 20:09:15 +03:00
|
|
|
|
2016-04-08 14:58:55 +03:00
|
|
|
click(items.at(1).shallow());
|
2016-03-24 19:29:27 +03:00
|
|
|
expect(spy).toHaveBeenCalledWith({ text: 'bar', value: 2 }, 1);
|
2016-03-11 20:09:15 +03:00
|
|
|
});
|
2016-03-14 20:48:05 +03:00
|
|
|
|
2016-03-22 19:16:06 +03:00
|
|
|
it('should fire onClick (array of strings)', () => {
|
|
|
|
const spy = jasmine.createSpy('spy');
|
|
|
|
result = shallow(<List data={primitives} onClick={spy} />);
|
|
|
|
const items = result.find(ListItem);
|
|
|
|
|
2016-04-08 14:58:55 +03:00
|
|
|
click(items.at(0).shallow());
|
2016-03-24 19:29:27 +03:00
|
|
|
expect(spy).toHaveBeenCalledWith("foo", 0);
|
2016-03-22 19:16:06 +03:00
|
|
|
|
2016-04-08 14:58:55 +03:00
|
|
|
click(items.at(1).shallow());
|
2016-03-24 19:29:27 +03:00
|
|
|
expect(spy).toHaveBeenCalledWith("bar", 1);
|
2016-03-22 19:16:06 +03:00
|
|
|
});
|
2016-03-11 20:09:15 +03:00
|
|
|
});
|