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-133262 / 25.04 / Fix more strict null issues #11240

Merged
merged 4 commits into from
Dec 28, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('RebootRequiredDialogComponent', () => {

it('shows reasons', () => {
expect(
spectator.queryAll('.reasons li').map((item) => item.textContent.trim()),
spectator.queryAll('.reasons li').map((item) => item.textContent!.trim()),
).toEqual([
'Test Reason 1',
'Test Reason 2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IxDatepickerComponent } from './ix-date-picker.component';
describe('IxDatePickerComponent', () => {
let spectator: SpectatorHost<IxDatepickerComponent>;
let loader: HarnessLoader;
const formControl = new FormControl<Date>(null);
const formControl = new FormControl<Date | null>(null);

const createHost = createHostFactory({
component: IxDatepickerComponent,
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('IxDatePickerComponent', () => {
},
});

const label = spectator.query(IxLabelComponent);
const label = spectator.query(IxLabelComponent)!;
expect(label).toExist();
expect(label.label()).toBe('Label');
expect(label.tooltip()).toBe('Tooltip');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('IxSlideIn2Component', () => {

it('close slide-in when backdrop is clicked', fakeAsync(() => {
setupComponent();
const backdrop = spectator.query('.ix-slide-in2-background');
const backdrop = spectator.query('.ix-slide-in2-background')!;
backdrop.dispatchEvent(new Event('click'));
spectator.detectChanges();
expect(close$.next).toHaveBeenCalledWith({ response: false, error: null });
Expand All @@ -203,7 +203,7 @@ describe('IxSlideIn2Component', () => {

it('asks for confirmation when require confirmation method setup', fakeAsync(() => {
setupComponent();
const form = spectator.query(CloudSyncFormComponent);
const form = spectator.query(CloudSyncFormComponent)!;
form.form.markAsDirty();
spectator.detectChanges();
const backdrop = spectator.query('.ix-slide-in2-background');
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('IxSlideIn2Component', () => {
await saveButton.click();
form.form.markAsDirty();
spectator.detectChanges();
const backdrop = spectator.query('.ix-slide-in2-background');
const backdrop = spectator.query('.ix-slide-in2-background')!;
backdrop.dispatchEvent(new Event('click'));

expect(spectator.inject(DialogService).confirm).not.toHaveBeenCalledWith({
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/slide-ins/old-slide-in.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('SlideInComponent', () => {

it('call \'openSlideIn\' should create a host element in the body of the slide', () => {
spectator.component.openSlideIn(TestClassComponent, { wide: true, data: 'Component created dynamically' });
const dynamicElement: HTMLElement = (spectator.debugElement.nativeElement as Element).querySelector('h1');
const dynamicElement = (spectator.debugElement.nativeElement as Element).querySelector('h1');
spectator.fixture.detectChanges();

expect(dynamicElement).toHaveText('Component created dynamically');
Expand All @@ -62,7 +62,7 @@ describe('SlideInComponent', () => {
spectator.component.closeSlideIn();

spectator.tick(200);
const dynamicElement: HTMLElement = (spectator.debugElement.nativeElement as Element).querySelector('.ix-slide-in-body');
const dynamicElement = (spectator.debugElement.nativeElement as Element).querySelector('.ix-slide-in-body');
expect(dynamicElement).toBeEmpty();
}));
});
20 changes: 8 additions & 12 deletions src/app/pages/audit/audit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ export class AuditComponent implements OnInit, OnDestroy {
textColumn({
title: this.translate.instant('Service'),
propertyName: 'service',
getValue: (row) => (auditServiceLabels.has(row.service)
? this.translate.instant(auditServiceLabels.get(row.service))
: row.service || '-'),
getValue: (row) => this.translate.instant(auditServiceLabels.get(row.service) || row.service || '-'),
}),
textColumn({
title: this.translate.instant('User'),
Expand All @@ -142,9 +140,7 @@ export class AuditComponent implements OnInit, OnDestroy {
textColumn({
title: this.translate.instant('Event'),
propertyName: 'event',
getValue: (row) => (auditEventLabels.has(row.event)
? this.translate.instant(auditEventLabels.get(row.event))
: row.event || '-'),
getValue: (row) => this.translate.instant(auditEventLabels.get(row.event) || row.event || '-'),
}),
textColumn({
title: this.translate.instant('Event Data'),
Expand Down Expand Up @@ -334,8 +330,8 @@ export class AuditComponent implements OnInit, OnDestroy {
'service',
this.translate.instant('Service'),
of(Object.values(AuditService).map((key) => ({
label: this.translate.instant(auditServiceLabels.get(key)),
value: `"${this.translate.instant(auditServiceLabels.get(key))}"`,
label: this.translate.instant(auditServiceLabels.get(key) || key),
value: `"${this.translate.instant(auditServiceLabels.get(key) || key)}"`,
}))),
auditServiceLabels,
),
Expand All @@ -348,8 +344,8 @@ export class AuditComponent implements OnInit, OnDestroy {
'event',
this.translate.instant('Event'),
of(Object.values(AuditEvent).map((key) => ({
label: this.translate.instant(auditEventLabels.get(key)),
value: `"${this.translate.instant(auditEventLabels.get(key))}"`,
label: this.translate.instant(auditEventLabels.get(key) || key),
value: `"${this.translate.instant(auditEventLabels.get(key) || key)}"`,
}))),
auditEventLabels,
),
Expand Down Expand Up @@ -388,8 +384,8 @@ export class AuditComponent implements OnInit, OnDestroy {
'event_data.credentials.credentials',
this.translate.instant('Middleware - Credentials'),
of(Object.values(CredentialType).map((key) => ({
label: this.translate.instant(credentialTypeLabels.get(key)),
value: `"${this.translate.instant(credentialTypeLabels.get(key))}"`,
label: this.translate.instant(credentialTypeLabels.get(key) || key),
value: `"${this.translate.instant(credentialTypeLabels.get(key) || key)}"`,
}))),
credentialTypeLabels,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const cloudCredentialsCardElements = {
T('Add Credential'),
T('Add Backup Credential'),
T('New Credential'),
T('New Could Credential'),
T('New Cloud Credential'),
T('New Backup Credential'),
T('Create Credential'),
T('Create Cloud Credential'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('CloudCredentialsFormComponent', () => {
const providersSelect = await form.getControl('Provider') as IxSelectHarness;
await providersSelect.setValue('Amazon S3');

const providerForm = spectator.query(S3ProviderFormComponent);
const providerForm = spectator.query(S3ProviderFormComponent)!;
expect(providerForm).toBeTruthy();
expect(providerForm.provider).toBe(s3Provider);
});
Expand All @@ -144,7 +144,7 @@ describe('CloudCredentialsFormComponent', () => {
const providersSelect = await form.getControl('Provider') as IxSelectHarness;
await providersSelect.setValue('Storj iX');

const providerForm = spectator.query(StorjProviderFormComponent);
const providerForm = spectator.query(StorjProviderFormComponent)!;
expect(providerForm).toBeTruthy();
expect(providerForm.provider).toBe(storjProvider);
expect(spectator.query(CloudSyncProviderDescriptionComponent)).toBeTruthy();
Expand All @@ -154,7 +154,7 @@ describe('CloudCredentialsFormComponent', () => {
const providersSelect = await form.getControl('Provider') as IxSelectHarness;
await providersSelect.setValue('Box');

const providerForm = spectator.query(TokenProviderFormComponent);
const providerForm = spectator.query(TokenProviderFormComponent)!;
expect(providerForm).toBeTruthy();
expect(providerForm.provider).toBe(boxProvider);
});
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('CloudCredentialsFormComponent', () => {
const saveButton = await loader.getHarness(MatButtonHarness.with({ text: 'Verify Credential' }));
await saveButton.click();

const providerForm = spectator.query(S3ProviderFormComponent);
const providerForm = spectator.query(S3ProviderFormComponent)!;
expect(providerForm.beforeSubmit).toHaveBeenCalled();
});

Expand Down Expand Up @@ -222,7 +222,7 @@ describe('CloudCredentialsFormComponent', () => {
const saveButton = await loader.getHarness(MatButtonHarness.with({ text: 'Save' }));
await saveButton.click();

const providerForm = spectator.query(S3ProviderFormComponent);
const providerForm = spectator.query(S3ProviderFormComponent)!;
expect(providerForm.beforeSubmit).toHaveBeenCalled();
});

Expand Down Expand Up @@ -299,7 +299,7 @@ describe('CloudCredentialsFormComponent', () => {
Provider: 'Amazon S3',
});

const providerForm = spectator.query(S3ProviderFormComponent);
const providerForm = spectator.query(S3ProviderFormComponent)!;
expect(providerForm).toBeTruthy();
expect(providerForm.getFormSetter$().next).toHaveBeenCalledWith({
type: CloudSyncProviderName.AmazonS3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ describe('CertificateAuthorityAddComponent', () => {
await goToNextStep();
await goToNextStep();

const summary = spectator.query(SummaryComponent);
const summary = spectator.query(SummaryComponent)!;
expect(summary.summary).toEqual([
[
{ label: 'Name', value: 'new' },
Expand Down Expand Up @@ -286,13 +286,13 @@ describe('CertificateAuthorityAddComponent', () => {
});

it('updates form fields and sets constrains when Profile is emitted by CertificateIdentifierAndTypeComponent', async () => {
const optionsForm = spectator.query(CertificateOptionsComponent);
const subjectForm = spectator.query(CertificateSubjectComponent);
const optionsForm = spectator.query(CertificateOptionsComponent)!;
const subjectForm = spectator.query(CertificateSubjectComponent)!;

jest.spyOn(optionsForm.form, 'patchValue');
jest.spyOn(subjectForm.form, 'patchValue');

const constraintsForm = spectator.query(CertificateConstraintsComponent);
const constraintsForm = spectator.query(CertificateConstraintsComponent)!;
jest.spyOn(constraintsForm, 'setFromProfile');

await form.fillForm({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ describe('CertificateDetailsComponent', () => {
function getDetails(): Record<string, string> {
const itemElements = spectator.queryAll('dl > div');
return itemElements.reduce((acc, item) => {
const key = item.querySelector('dt')!.textContent;
const value = item.querySelector('dd')!.textContent;
const key = item.querySelector('dt')!.textContent!;
const value = item.querySelector('dd')!.textContent!;
acc[key] = value;
return acc;
}, {} as Record<string, string>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ describe('CsrAddComponent', () => {

await nextButton.click();

const summary = spectator.query(SummaryComponent);
const summary = spectator.query(SummaryComponent)!;
expect(summary.summary).toEqual([
[
{ label: 'Name', value: 'import' },
Expand All @@ -251,13 +251,13 @@ describe('CsrAddComponent', () => {
});

it('updates form fields and sets constrains when Profile is emitted by CertificateIdentifierAndTypeComponent', async () => {
const optionsForm = spectator.query(CertificateOptionsComponent);
const subjectForm = spectator.query(CertificateSubjectComponent);
const optionsForm = spectator.query(CertificateOptionsComponent)!;
const subjectForm = spectator.query(CertificateSubjectComponent)!;

jest.spyOn(optionsForm.form, 'patchValue');
jest.spyOn(subjectForm.form, 'patchValue');

const constraintsForm = spectator.query(CertificateConstraintsComponent);
const constraintsForm = spectator.query(CertificateConstraintsComponent)!;
jest.spyOn(constraintsForm, 'setFromProfile');

await form.fillForm({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { getCertificatePreview } from 'app/pages/credentials/certificates-dash/u
],
})
export class CsrImportComponent implements SummaryProvider {
form = this.formBuilder.group({
form = this.formBuilder.nonNullable.group({
CSR: ['', Validators.required],
privatekey: ['', Validators.required],
passphrase: [''],
Expand All @@ -58,7 +58,7 @@ export class CsrImportComponent implements SummaryProvider {
) {}

getSummary(): SummarySection {
const values = this.form.value;
const values = this.form.getRawValue();
const csrPreview = getCertificatePreview(values.CSR);

const summary: SummarySection = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('AcmednsFormComponent', () => {
it('shows values for an existing DNS Authenticator when form is opened for edit', async () => {
spectator.component.ngOnInit();

let authenticator: Option[];
let authenticator: Option[] = [];
spectator.component.authenticatorOptions$.subscribe((options) => authenticator = options);

expect(spectator.inject(ApiService).call).toHaveBeenCalledWith('acme.dns.authenticator.authenticator_schemas');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { ApiService } from 'app/services/websocket/api.service';
export class DeleteGroupDialogComponent {
readonly requiredRoles = [Role.AccountWrite];

deleteUsersCheckbox = new FormControl(false);
deleteUsersCheckbox = new FormControl(false, { nonNullable: true });

readonly deleteMessage = T('Are you sure you want to delete group <b>"{name}"</b>?');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const dummyGroup = {
group: 'dummy',
builtin: false,
smb: true,
users: [],
users: [] as number[],
} as Group;

describe('GroupDetailsRowComponent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('GroupFormComponent', () => {
const fakeDataGroup = {
id: 13,
gid: 1111,
sudo_commands: [],
sudo_commands: [] as string[],
name: 'Group A',
sudo_commands_nopasswd: [allCommands],
smb: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class GroupListComponent implements OnInit {
textColumn({
title: this.translate.instant('Roles'),
getValue: (row) => row.roles
.map((role) => (roleNames.has(role) ? this.translate.instant(roleNames.get(role)) : role))
.map((role) => this.translate.instant(roleNames.get(role) || role))
.join(', ') || this.translate.instant('N/A'),
}),
], {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class PrivilegeFormComponent implements OnInit {
});

return sortedRoles.map((role) => ({
label: roleNames.has(role.name) ? this.translate.instant(roleNames.get(role.name)) : role.name,
label: this.translate.instant(roleNames.get(role.name) || role.name),
value: role.name,
}));
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class PrivilegeListComponent implements OnInit {
textColumn({
title: this.translate.instant('Roles'),
getValue: (row) => row.roles.map((role) => {
return roleNames.has(role) ? this.translate.instant(roleNames.get(role)) : role;
return this.translate.instant(roleNames.get(role) || role);
}).join(', ') || this.translate.instant('N/A'),
disableSorting: true,
}),
Expand Down Expand Up @@ -137,8 +137,8 @@ export class PrivilegeListComponent implements OnInit {

private readonly rolesSuggestions$ = of(Object.values(Role)).pipe(
map((roles) => roles.map((key) => ({
label: this.translate.instant(roleNames.get(key)),
value: `"${this.translate.instant(roleNames.get(key))}"`,
label: this.translate.instant(roleNames.get(key) || key),
value: `"${this.translate.instant(roleNames.get(key) || key)}"`,
}))),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ const dummyUser = {
smb: false,
password_disabled: false,
locked: false,
sudo_commands: [],
sudo_commands_nopasswd: [],
sudo_commands: [] as string[],
sudo_commands_nopasswd: [] as string[],
email: 'test-user@test-user.com',
group: {
id: 41,
bsdgrp_gid: 0,
bsdgrp_group: 'test-user',
},
groups: [],
groups: [] as number[],
} as User;

describe('UserDetailsRowComponent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class UserListComponent implements OnInit {
textColumn({
title: this.translate.instant('Roles'),
getValue: (row) => row.roles
.map((role) => (roleNames.has(role) ? this.translate.instant(roleNames.get(role)) : role))
.map((role) => this.translate.instant(roleNames.get(role) || role))
.join(', ') || this.translate.instant('N/A'),
}),
], {
Expand Down
Loading
Loading