Unverified Commit f327ecf7 authored by RehanY147's avatar RehanY147 Committed by GitHub
Browse files

NAS-118857 / 22.12 / Using job instead of call (#7292)

parent e7366152
Showing with 53 additions and 20 deletions
+53 -20
......@@ -19,6 +19,7 @@ export const mockEntityJobComponentRef = {
failure: new EventEmitter(),
wsshow: jest.fn(),
wspost: jest.fn(),
updateSize: jest.fn(),
},
close: jest.fn(),
} as unknown as MatDialogRef<EntityJobComponent>;
......@@ -2,8 +2,9 @@ import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { ReactiveFormsModule } from '@angular/forms';
import { MatButtonHarness } from '@angular/material/button/testing';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { MAT_DIALOG_DATA, MatDialogRef, MatDialog } from '@angular/material/dialog';
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest';
import { mockEntityJobComponentRef } from 'app/core/testing/utils/mock-entity-job-component-ref.utils';
import { mockCall, mockWebsocket } from 'app/core/testing/utils/mock-websocket.utils';
import { EncryptionKeyFormat } from 'app/enums/encryption-key-format.enum';
import { Dataset } from 'app/interfaces/dataset.interface';
......@@ -13,7 +14,7 @@ import { IxFormHarness } from 'app/modules/ix-forms/testing/ix-form.harness';
import { AppLoaderModule } from 'app/modules/loader/app-loader.module';
import { SnackbarModule } from 'app/modules/snackbar/snackbar.module';
import { EncryptionOptionsDialogComponent } from 'app/pages/datasets/modules/encryption/components/encyption-options-dialog/encryption-options-dialog.component';
import { DialogService, WebSocketService } from 'app/services';
import { AppLoaderService, DialogService, WebSocketService } from 'app/services';
import { EncryptionOptionsDialogData } from './encryption-options-dialog-data.interface';
describe('EncryptionOptionsDialogComponent', () => {
......@@ -34,6 +35,10 @@ describe('EncryptionOptionsDialogComponent', () => {
{ provide: MAT_DIALOG_DATA, useValue: {} },
mockProvider(MatDialogRef),
mockProvider(DialogService),
mockProvider(MatDialog, {
open: jest.fn(() => mockEntityJobComponentRef),
}),
mockProvider(AppLoaderService),
mockWebsocket([
mockCall('pool.dataset.change_key'),
mockCall('pool.dataset.inherit_parent_encryption_properties'),
......@@ -148,7 +153,7 @@ describe('EncryptionOptionsDialogComponent', () => {
const saveButton = await loader.getHarness(MatButtonHarness.with({ text: 'Save' }));
await saveButton.click();
expect(websocket.call).toHaveBeenCalledWith(
expect(mockEntityJobComponentRef.componentInstance.setCall).toHaveBeenCalledWith(
'pool.dataset.change_key',
['pool/parent/child', { key, generate_key: false }],
);
......@@ -169,7 +174,7 @@ describe('EncryptionOptionsDialogComponent', () => {
const saveButton = await loader.getHarness(MatButtonHarness.with({ text: 'Save' }));
await saveButton.click();
expect(websocket.call).toHaveBeenCalledWith(
expect(mockEntityJobComponentRef.componentInstance.setCall).toHaveBeenCalledWith(
'pool.dataset.change_key',
['pool/parent/child', { generate_key: true }],
);
......@@ -192,7 +197,7 @@ describe('EncryptionOptionsDialogComponent', () => {
const saveButton = await loader.getHarness(MatButtonHarness.with({ text: 'Save' }));
await saveButton.click();
expect(websocket.call).toHaveBeenCalledWith(
expect(mockEntityJobComponentRef.componentInstance.setCall).toHaveBeenCalledWith(
'pool.dataset.change_key',
['pool/parent/child', { passphrase: '12345678', pbkdf2iters: 350001 }],
);
......
......@@ -2,7 +2,7 @@ import {
ChangeDetectionStrategy, Component, Inject, OnInit,
} from '@angular/core';
import { Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { MAT_DIALOG_DATA, MatDialogRef, MatDialog } from '@angular/material/dialog';
import { FormBuilder } from '@ngneat/reactive-forms';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslateService } from '@ngx-translate/core';
......@@ -15,6 +15,7 @@ import { DatasetChangeKeyParams } from 'app/interfaces/dataset-change-key.interf
import { Dataset } from 'app/interfaces/dataset.interface';
import { WebsocketError } from 'app/interfaces/websocket-error.interface';
import { matchOtherValidator } from 'app/modules/entity/entity-form/validators/password-validation/password-validation';
import { EntityJobComponent } from 'app/modules/entity/entity-job/entity-job.component';
import { FormErrorHandlerService } from 'app/modules/ix-forms/services/form-error-handler.service';
import { IxValidatorsService } from 'app/modules/ix-forms/services/ix-validators.service';
import { findInTree } from 'app/modules/ix-tree/utils/find-in-tree.utils';
......@@ -78,6 +79,7 @@ export class EncryptionOptionsDialogComponent implements OnInit {
private validatorsService: IxValidatorsService,
private errorHandler: FormErrorHandlerService,
private snackbar: SnackbarService,
private mdDialog: MatDialog,
@Inject(MAT_DIALOG_DATA) public data: EncryptionOptionsDialogData,
) {}
......@@ -149,20 +151,28 @@ export class EncryptionOptionsDialogComponent implements OnInit {
body.pbkdf2iters = Number(values.pbkdf2iters);
}
this.loader.open();
this.ws.call('pool.dataset.change_key', [this.data.dataset.id, body])
.pipe(untilDestroyed(this))
.subscribe({
next: () => {
this.loader.close();
this.showSuccessDialog();
this.dialogRef.close(true);
},
error: (error: WebsocketError) => {
this.loader.close();
this.errorHandler.handleWsFormError(error, this.form);
},
});
const jobDialogRef = this.mdDialog.open(EntityJobComponent, {
data: {
title: this.translate.instant('Updating key type'),
},
});
jobDialogRef.componentInstance.setCall('pool.dataset.change_key', [this.data.dataset.id, body]);
jobDialogRef.componentInstance.success.pipe(untilDestroyed(this)).subscribe({
next: () => {
jobDialogRef.close();
this.showSuccessDialog();
this.dialogRef.close(true);
},
error: (error: WebsocketError) => {
this.errorHandler.handleWsFormError(error, this.form);
},
});
jobDialogRef.componentInstance.failure.pipe(untilDestroyed(this)).subscribe({
next: (error) => {
this.errorHandler.handleWsFormError(error, this.form);
},
});
jobDialogRef.componentInstance.submit();
}
private showSuccessDialog(): void {
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3277,6 +3277,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Waiting to Finish": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -2430,6 +2430,7 @@
"Updates Available": "",
"Updating": "",
"Updating Dataset ACL": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Waiting to Finish": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
......@@ -3775,6 +3775,7 @@
"Updating": "",
"Updating Dataset ACL": "",
"Updating group members": "",
"Updating key type": "",
"Updating production status...": "",
"Upgrade": "",
"Upgrade Pool": "",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment