1 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { RgwSyncMetadataInfoComponent } from './rgw-sync-metadata-info.component';
4 import { NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap';
5 import { configureTestBed } from '~/testing/unit-test-helper';
6 import { By } from '@angular/platform-browser';
7 import { RelativeDatePipe } from '~/app/shared/pipes/relative-date.pipe';
9 describe('RgwSyncMetadataInfoComponent', () => {
10 let component: RgwSyncMetadataInfoComponent;
11 let fixture: ComponentFixture<RgwSyncMetadataInfoComponent>;
14 declarations: [RgwSyncMetadataInfoComponent, RelativeDatePipe],
15 imports: [NgbPopoverModule]
19 fixture = TestBed.createComponent(RgwSyncMetadataInfoComponent);
20 component = fixture.componentInstance;
21 fixture.detectChanges();
24 it('should create', () => {
25 expect(component).toBeTruthy();
28 it('should display "Up to Date" badge when zone is up to date', () => {
29 component.metadataSyncInfo = {
32 fixture.detectChanges();
33 const upToDateBadge = fixture.debugElement.query(By.css('.badge-success'));
34 expect(upToDateBadge).toBeTruthy();
35 expect(upToDateBadge.nativeElement.textContent).toEqual('Up to Date');
38 it('should display correct sync status and last synced time', () => {
39 component.metadataSyncInfo = {
40 syncstatus: 'Syncing',
41 timestamp: new Date(Date.now() - 10 * 60 * 1000)
43 fixture.detectChanges();
45 const statusElement = fixture.debugElement.query(By.css('li b'));
46 expect(statusElement.nativeElement.textContent).toContain('Status:');
48 const lastSyncedElement = fixture.debugElement.query(By.css('li.mt-4.fw-bold'));
49 expect(lastSyncedElement.nativeElement.textContent).toContain('Last Synced:');
50 const lastSyncedTimestamp = fixture.debugElement.query(By.css('.badge-info'));
51 expect(lastSyncedTimestamp.nativeElement.textContent).toEqual('10 minutes ago');
54 it('should display sync status in the popover', () => {
55 component.metadataSyncInfo = {
56 syncstatus: 'Syncing',
57 timestamp: new Date(Date.now() - 10 * 60 * 1000),
59 'full sync:0/128 shards',
60 'incremental sync:128/128 shards',
61 'Data is behind on 31 shards'
64 fixture.detectChanges();
65 const syncStatus = fixture.debugElement.query(By.css('.text-primary'));
66 expect(syncStatus).toBeTruthy();
67 expect(syncStatus.nativeElement.textContent).toEqual('Syncing');
68 const syncPopover = fixture.nativeElement.querySelector('a');
69 syncPopover.dispatchEvent(new Event('click'));
70 fixture.detectChanges();
71 expect(syncPopover).toBeTruthy();
72 const syncPopoverText = fixture.debugElement.query(By.css('.text-center'));
73 expect(syncPopoverText.nativeElement.textContent).toEqual(
74 'Metadata Sync Status:Full Sync:0/128 Shards Incremental Sync:128/128 Shards Data Is Behind On 31 Shards'