import _ from 'underscore';
import { shiftClick } from 'new-dashboard/utils/shift-click.service';

describe('.shiftClick', () => {
  describe('when there is not selected items', () => {
    it('should select the item when the clicked', () => {
      const dummyItems = [{id: 0}, {id: 1}, {id: 2}, {id: 3}];
      const dummyItem = dummyItems[2];
      const selectedItems = [];

      let selectedInBetween = shiftClick(dummyItems, selectedItems, dummyItem);

      expect(_.sortBy(selectedInBetween, 'id')).toEqual([dummyItem]);
    });
  });
  describe('when there is a selected item', () => {
    it('should keep the item selected when clicked', () => {
      const dummyItems = [{id: 0}, {id: 1}, {id: 2}, {id: 3}];
      const dummyItem = dummyItems[2];
      const selectedItems = [dummyItem];

      let selectedInBetween = shiftClick(dummyItems, selectedItems, dummyItem);

      expect(_.sortBy(selectedInBetween, 'id')).toEqual([dummyItem]);
    });
    describe('and another item is selected after', () => {
      it('should select all the items in between', () => {
        const dummyItems = [{id: 0}, {id: 1}, {id: 2}, {id: 3}];
        const fromItem = dummyItems[0];
        const toItem = dummyItems[3];
        const selectedItems = [fromItem];

        let selectedInBetween = shiftClick(dummyItems, selectedItems, toItem);
        expect(_.sortBy(selectedInBetween, 'id')).toEqual(dummyItems);
      });
    });
    describe('and another item is selected before', () => {
      it('should select all the items in between', () => {
        const dummyItems = [{id: 0}, {id: 1}, {id: 2}, {id: 3}];
        const fromItem = dummyItems[3];
        const toItem = dummyItems[0];
        const selectedItems = [fromItem];

        let selectedInBetween = shiftClick(dummyItems, selectedItems, toItem);
        expect(_.sortBy(selectedInBetween, 'id')).toEqual(dummyItems);
      });
    });
  });

  describe('when there are multiple selected items', () => {
    describe('and another item is selected after', () => {
      it('should select all the items in between', () => {
        const dummyItems = [{id: 0}, {id: 1}, {id: 2}, {id: 3}];
        const selectedItems = [dummyItems[0], dummyItems[1]];
        let selectedInBetween = shiftClick(dummyItems, selectedItems, dummyItems[3]);

        expect(_.sortBy(selectedInBetween, 'id')).toEqual(dummyItems);
      });
    });
    describe('and another item is selected before', () => {
      it('should select all the items in between', () => {
        const dummyItems = [{id: 0}, {id: 1}, {id: 2}, {id: 3}];
        const selectedItems = [dummyItems[2], dummyItems[3]];
        let selectedInBetween = shiftClick(dummyItems, selectedItems, dummyItems[0]);

        expect(_.sortBy(selectedInBetween, 'id')).toEqual(dummyItems);
      });
    });
  });
});

@@ -151,14 +151,14 @@
 ere 
-is
+are
  no
-t
  sel
@@ -431,32 +431,43 @@
 , selectedItems,
+ dummyItem,
  dummyItem);%0A%0A  
@@ -864,32 +864,43 @@
 , selectedItems,
+ dummyItem,
  dummyItem);%0A%0A  
@@ -1347,32 +1347,42 @@
 tedItems, toItem
+, fromItem
 );%0A        expec
@@ -1834,24 +1834,34 @@
 tems, toItem
+, fromItem
 );%0A        e
@@ -2336,16 +2336,31 @@
 Items%5B3%5D
+, dummyItems%5B0%5D
 );%0A%0A    
@@ -2765,32 +2765,47 @@
 s, dummyItems%5B0%5D
+, dummyItems%5B3%5D
 );%0A%0A        expe
@@ -2877,22 +2877,1056 @@
 %7D);%0A    %7D);%0A
+    describe('when there are two elements selected consecutively without shift', () =%3E %7B%0A      describe('and you select the one below', () =%3E %7B%0A        it('should select two elements: the clicked one and the one above', () =%3E %7B%0A          const dummyItems = %5B%7Bid: 0%7D, %7Bid: 1%7D, %7Bid: 2%7D%5D;%0A          const selectedItems = %5BdummyItems%5B0%5D, dummyItems%5B1%5D%5D;%0A          let selectedInBetween = shiftClick(dummyItems, selectedItems, dummyItems%5B2%5D, dummyItems%5B1%5D);%0A%0A          expect(_.sortBy(selectedInBetween, 'id')).toEqual(%5B%7Bid: 1%7D, %7Bid: 2%7D%5D);%0A        %7D);%0A      %7D);%0A%0A      describe('and you select the one above', () =%3E %7B%0A        it('should select two elements: the clicked one and the one below', () =%3E %7B%0A          const dummyItems = %5B%7Bid: 0%7D, %7Bid: 1%7D, %7Bid: 2%7D%5D;%0A          const selectedItems = %5BdummyItems%5B1%5D, dummyItems%5B2%5D%5D;%0A          let selectedInBetween = shiftClick(dummyItems, selectedItems, dummyItems%5B0%5D, dummyItems%5B1%5D);%0A%0A          expect(_.sortBy(selectedInBetween, 'id')).toEqual(%5B%7Bid: 0%7D, %7Bid: 1%7D%5D);%0A        %7D);%0A      %7D);%0A    %7D);%0A
   %7D);%0A%7D);%0A

Fix and update tests