Skip to content
Snippets Groups Projects
datatable.component.spec.ts 7.82 KiB
Newer Older
  • Learn to ignore specific revisions
  • // import { ComponentFixture, TestBed } from '@angular/core/testing';
    // import { Component, Input } from '@angular/core';
    // import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    //
    // import { AccordionModule } from 'ngx-bootstrap/accordion';
    // import { DatatableSectionComponent } from './datatable.component';
    // import { Dataset } from '../../../metamodel/model';
    // import { ATTRIBUTE_LIST, DATASET_LIST } from '../../../../settings/test-data';
    //
    // describe('[Search][Result] Component: DatatableComponent', () => {
    //     @Component({ selector: 'app-img', template: '' })
    //     class ImgStubComponent {
    //         @Input() src: string;
    //     }
    //
    //     @Component({ selector: 'app-thumbnail', template: '' })
    //     class ThumbnailStubComponent {
    //         @Input() src: string;
    //         @Input() attributeName: string;
    //     }
    //
    //     @Component({ selector: 'app-link', template: '' })
    //     class LinkStubComponent {
    //         @Input() href: string;
    //     }
    //
    //     @Component({ selector: 'app-btn', template: '' })
    //     class BtnStubComponent {
    //         @Input() href: string;
    //     }
    //
    //     @Component({ selector: 'app-detail', template: '' })
    //     class DetailStubComponent {
    //         @Input() style: string;
    //         @Input() datasetName: string;
    //         @Input() data: string | number;
    //     }
    //
    //     @Component({ selector: 'app-download', template: '' })
    //     class DownloadStubComponent {
    //         @Input() href: string;
    //     }
    //
    //     @Component({ selector: 'app-json-renderer', template: '' })
    //     class JsonStubComponent {
    //         @Input() attributeName: string;
    //         @Input() json: string;
    //     }
    //
    //     @Component({ selector: 'pagination', template: '' })
    //     class PaginationStubComponent {
    //         @Input() totalItems: number;
    //         @Input() boundaryLinks: boolean;
    //         @Input() rotate: boolean;
    //         @Input() maxSize: number;
    //     }
    //
    //     let component: DatatableSectionComponent;
    //     let fixture: ComponentFixture<DatatableSectionComponent>;
    //
    //     beforeEach(() => {
    //         TestBed.configureTestingModule({
    //             declarations: [
    //                 DatatableSectionComponent,
    //                 ImgStubComponent,
    //                 ThumbnailStubComponent,
    //                 LinkStubComponent,
    //                 BtnStubComponent,
    //                 DetailStubComponent,
    //                 DownloadStubComponent,
    //                 JsonStubComponent,
    //                 PaginationStubComponent
    //             ],
    //             imports: [AccordionModule.forRoot(), BrowserAnimationsModule]
    //         });
    //         fixture = TestBed.createComponent(DatatableSectionComponent);
    //         component = fixture.componentInstance;
    //     });
    //
    //     it('should create the component', () => {
    //         expect(component).toBeTruthy();
    //     });
    //
    //     it('#isDatatableOpened() should return if datatable has to be opened or not', () => {
    //         component.datasetList = DATASET_LIST;
    //         component.datasetName = 'cat_1';
    //         expect(component.isDatatableOpened()).toBeTruthy();
    //         component.datasetName = 'cat_2';
    //         expect(component.isDatatableOpened()).toBeFalsy();
    //     });
    //
    //     it('#getOutputList() should return filtered output list', () => {
    //         component.outputList = [2]
    //         component.datasetAttributeList = ATTRIBUTE_LIST;
    //         expect(component.getOutputList().length).toBe(1);
    //     });
    //
    //     it('#getDataset() should return dataset object', () => {
    //         component.datasetList = DATASET_LIST;
    //         component.datasetName = 'cat_1';
    //         const dataset: Dataset = component.getDataset();
    //         expect(dataset.name).toBe('cat_1');
    //         expect(dataset.label).toBe('Cat 1');
    //     });
    //
    //     it('#getAttributeId(attributeName) should return id of attributeName', () => {
    //         component.datasetAttributeList = ATTRIBUTE_LIST;
    //         expect(component.getAttributeId('name_one')).toBe(1);
    //     });
    //
    //     it('#toggleSelection(datum) should return add datum to selectedData', () => {
    //         const datum = { label_one: 123456 };
    //         component.datasetAttributeList = ATTRIBUTE_LIST;
    //         component.selectedData = [];
    //         component.addSelectedData.subscribe((event: any) => expect(event).toBe(123456));
    //         component.toggleSelection(datum);
    //     });
    //
    //     it('#toggleSelection(datum) should return remove datum to selectedData', () => {
    //         const datum = { label_one: 123456 };
    //         component.selectedData = [123456];
    //         component.datasetAttributeList = ATTRIBUTE_LIST;
    //         component.deleteSelectedData.subscribe((event: any) => expect(event).toBe(123456));
    //         component.toggleSelection(datum);
    //     });
    //
    //     it('#isSelected(datum) should return true datum is selected', () => {
    //         const datum = { label_one: 123456 };
    //         component.datasetAttributeList = ATTRIBUTE_LIST;
    //         component.selectedData = [123456];
    //         expect(component.isSelected(datum)).toBeTruthy();
    //     });
    //
    //     it('#isSelected(datum) should return false datum is not selected', () => {
    //         const datum = { label_one: 123456 };
    //         component.datasetAttributeList = ATTRIBUTE_LIST;
    //         component.selectedData = [];
    //         expect(component.isSelected(datum)).toBeFalsy();
    //     });
    //
    //     it('#noSelectedData() should return true if no selectedData', () => {
    //         component.selectedData = [];
    //         expect(component.noSelectedData()).toBeTruthy();
    //     });
    //
    //     it('#noSelectedData() should return false if there are selectedData', () => {
    //         component.selectedData = [123456];
    //         expect(component.noSelectedData()).toBeFalsy();
    //     });
    //
    //     it('#emitProcess() should raise executeProcess event and transmit process type', () => {
    //         component.executeProcess.subscribe((event: string) => expect(event).toBe('test'));
    //         component.emitProcess('test');
    //     });
    //
    //     it('#changePage() should change page value and raise getSearchData event', () => {
    //         component.sortedCol = 1;
    //         component.sortedOrder = 'a';
    //         component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([2, 10, 1, 'a']));
    //         component.changePage(2);
    //     });
    //
    //     it('#changeNbItems() should change nbItems value and raise getSearchData event', () => {
    //         component.sortedCol = 1;
    //         component.sortedOrder = 'a';
    //         component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([1, 20, 1, 'a']));
    //         component.changeNbItems(20);
    //     });
    //
    //     it('#ngOnInit() should init sortedCol and sortedOrder values', () => {
    //         component.datasetAttributeList = ATTRIBUTE_LIST;
    //         component.ngOnInit();
    //         expect(component.sortedCol).toEqual(1);
    //         expect(component.sortedOrder).toBe('a');
    //     });
    //
    //     it('#sort() should raise getSearchData event with correct parameters', () => {
    //         component.sortedOrder = 'a';
    //         let subscribtion = component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([1, 10, 1, 'a']));
    //         component.sort(1);
    //         subscribtion.unsubscribe();
    //         component.sortedCol = 1;
    //         component.sortedOrder = 'a';
    //         subscribtion = component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([1, 10, 1, 'd']));
    //         component.sort(1);
    //         subscribtion.unsubscribe();
    //         component.sortedCol = 1;
    //         component.sortedOrder = 'd';
    //         subscribtion = component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([1, 10, 1, 'a']));
    //         component.sort(1);
    //     });
    // });
    //