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

fix(search): SSR gets stuck in resolver when query is empty #2954

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
82 changes: 53 additions & 29 deletions libs/search/routing/src/resolvers/search/search.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,44 +78,68 @@ describe('@daffodil/search/routing | DaffSearchPageResolver', () => {
spyOn(store, 'dispatch');
}));

it('should dispatch a DaffSearchLoad action with the correct search query', () => {
searchResolver.resolve(<ActivatedRouteSnapshot><unknown>{
...route.snapshot,
queryParams: {
query,
},
}).subscribe();
expect(store.dispatch).toHaveBeenCalledWith(
new DaffSearchLoad(query, options),
);
});
describe('when the query is defined', () => {
let snapshot: ActivatedRouteSnapshot;

beforeEach(() => {
snapshot = <ActivatedRouteSnapshot><unknown>{
...route.snapshot,
queryParams: {
query,
},
};
});

it('should resolve when DaffSearchLoadSuccess is dispatched', done => {
searchResolver.resolve(route.snapshot).subscribe(value => {
expect(value).toEqual(true);
done();
it('should dispatch a DaffSearchLoad action with the correct search query', () => {
searchResolver.resolve(snapshot).subscribe();
expect(store.dispatch).toHaveBeenCalledWith(
new DaffSearchLoad(query, options),
);
});

actions$.next(new DaffSearchLoadSuccess({
collection: {},
metadata: {},
}));
});
it('should resolve when DaffSearchLoadSuccess is dispatched', done => {
searchResolver.resolve(snapshot).subscribe(value => {
expect(value).toEqual(true);
done();
});

it('should resolve when DaffCartLoadFailure is dispatched', done => {
searchResolver.resolve(route.snapshot).subscribe(value => {
expect(value).toEqual(true);
done();
actions$.next(new DaffSearchLoadSuccess({
collection: {},
metadata: {},
}));
});

actions$.next(new DaffSearchLoadFailure(null));
it('should resolve when DaffCartLoadFailure is dispatched', done => {
searchResolver.resolve(snapshot).subscribe(value => {
expect(value).toEqual(true);
done();
});

actions$.next(new DaffSearchLoadFailure(null));
});

it('should not resolve without a search load success or failure', () => {
searchResolver.resolve(snapshot).subscribe(() => {
fail();
});
expect(true).toBeTruthy();
});
});

it('should not resolve without a search load success or failure', () => {
searchResolver.resolve(route.snapshot).subscribe(() => {
fail();
describe('when the query is not defined', () => {
it('should return true immediately', (done) => {
searchResolver.resolve(route.snapshot).subscribe((res) => {
expect(res).toBeTrue();
done();
});
});

it('should not initiate a search', (done) => {
searchResolver.resolve(route.snapshot).subscribe((res) => {
expect(store.dispatch).not.toHaveBeenCalled();
done();
});
});
expect(true).toBeTruthy();
});
});

Expand Down
18 changes: 10 additions & 8 deletions libs/search/routing/src/resolvers/search/search.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ export class DaffSearchPageResolver {
const query = getQuery(route);
if (query) {
this.store.dispatch(new DaffSearchLoad(query, this.builder(route)));

return isPlatformBrowser(this.platformId) ? of(true) : this.dispatcher.pipe(
ofType(
DaffSearchActionTypes.SearchLoadSuccessAction,
DaffSearchActionTypes.SearchLoadFailureAction,
),
map(() => true),
take(1),
);
}

return isPlatformBrowser(this.platformId) ? of(true) : this.dispatcher.pipe(
ofType(
DaffSearchActionTypes.SearchLoadSuccessAction,
DaffSearchActionTypes.SearchLoadFailureAction,
),
map(() => true),
take(1),
);
return of(true);
}
}
Loading