|
| 1 | +import { NO_ERRORS_SCHEMA } from '@angular/core'; |
| 2 | +import { |
| 3 | + ComponentFixture, |
| 4 | + TestBed, |
| 5 | + waitForAsync, |
| 6 | +} from '@angular/core/testing'; |
| 7 | +import { By } from '@angular/platform-browser'; |
| 8 | +import { RouterTestingModule } from '@angular/router/testing'; |
| 9 | +import { Audit } from '@dspace/core/audit/model/audit.model'; |
| 10 | +import { DSONameService } from '@dspace/core/breadcrumbs/dso-name.service'; |
| 11 | +import { DSpaceObjectDataService } from '@dspace/core/data/dspace-object-data.service'; |
| 12 | +import { PaginatedList } from '@dspace/core/data/paginated-list.model'; |
| 13 | +import { DSpaceObject } from '@dspace/core/shared/dspace-object.model'; |
| 14 | +import { AuditMock } from '@dspace/core/testing/audit.mock'; |
| 15 | +import { DSONameServiceMock } from '@dspace/core/testing/dso-name.service.mock'; |
| 16 | +import { createSuccessfulRemoteDataObject$ } from '@dspace/core/utilities/remote-data.utils'; |
| 17 | +import { TranslateModule } from '@ngx-translate/core'; |
| 18 | +import { PaginationComponent } from 'src/app/shared/pagination/pagination.component'; |
| 19 | + |
| 20 | +import { AuditTableComponent } from './audit-table.component'; |
| 21 | + |
| 22 | +describe('AuditTableComponent', () => { |
| 23 | + let component: AuditTableComponent; |
| 24 | + let fixture: ComponentFixture<AuditTableComponent>; |
| 25 | + |
| 26 | + let audits = new PaginatedList() as PaginatedList<Audit>; |
| 27 | + const dSpaceObjectDataService = jasmine.createSpyObj('DSpaceObjectDataService', { findById: createSuccessfulRemoteDataObject$(new DSpaceObject()) }); |
| 28 | + |
| 29 | + |
| 30 | + beforeEach(waitForAsync(() => { |
| 31 | + audits.page = [ AuditMock ]; |
| 32 | + TestBed.configureTestingModule({ |
| 33 | + imports: [ |
| 34 | + TranslateModule.forRoot(), |
| 35 | + RouterTestingModule.withRoutes([]), |
| 36 | + AuditTableComponent, |
| 37 | + PaginationComponent, |
| 38 | + ], |
| 39 | + providers: [ |
| 40 | + { provide: DSONameService, useValue: new DSONameServiceMock() }, |
| 41 | + { provide: DSpaceObjectDataService, useValue: dSpaceObjectDataService }, |
| 42 | + ], |
| 43 | + schemas: [NO_ERRORS_SCHEMA], |
| 44 | + }) |
| 45 | + .overrideComponent(AuditTableComponent, { |
| 46 | + remove: { imports: [PaginationComponent] }, |
| 47 | + }) |
| 48 | + .compileComponents(); |
| 49 | + })); |
| 50 | + |
| 51 | + beforeEach(() => { |
| 52 | + fixture = TestBed.createComponent(AuditTableComponent); |
| 53 | + component = fixture.componentInstance; |
| 54 | + component.audits = audits; |
| 55 | + component.isOverviewPage = true; |
| 56 | + fixture.detectChanges(); |
| 57 | + }); |
| 58 | + |
| 59 | + describe('table structure', () => { |
| 60 | + |
| 61 | + it('should display the entityType in the first column', () => { |
| 62 | + const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); |
| 63 | + const el = rowElements[0].query(By.css('td:nth-child(1)')).nativeElement; |
| 64 | + expect(el.textContent).toContain(audits.page[0].eventType); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should display the eperson in the second column', () => { |
| 68 | + const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); |
| 69 | + const el = rowElements[0].query(By.css('td:nth-child(2)')).nativeElement; |
| 70 | + expect(el.textContent).toContain(audits.page[0].epersonName); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should display the timestamp in the third column', () => { |
| 74 | + const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); |
| 75 | + const el = rowElements[0].query(By.css('td:nth-child(3)')).nativeElement; |
| 76 | + expect(el.textContent).toContain('2020-11-13 10:41:06'); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should display the objectUUID in the fourth column', () => { |
| 80 | + const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); |
| 81 | + const el = rowElements[0].query(By.css('td:nth-child(4)')).nativeElement; |
| 82 | + expect(el.textContent).toContain(audits.page[0].objectUUID); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should display the objectType in the fifth column', () => { |
| 86 | + const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); |
| 87 | + const el = rowElements[0].query(By.css('td:nth-child(5)')).nativeElement; |
| 88 | + expect(el.textContent).toContain(audits.page[0].objectType); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should display the subjectUUID in the sixth column', () => { |
| 92 | + const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); |
| 93 | + const el = rowElements[0].query(By.css('td:nth-child(6)')).nativeElement; |
| 94 | + expect(el.textContent).toContain(audits.page[0].subjectUUID); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should display the subjectType in the seventh column', () => { |
| 98 | + const rowElements = fixture.debugElement.queryAll(By.css('tbody tr')); |
| 99 | + const el = rowElements[0].query(By.css('td:nth-child(7)')).nativeElement; |
| 100 | + expect(el.textContent).toContain(audits.page[0].subjectType); |
| 101 | + }); |
| 102 | + }); |
| 103 | +}); |
0 commit comments