Skip to content

Commit

Permalink
NAS-129788 / 24.10 / Cloud Backup | Snapshots list is not updating af…
Browse files Browse the repository at this point in the history
…ter Job Run (#10257)

* NAS-129788: Cloud Backup | Snapshots list is not updating after Job Run

* NAS-129788: PR update

* NAS-129788: PR update
  • Loading branch information
AlexKarpov98 authored Jul 1, 2024
1 parent 27ec2fd commit 36fe155
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import { provideMockStore } from '@ngrx/store/testing';
import { MockComponents, MockModule } from 'ng-mocks';
import { of } from 'rxjs';
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockJob, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { JobState } from 'app/enums/job-state.enum';
import { CloudBackup } from 'app/interfaces/cloud-backup.interface';
import { DialogService } from 'app/modules/dialog/dialog.service';
import { IxSlideInRef } from 'app/modules/forms/ix-forms/components/ix-slide-in/ix-slide-in-ref';
import { SearchInput1Component } from 'app/modules/forms/search-input1/search-input1.component';
import { IxIconHarness } from 'app/modules/ix-icon/ix-icon.harness';
import { AsyncDataProvider } from 'app/modules/ix-table/classes/async-data-provider/async-data-provider';
import { IxTableHarness } from 'app/modules/ix-table/components/ix-table/ix-table.harness';
import { SortDirection } from 'app/modules/ix-table/enums/sort-direction.enum';
import { IxTableModule } from 'app/modules/ix-table/ix-table.module';
import { AppLoaderModule } from 'app/modules/loader/app-loader.module';
import { PageHeaderModule } from 'app/modules/page-header/page-header.module';
Expand Down Expand Up @@ -69,6 +71,7 @@ describe('CloudBackupListComponent', () => {
mockCall('cloud_backup.query', cloudBackups),
mockCall('cloud_backup.delete'),
mockCall('cloud_backup.update'),
mockJob('cloud_backup.sync'),
]),
mockProvider(DialogService, {
confirm: jest.fn(() => of(true)),
Expand Down Expand Up @@ -133,6 +136,7 @@ describe('CloudBackupListComponent', () => {
});

expect(spectator.inject(WebSocketService).job).toHaveBeenCalledWith('cloud_backup.sync', [1]);
expect(spectator.component.dataProvider.expandedRow).toEqual({ ...cloudBackups[0] });
});

it('deletes a Cloud Backup with confirmation when Delete button is pressed', async () => {
Expand All @@ -159,4 +163,44 @@ describe('CloudBackupListComponent', () => {
[1, { enabled: true }],
);
});

it('closes mobile details view and updates dataProvider expandedRow', () => {
spectator.component.showMobileDetails = true;
spectator.component.dataProvider.expandedRow = cloudBackups[0];

spectator.component.closeMobileDetails();

expect(spectator.component.showMobileDetails).toBe(false);
expect(spectator.component.dataProvider.expandedRow).toBeNull();
});

it('sets the default sort for dataProvider', () => {
spectator.component.dataProvider = {
setSorting: jest.fn(),
} as unknown as AsyncDataProvider<CloudBackup>;

spectator.component.setDefaultSort();

expect(spectator.component.dataProvider.setSorting).toHaveBeenCalledWith({
active: 1,
direction: SortDirection.Asc,
propertyName: 'description',
});
});

it('filters the list of cloud backups based on the query string', () => {
spectator.component.dataProvider = {
setFilter: jest.fn(),
} as unknown as AsyncDataProvider<CloudBackup>;

const queryString = 'UA';
spectator.component.onListFiltered(queryString);

expect(spectator.component.filterString).toBe(queryString.toLowerCase());

expect(spectator.component.dataProvider.setFilter).toHaveBeenCalledWith({
query: queryString,
columnKeys: ['description'],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,16 @@ export class CloudBackupListComponent implements OnInit {
}).pipe(
filter(Boolean),
tap(() => this.updateRowJob(row, { ...row.job, state: JobState.Running })),
tap(() => this.snackbar.success(this.translate.instant('Cloud Backup «{name}» has started.', { name: row.description }))),
switchMap(() => this.ws.job('cloud_backup.sync', [row.id])),
untilDestroyed(this),
).subscribe({
next: (job: Job) => {
this.snackbar.success(this.translate.instant('Cloud Backup «{name}» has started.', { name: row.description }));
this.updateRowJob(row, job);
// Update expanded row to call child ngOnChanges method & update snapshots list
if (job.state === JobState.Success && this.dataProvider.expandedRow?.id === row.id) {
this.dataProvider.expandedRow = { ...row };
}
this.cdr.markForCheck();
},
error: (error: unknown) => {
Expand Down

0 comments on commit 36fe155

Please sign in to comment.