Skip to content
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
56 changes: 55 additions & 1 deletion ui/src/app/search/rich-skill-search-results.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Title } from "@angular/platform-browser"
import { ActivatedRoute, Router } from "@angular/router"
import { ActivatedRouteStubSpec } from "test/util/activated-route-stub.spec"
import { createMockPaginatedSkills, createMockSkillSummary } from "../../../test/resource/mock-data"
import { RichSkillServiceStub, SearchServiceStub } from "../../../test/resource/mock-stubs"
import {RichSkillServiceStub, SearchServiceData, SearchServiceStub} from "../../../test/resource/mock-stubs"
import { AppConfig } from "../app.config"
import { EnvironmentService } from "../core/environment.service"
import { PublishStatus } from "../PublishStatus"
Expand Down Expand Up @@ -297,3 +297,57 @@ describe("RichSkillSearchResultsComponent with params", () => {
expect(component.apiSearch).toBeTruthy()
})
})

describe("RichSkillSearchResultsComponent with advance search params in history.state", () => {
let searchService: SearchService
let advanced: ApiAdvancedSearch

beforeEach(() => {
activatedRoute = new ActivatedRouteStubSpec()
})

beforeEach(async(() => {
const routerSpy = ActivatedRouteStubSpec.createRouterSpy()

TestBed.configureTestingModule({
declarations: [
RichSkillSearchResultsComponent
],
imports: [
HttpClientTestingModule, // Needed to avoid the toolName race condition below
],
providers: [
EnvironmentService, // Needed to avoid the toolName race condition below
AppConfig, // Needed to avoid the toolName race condition below
Title,
ToastService,
{ provide: SearchService, useClass: SearchServiceStub },
{ provide: RichSkillService, useClass: RichSkillServiceStub },
{ provide: ActivatedRoute, useValue: activatedRoute },
{ provide: Router, useValue: routerSpy },
]
})
.compileComponents()

const appConfig = TestBed.inject(AppConfig)
AppConfig.settings = appConfig.defaultConfig() // This avoids the race condition on reading the config's whitelabel.toolName
searchService = TestBed.inject(SearchService)

createComponent(RichSkillSearchResultsComponent, () => {
// Arrange - Setup for ngOnInit alternate path
advanced = new ApiAdvancedSearch()
advanced.keywords = ["test keywords"]

searchService.advancedSkillSearch(advanced)
history.pushState(SearchServiceData.latestSearch, "advanced")
component.apiSearch = new ApiSearch({advanced})
})
}))

it("ngOnInit should handle latestSearch", () => {
// Assert
expect(component.apiSearch).toBeTruthy()
expect(history.state.advanced).toBeTruthy()
expect(history.state.advanced).toEqual({keywords: ["test keywords"]})
})
})
3 changes: 3 additions & 0 deletions ui/src/app/search/rich-skill-search-results.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class RichSkillSearchResultsComponent extends SkillsListComponent impleme

ngOnInit(): void {
this.titleService.setTitle(`Search Results | ${this.whitelabel.toolName}`)
if (history.state?.advanced) {
this.searchService.latestSearch = new ApiSearch(history.state);
}

if (this.searchService.latestSearch !== undefined) {
this.handleNewSearch(this.searchService.latestSearch)
Expand Down
16 changes: 16 additions & 0 deletions ui/src/app/search/search.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ describe("SearchService", () => {
expect(RouterData.commands).toEqual(["/skills/search"])
})

it( "should pass advanced query to history.state via router navigation", () => {
// Arrange
const advanced = new ApiAdvancedSearch()
advanced.keywords = ["test keywords"]
const apiSearch = new ApiSearch({advanced});
RouterData.commands = []
RouterData.extras = {}

// Act
service.advancedSkillSearch(advanced)

// Assert
expect(RouterData.commands).toEqual(["/skills/search"])
expect(RouterData.extras).toEqual({state: apiSearch})
})

it("should perform simple collection search", () => {
// Arrange
let result: ApiSearch | undefined
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/search/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class SearchService {
}
advancedSkillSearch(advanced: ApiAdvancedSearch): void {
this.setLatestSearch(new ApiSearch({advanced}))
this.router.navigate(["/skills/search"])
this.router.navigate(["/skills/search"], {state: this.latestSearch})
}

simpleCollectionSearch(query: string): void {
Expand Down