Sonarcloud issues fixes (#3499)

* Sonarcloud issues fixes

* Code smell fixes

* Refactoring to remove new code duplications

* Sonarcloud code smell fixes part I

* Sonarcloud code smell fixes part II

* Missing code smell fix

* Add new ESLint rules to cover fixed SonarCloud issues

* Add missing command

* Add missing is existing check
This commit is contained in:
MichalKinas
2023-11-03 11:43:06 +01:00
committed by GitHub
parent 968febffb0
commit 69c00fc403
72 changed files with 327 additions and 530 deletions

View File

@@ -42,39 +42,39 @@ describe('SearchInputControlComponent', () => {
fixture.detectChanges();
});
it('should emit submit event on searchSubmit', async () => {
it('should emit submit event on searchSubmit', () => {
const keyboardEvent = { target: { value: 'a' } };
let eventArgs = null;
component.submit.subscribe((args) => (eventArgs = args));
await component.searchSubmit(keyboardEvent);
component.searchSubmit(keyboardEvent);
expect(eventArgs).toBe(keyboardEvent);
});
it('should emit searchChange event on inputChange', async () => {
it('should emit searchChange event on inputChange', () => {
const searchTerm = 'b';
let eventArgs = null;
component.searchChange.subscribe((args) => (eventArgs = args));
await component.inputChange(searchTerm);
component.inputChange(searchTerm);
expect(eventArgs).toBe(searchTerm);
});
it('should emit searchChange event on clear', async () => {
it('should emit searchChange event on clear', () => {
let eventArgs = null;
component.searchChange.subscribe((args) => (eventArgs = args));
await component.clear();
component.clear();
expect(eventArgs).toBe('');
});
it('should clear searchTerm', async () => {
it('should clear searchTerm', () => {
component.searchTerm = 'c';
fixture.detectChanges();
await component.clear();
component.clear();
expect(component.searchTerm).toBe('');
});

View File

@@ -53,13 +53,13 @@ describe('SearchLibrariesQueryBuilderService', () => {
expect(builder.userQuery).toEqual('something');
});
it('should build query and raise an event on update', async () => {
it('should build query and raise an event on update', () => {
spyOn(builder, 'buildQuery').and.returnValue(query);
let eventArgs = null;
builder.updated.subscribe((args) => (eventArgs = args));
await builder.update();
builder.update();
expect(eventArgs).toBe(query);
});

View File

@@ -80,12 +80,12 @@ export class SearchLibrariesQueryBuilderService {
buildQuery(): LibrarySearchQuery {
const query = this.userQuery;
if (query && query.length > 1) {
if (query?.length > 1) {
return {
term: query,
opts: {
skipCount: this.paging && this.paging.skipCount,
maxItems: this.paging && this.paging.maxItems
skipCount: this.paging?.skipCount,
maxItems: this.paging?.maxItems
}
};
}

View File

@@ -158,7 +158,7 @@ export class SearchLibrariesResultsComponent extends PageComponent implements On
}
getNumberOfResults() {
if (this.data && this.data.list && this.data.list.pagination) {
if (this.data?.list?.pagination) {
return this.data.list.pagination.totalItems;
}
return 0;
@@ -173,7 +173,7 @@ export class SearchLibrariesResultsComponent extends PageComponent implements On
}
navigateTo(node: SiteEntry) {
if (node && node.entry && node.entry.guid) {
if (node?.entry?.guid) {
this.store.dispatch(new NavigateLibraryAction(node.entry.guid));
}
}

View File

@@ -74,7 +74,7 @@ export class SearchResultsRowComponent implements OnInit, OnDestroy {
if (entry.id === node.id) {
entry.name = node.name;
entry.properties = Object.assign({}, node.properties);
entry.properties = { ...node.properties };
this.updateValues();
}

View File

@@ -95,11 +95,7 @@ describe('SearchComponent', () => {
});
it('should raise an error if search fails', fakeAsync(() => {
spyOn(queryBuilder['searchApi'], 'search').and.returnValue(
Promise.reject({
message: `{ "error": { "statusCode": 500 } } `
})
);
spyOn(queryBuilder['searchApi'], 'search').and.returnValue(Promise.reject(new Error('{ "error": { "statusCode": 500 } }')));
spyOn(queryBuilder, 'buildQuery').and.returnValue(searchRequest);
spyOn(store, 'dispatch').and.stub();
@@ -118,11 +114,7 @@ describe('SearchComponent', () => {
return key;
});
spyOn(queryBuilder['searchApi'], 'search').and.returnValue(
Promise.reject({
message: `{ "error": { "statusCode": 401 } } `
})
);
spyOn(queryBuilder['searchApi'], 'search').and.returnValue(Promise.reject(new Error('{ "error": { "statusCode": 401 } }')));
spyOn(queryBuilder, 'buildQuery').and.returnValue(searchRequest);
spyOn(store, 'dispatch').and.stub();
@@ -141,11 +133,7 @@ describe('SearchComponent', () => {
return key;
});
spyOn(queryBuilder['searchApi'], 'search').and.returnValue(
Promise.reject({
message: `{ "error": { "statusCode": 401 } } `
})
);
spyOn(queryBuilder['searchApi'], 'search').and.returnValue(Promise.reject(new Error('{ "error": { "statusCode": 401 } }')));
spyOn(queryBuilder, 'buildQuery').and.returnValue(searchRequest);
spyOn(store, 'dispatch').and.stub();
@@ -191,7 +179,7 @@ describe('SearchComponent', () => {
});
it('should format user input as cm:name if configuration not provided', () => {
const query = component.formatSearchQuery('hello', undefined);
const query = component.formatSearchQuery('hello');
expect(query).toBe(`(cm:name:"hello*")`);
});

View File

@@ -266,7 +266,7 @@ export class SearchResultsComponent extends PageComponent implements OnInit {
}
onNodeDoubleClick(node: NodeEntry) {
if (node && node.entry) {
if (node?.entry) {
if (node.entry.isFolder) {
this.store.dispatch(new NavigateToFolder(node));
return;