Skip to content

Commit

Permalink
test(list): update display density tests #4393
Browse files Browse the repository at this point in the history
  • Loading branch information
tachojelev committed Apr 8, 2019
1 parent abce089 commit 06eb65c
Showing 1 changed file with 5 additions and 35 deletions.
40 changes: 5 additions & 35 deletions projects/igniteui-angular/src/lib/list/list.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ const LIST_CSS_CLASS = 'igx-list';
const LIST_COMPACT_DENSITY_CSS_CLASS = 'igx-list--compact';
const LIST_COSY_DENSITY_CSS_CLASS = 'igx-list--cosy';

const LIST_ITEM_BASE_CSS_CLASS = 'igx-list__item-base';
const LIST_ITEM_BASE_COMPACT_DENSITY_CSS_CLASS = 'igx-list__item-base--compact';
const LIST_ITEM_BASE_COSY_DENSITY_CSS_CLASS = 'igx-list__item-base--cosy';

const LIST_ITEM_HEADER_CSS_CLASS = 'igx-list__header';
const LIST_ITEM_HEADER_COMPACT_DENSITY_CSS_CLASS = 'igx-list__header--compact';
const LIST_ITEM_HEADER_COSY_DENSITY_CSS_CLASS = 'igx-list__header--cosy';

describe('List', () => {
configureTestSuite();
beforeEach(async(() => {
Expand Down Expand Up @@ -642,19 +634,19 @@ describe('List', () => {

const list = fixture.componentInstance.list as IgxListComponent;
const domList = fixture.debugElement.query(By.css('igx-list'));
verifyDisplayDensity(list, domList, 3, 2, DisplayDensity.comfortable);
verifyDisplayDensity(list, domList, DisplayDensity.comfortable);

list.displayDensity = DisplayDensity.compact;
fixture.detectChanges();
verifyDisplayDensity(list, domList, 3, 2, DisplayDensity.compact);
verifyDisplayDensity(list, domList, DisplayDensity.compact);

list.displayDensity = DisplayDensity.cosy;
fixture.detectChanges();
verifyDisplayDensity(list, domList, 3, 2, DisplayDensity.cosy);
verifyDisplayDensity(list, domList, DisplayDensity.cosy);

list.displayDensity = DisplayDensity.comfortable;
fixture.detectChanges();
verifyDisplayDensity(list, domList, 3, 2, DisplayDensity.comfortable);
verifyDisplayDensity(list, domList, DisplayDensity.comfortable);
});

it('should emit onDensityChanged with proper event arguments', () => {
Expand Down Expand Up @@ -775,46 +767,24 @@ describe('List', () => {
* Verifies the display density of the IgxList and its items by providing the IgxListComponent, the list DebugElement,
* the expected items and headers count and the expected DisplayDensity enumeration value.
*/
function verifyDisplayDensity(listComp, listDebugEl, expectedItemsCount, expectdHeadersCount, expectedDisplayDensity: DisplayDensity) {
function verifyDisplayDensity(listComp, listDebugEl, expectedDisplayDensity: DisplayDensity) {
let expectedListDensityClass;
let expectedListItemBaseClass;
let expectedListItemHeaderClass;

switch (expectedDisplayDensity) {
case DisplayDensity.compact: {
expectedListDensityClass = LIST_COMPACT_DENSITY_CSS_CLASS;
expectedListItemBaseClass = LIST_ITEM_BASE_COMPACT_DENSITY_CSS_CLASS;
expectedListItemHeaderClass = LIST_ITEM_HEADER_COMPACT_DENSITY_CSS_CLASS;
} break;
case DisplayDensity.cosy: {
expectedListDensityClass = LIST_COSY_DENSITY_CSS_CLASS;
expectedListItemBaseClass = LIST_ITEM_BASE_COSY_DENSITY_CSS_CLASS;
expectedListItemHeaderClass = LIST_ITEM_HEADER_COSY_DENSITY_CSS_CLASS;
} break;
default: {
expectedListDensityClass = LIST_CSS_CLASS;
expectedListItemBaseClass = LIST_ITEM_BASE_CSS_CLASS;
expectedListItemHeaderClass = LIST_ITEM_HEADER_CSS_CLASS;
} break;
}

// Verify list display density.
expect(listDebugEl.nativeElement.classList[0]).toBe(expectedListDensityClass);
expect(listComp.hostClass).toBe(expectedListDensityClass);
expect(listComp.displayDensity).toBe(expectedDisplayDensity);

// Verify list items display density.
const listDomItems = listDebugEl.queryAll(By.css('.' + expectedListItemBaseClass));
expect(listDomItems.length).toBe(expectedItemsCount, `Incorrect count of ${expectedListItemBaseClass} items.`);
for (const listItem of listComp.items) {
expect(listItem.hostClass).toBe(expectedListItemBaseClass);
}

// Verify list headers display density.
const listDomHeaders = listDebugEl.queryAll(By.css('.' + expectedListItemHeaderClass));
expect(listDomHeaders.length).toBe(expectdHeadersCount, `Incorrect count of ${expectedListItemHeaderClass} items.`);
for (const listItem of listComp.headers) {
expect(listItem.hostClass).toBe(expectedListItemHeaderClass);
}
}
});

0 comments on commit 06eb65c

Please sign in to comment.