Skip to content

Commit

Permalink
Use reset whenever possible for logic standard
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Apr 16, 2024
1 parent 563372e commit 49b525e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 26 deletions.
2 changes: 1 addition & 1 deletion scilog/src/app/core/search-scroll.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class SearchScrollBaseService extends ScrollBaseService {

}

@Injectable()
@Injectable({ providedIn: 'root' })
export class SearchScrollService extends SearchScrollBaseService {

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
</span>

</mat-toolbar>
<search *ngIf="submittedSearch && searchString" [config]="config" [searchString]="submittedSearch" (close)="closeSearch()"></search>
<div class="searchHelp" *ngIf="!submittedSearch || !searchString">
<search *ngIf="logbookId && searched" [config]="config" (close)="closeSearch()"></search>
<div class="searchHelp" *ngIf="!logbookId || !searched ">
<mat-divider></mat-divider>
<div class="header">
Suggestions...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('SearchWindowComponent', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ SearchWindowComponent ],
providers: [
{ provide: AppConfigService, useValue: { getConfig } },
{ provide: MatDialog, useValue: {} },
Expand Down Expand Up @@ -51,17 +50,18 @@ describe('SearchWindowComponent', () => {
});

it('should submitSearch logbook', () => {
component.searchString = 'some';
expect(component.submittedSearch).toEqual(undefined);
const resetSpy = spyOn(component['searchScrollService'], 'reset');
const search = 'some';
component.searchString = search;
component.submitSearch();
expect(component.submittedSearch).toEqual('some');
expect(resetSpy).toHaveBeenCalledOnceWith(search);
expect(component.searched).toEqual(search);
});

it('should submitSearch overview', () => {
component.logbookId = undefined;
const search = 'some';
component.searchString = search;
expect(component.submittedSearch).toEqual(undefined);
const resetSpy = spyOn(component['logbookIconScrollService'], 'reset');
const emitSpy = spyOn(component.overviewSearch, 'emit');
const closeSearchSpy = spyOn(component, 'closeSearch');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { LogbookInfoService } from '@shared/logbook-info.service';
import { TagService } from '@shared/tag.service';
import { Hotkeys } from '@shared/hotkeys.service';
import { LogbookIconScrollService } from 'src/app/overview/logbook-icon-scroll-service.service';
import { SearchScrollService } from 'src/app/core/search-scroll.service';

interface SearchResult {
location: string[],
Expand Down Expand Up @@ -41,7 +42,6 @@ export class SearchWindowComponent implements OnInit {
tags: string[] = [];
_sample_user: string = "";
subscriptions: Subscription[] = [];
submittedSearch: string;
logbookId?: string;

constructor(
Expand All @@ -50,6 +50,7 @@ export class SearchWindowComponent implements OnInit {
private tagService: TagService,
private hotkeys: Hotkeys,
private logbookIconScrollService: LogbookIconScrollService,
private searchScrollService: SearchScrollService,
) { }

async ngOnInit(): Promise<void> {
Expand All @@ -74,8 +75,9 @@ export class SearchWindowComponent implements OnInit {
}

submitSearch() {
this.searched = this.searchString;
if (this.logbookId) {
this.submittedSearch = this.searchString;
this.searchScrollService.reset(this.searchString);
return
}
this.logbookIconScrollService.reset(this.searchString);
Expand Down Expand Up @@ -123,7 +125,7 @@ export class SearchWindowComponent implements OnInit {

set searchString(searchString: string) {
this._searchString = searchString;
if (this.logbookId && !searchString) this.submittedSearch = searchString;
if (!searchString) this.searched = searchString;
}

get searchString() {
Expand Down
6 changes: 0 additions & 6 deletions scilog/src/app/logbook/core/search/search.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ describe('SearchComponent', () => {
expect(component).toBeTruthy();
});

it('should submitSearch', () => {
const resetSpy = spyOn<any>(component.searchScrollService, 'reset');
component.submitSearch();
expect(resetSpy).toHaveBeenCalled();
});

it('should selectedSnippet', () => {
const emitSpy = spyOn(component.close, 'emit');
component.selectedSnippet('');
Expand Down
9 changes: 0 additions & 9 deletions scilog/src/app/logbook/core/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { animate, style, transition, trigger } from '@angular/animations';
selector: 'search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.css'],
providers: [SearchScrollService],
animations: [
trigger('spinner', [
transition(':enter', [
Expand All @@ -23,9 +22,6 @@ export class SearchComponent implements OnInit {
@Input()
config: WidgetItemConfig;

@Input()
searchString: string;

@Output() close = new EventEmitter<void>();

constructor(
Expand All @@ -35,11 +31,6 @@ export class SearchComponent implements OnInit {

async ngOnInit(): Promise<void> {
this.searchScrollService.initialize(this.config);
if (this.searchString) this.submitSearch();
}

submitSearch() {
this.searchScrollService.reset(this.searchString);
}

selectedSnippet($event) {
Expand Down

0 comments on commit 49b525e

Please sign in to comment.