]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
0457fe2a98348fb8824989b79cb05a615b11fd95
[ceph.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2
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';
8
9 describe('RgwSyncMetadataInfoComponent', () => {
10   let component: RgwSyncMetadataInfoComponent;
11   let fixture: ComponentFixture<RgwSyncMetadataInfoComponent>;
12
13   configureTestBed({
14     declarations: [RgwSyncMetadataInfoComponent, RelativeDatePipe],
15     imports: [NgbPopoverModule]
16   });
17
18   beforeEach(() => {
19     fixture = TestBed.createComponent(RgwSyncMetadataInfoComponent);
20     component = fixture.componentInstance;
21     fixture.detectChanges();
22   });
23
24   it('should create', () => {
25     expect(component).toBeTruthy();
26   });
27
28   it('should display "Up to Date" badge when zone is up to date', () => {
29     component.metadataSyncInfo = {
30       timestamp: null
31     };
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');
36   });
37
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)
42     };
43     fixture.detectChanges();
44
45     const statusElement = fixture.debugElement.query(By.css('li b'));
46     expect(statusElement.nativeElement.textContent).toContain('Status:');
47
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');
52   });
53
54   it('should display sync status in the popover', () => {
55     component.metadataSyncInfo = {
56       syncstatus: 'Syncing',
57       timestamp: new Date(Date.now() - 10 * 60 * 1000),
58       fullSyncStatus: [
59         'full sync:0/128 shards',
60         'incremental sync:128/128 shards',
61         'Data is behind on 31 shards'
62       ]
63     };
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'
75     );
76   });
77 });