Skip to content

Commit

Permalink
fixed #6578
Browse files Browse the repository at this point in the history
orderlist unit test improved.
+ctrl + click control.
+touchend control.
  • Loading branch information
yigitfindikli committed Sep 27, 2018
1 parent 327df65 commit b1820e7
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion src/app/components/orderlist/orderlist.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TestOrderListComponent {
}
}

describe('OrderList', () => {
fdescribe('OrderList', () => {

let orderlist: OrderList;
let fixture: ComponentFixture<TestOrderListComponent>;
Expand Down Expand Up @@ -120,10 +120,52 @@ describe('OrderList', () => {
const itemListEl = fixture.debugElement.query(By.css('ul'));

expect(itemListEl).toBeTruthy();
expect(orderlist.itemTouched).toEqual(undefined);
expect(itemListEl.children.length).toEqual(10);
});

it('should call onItem click and select a item', () => {
const onItemClickSpy = spyOn(orderlist, 'onItemClick').and.callThrough();
const onItemTouchEndSpy = spyOn(orderlist, 'onItemTouchEnd').and.callThrough();
fixture.detectChanges();

const itemListEl = fixture.debugElement.query(By.css('ul'));
const bmwEl = itemListEl.queryAll(By.css('.ui-orderlist-item'))[3];
bmwEl.nativeElement.dispatchEvent(new Event('touchend'));
fixture.detectChanges();
expect(orderlist.itemTouched).toEqual(true);

bmwEl.nativeElement.click();
fixture.detectChanges();

expect(onItemClickSpy).toHaveBeenCalled();
expect(onItemTouchEndSpy).toHaveBeenCalled();
expect(orderlist.itemTouched).toEqual(false);
expect(orderlist.selectedItems.length).toEqual(1);
expect(orderlist.selectedItems[0].brand).toEqual("BMW");
expect(bmwEl.nativeElement.className).toContain('ui-state-highlight');
});

it('should call onItem click and unselect a item', () => {
const onItemClickSpy = spyOn(orderlist, 'onItemClick').and.callThrough();
fixture.detectChanges();

const itemListEl = fixture.debugElement.query(By.css('ul'));
const bmwEl = itemListEl.queryAll(By.css('.ui-orderlist-item'))[3];
bmwEl.nativeElement.click();
fixture.detectChanges();

const ctrlClickEvent = {'ctrlKey':true};
orderlist.onItemClick(ctrlClickEvent,orderlist.selectedItems[0],3);
fixture.detectChanges();

expect(onItemClickSpy).toHaveBeenCalledTimes(2);
expect(orderlist.selectedItems.length).toEqual(0);
expect(bmwEl.nativeElement.className).not.toContain('ui-state-highlight');
});

it('should call onItem click and select a item with metaKeySelection false', () => {
orderlist.metaKeySelection = false;
const onItemClickSpy = spyOn(orderlist, 'onItemClick').and.callThrough();
fixture.detectChanges();

Expand All @@ -138,6 +180,25 @@ describe('OrderList', () => {
expect(bmwEl.nativeElement.className).toContain('ui-state-highlight');
});

it('should call onItem click and unselect a item with metaKeySelection', () => {
orderlist.metaKeySelection = false;
const onItemClickSpy = spyOn(orderlist, 'onItemClick').and.callThrough();
fixture.detectChanges();

const itemListEl = fixture.debugElement.query(By.css('ul'));
const bmwEl = itemListEl.queryAll(By.css('.ui-orderlist-item'))[3];
bmwEl.nativeElement.click();
fixture.detectChanges();

const ctrlClickEvent = {'ctrlKey':true};
orderlist.onItemClick(ctrlClickEvent,orderlist.selectedItems[0],3);
fixture.detectChanges();

expect(onItemClickSpy).toHaveBeenCalledTimes(2);
expect(orderlist.selectedItems.length).toEqual(0);
expect(bmwEl.nativeElement.className).not.toContain('ui-state-highlight');
});

it('should call moveUp', () => {
const moveUpSpy = spyOn(orderlist, 'moveUp').and.callThrough();
fixture.detectChanges();
Expand Down

0 comments on commit b1820e7

Please sign in to comment.