[AAE-2107] Move e2e to Unit test (#5535)

* [AAE-2107] Move e2e to Unit test

* * fixed namings

* * more unit test added

* * minor changes
This commit is contained in:
Eugenio Romano
2020-03-05 16:47:59 +00:00
committed by GitHub
parent 0217f0c788
commit a70883378a
19 changed files with 809 additions and 772 deletions

View File

@@ -16,6 +16,7 @@
*/
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { OverlayContainer } from '@angular/cdk/overlay';
import { By } from '@angular/platform-browser';
import { CardViewSelectItemModel } from '../../models/card-view-selectitem.model';
import { CardViewSelectItemComponent } from './card-view-selectitem.component';
@@ -27,6 +28,7 @@ describe('CardViewSelectItemComponent', () => {
let fixture: ComponentFixture<CardViewSelectItemComponent>;
let component: CardViewSelectItemComponent;
let overlayContainer: OverlayContainer;
const mockData = [{ key: 'one', label: 'One' }, { key: 'two', label: 'Two' }, { key: 'three', label: 'Three' }];
const mockDefaultProps = {
label: 'Select box label',
@@ -43,6 +45,7 @@ describe('CardViewSelectItemComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(CardViewSelectItemComponent);
component = fixture.componentInstance;
overlayContainer = TestBed.get(OverlayContainer);
component.property = new CardViewSelectItemModel(mockDefaultProps);
});
@@ -75,6 +78,50 @@ describe('CardViewSelectItemComponent', () => {
expect(selectBox).toBeNull();
});
it('should be possible edit selectBox item', () => {
component.property = new CardViewSelectItemModel({
...mockDefaultProps,
editable: true
});
component.editable = true;
component.displayNoneOption = true;
component.ngOnChanges();
fixture.detectChanges();
expect(component.value).toEqual('two');
expect(component.isEditable()).toBe(true);
const selectBox = fixture.debugElement.query(By.css('.mat-select-trigger'));
selectBox.triggerEventHandler('click', {});
fixture.detectChanges();
const optionsElement = Array.from(overlayContainer.getContainerElement().querySelectorAll('mat-option'));
expect(optionsElement.length).toEqual(4);
optionsElement[1].dispatchEvent(new Event('click'));
fixture.detectChanges();
expect(component.value).toEqual('one');
});
it('should be able to enable None option', () => {
component.property = new CardViewSelectItemModel({
...mockDefaultProps,
editable: true
});
component.editable = true;
component.displayNoneOption = true;
component.ngOnChanges();
fixture.detectChanges();
expect(component.isEditable()).toBe(true);
const selectBox = fixture.debugElement.query(By.css('.mat-select-trigger'));
selectBox.triggerEventHandler('click', {});
fixture.detectChanges();
const noneElement: HTMLElement = overlayContainer.getContainerElement().querySelector('mat-option');
expect(noneElement).toBeDefined();
expect(noneElement.innerText).toEqual('CORE.CARDVIEW.NONE');
});
it('should render select box if editable property is TRUE', () => {
component.ngOnChanges();
component.editable = true;