Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-132227 / 24.10.1 / Fix enable change in SMB table (by bvasilenko) #11008

Open
wants to merge 2 commits into
base: stable/electriceel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/app/pages/sharing/smb/smb-list/smb-list.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatButtonHarness } from '@angular/material/button/testing';
import { MatSlideToggleHarness } from '@angular/material/slide-toggle/testing';
import { Router } from '@angular/router';
import { Spectator, createComponentFactory, mockProvider } from '@ngneat/spectator/jest';
import { provideMockStore } from '@ngrx/store/testing';
Expand Down Expand Up @@ -143,6 +144,19 @@ describe('SmbListComponent', () => {
expect(spectator.inject(WebSocketService).call).toHaveBeenCalledWith('sharing.smb.delete', [1]);
});

it('updates SMB Enabled status once mat-toggle is updated', async () => {
const toggle = await table.getHarnessInCell(MatSlideToggleHarness, 1, 3);

expect(await toggle.isChecked()).toBe(true);

await toggle.uncheck();

expect(spectator.inject(WebSocketService).call).toHaveBeenCalledWith(
'sharing.smb.update',
[1, { enabled: false }],
);
});

it('should show table rows', async () => {
const expectedRows = [
['Name', 'Path', 'Description', 'Enabled', 'Audit Logging', ''],
Expand Down
30 changes: 16 additions & 14 deletions src/app/pages/sharing/smb/smb-list/smb-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,7 @@ export class SmbListComponent implements OnInit {
title: this.translate.instant('Enabled'),
propertyName: 'enabled',
requiredRoles: this.requiredRoles,
onRowToggle: (row) => {
this.ws.call('sharing.smb.update', [row.id, { enabled: row.enabled }]).pipe(
this.appLoader.withLoader(),
untilDestroyed(this),
).subscribe({
next: (share) => {
row.enabled = share.enabled;
},
error: (error: unknown) => {
this.dataProvider.load();
this.dialog.error(this.errorHandler.parseError(error));
},
});
},
onRowToggle: (row) => this.onChangeEnabledState(row),
}),
yesNoColumn({
title: this.translate.instant('Audit Logging'),
Expand Down Expand Up @@ -233,4 +220,19 @@ export class SmbListComponent implements OnInit {
message: this.translate.instant('The path <i>{path}</i> is in a locked dataset.', { path }),
});
}

private onChangeEnabledState(row: SmbShare): void {
this.ws.call('sharing.smb.update', [row.id, { enabled: !row.enabled }]).pipe(
this.appLoader.withLoader(),
untilDestroyed(this),
).subscribe({
next: () => {
this.dataProvider.load();
},
error: (error: unknown) => {
this.dataProvider.load();
this.dialog.error(this.errorHandler.parseError(error));
},
});
}
}
Loading