import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
+import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import _ from 'lodash';
import { ComponentsModule } from '~/app/shared/components/components.module';
+import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
import { CdTableColumnFilter } from '~/app/shared/models/cd-table-column-filter';
import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
});
});
+ describe('test cell transformations', () => {
+ interface ExecutingTemplateConfig {
+ valueClass?: string;
+ executingClass?: string;
+ }
+
+ const testExecutingTemplate = (templateConfig?: ExecutingTemplateConfig) => {
+ const state = 'updating';
+ const value = component.data[0].a;
+
+ component.autoReload = -1;
+ component.columns[0].cellTransformation = CellTemplate.executing;
+ if (templateConfig) {
+ component.columns[0].customTemplateConfig = templateConfig;
+ }
+ component.data[0].cdExecuting = state;
+ fixture.detectChanges();
+
+ const elements = fixture.debugElement
+ .query(By.css('datatable-body-row datatable-body-cell'))
+ .queryAll(By.css('span'));
+ expect(elements.length).toBe(2);
+
+ // Value
+ const valueElement = elements[0];
+ if (templateConfig?.valueClass) {
+ templateConfig.valueClass.split(' ').forEach((clz) => {
+ expect(valueElement.classes).toHaveProperty(clz);
+ });
+ }
+ expect(valueElement.nativeElement.textContent.trim()).toBe(`${value}`);
+ // Executing state
+ const executingElement = elements[1];
+ if (templateConfig?.executingClass) {
+ templateConfig.executingClass.split(' ').forEach((clz) => {
+ expect(executingElement.classes).toHaveProperty(clz);
+ });
+ }
+ expect(executingElement.nativeElement.textContent.trim()).toBe(`(${state})`);
+ };
+
+ it.only('should display executing template', () => {
+ testExecutingTemplate();
+ });
+
+ it.only('should display executing template with custom classes', () => {
+ testExecutingTemplate({ valueClass: 'a b', executingClass: 'c d' });
+ });
+ });
+
describe('reload data', () => {
beforeEach(() => {
component.ngOnInit();
perSecond = 'perSecond',
checkIcon = 'checkIcon',
routerLink = 'routerLink',
+ // Display the cell with an executing state. The state can be set to the `cdExecuting`
+ // attribute of table rows.
+ // It supports an optional custom configuration:
+ // {
+ // ...
+ // cellTransformation: CellTemplate.executing,
+ // customTemplateConfig: {
+ // valueClass?: string; // Cell value classes.
+ // executingClass?: string; // Executing state classes.
+ // }
executing = 'executing',
classAdding = 'classAdding',
// Display the cell value as a badge. The template