Commit a28be83e authored by Exbrayat Cédric's avatar Exbrayat Cédric
Browse files

fix: don't display results on new search

parent 0786a3ef
......@@ -9,7 +9,7 @@
</form>
</div>
<!-- results -->
<div class="mt-5">
<div class="mt-5" *ngIf="results">
<rare-genetic-resources [geneticResources]="results"></rare-genetic-resources>
</div>
<!-- pagination -->
......
......@@ -161,8 +161,8 @@ describe('SearchComponent', () => {
const tester = new SearchComponentTester();
const component = tester.componentInstance;
// then it should display results even if empty
expect(tester.results).not.toBeNull();
// then it should not display results if empty
expect(tester.results).toBeNull();
// when it has results
const resource = toGeneticResource('Bacteria');
......@@ -181,6 +181,29 @@ describe('SearchComponent', () => {
expect(paginationComponent.pageCount).toBe(2);
});
it('should hide results and pagination on a new search', () => {
// given a component
const tester = new SearchComponentTester();
const component = tester.componentInstance;
// with results
const resource = toGeneticResource('Bacteria');
component.results = toSecondPage([resource]);
tester.detectChanges();
// displayed
expect(tester.results).not.toBeNull();
// when a new search is triggered
component.newSearch();
tester.detectChanges();
// then it should hide previous results
expect(tester.results).toBeNull();
// and pagination
expect(tester.pagination).toBeNull();
});
it('should not display pagination if no result yet', () => {
// given a component with no result yet
const tester = new SearchComponentTester();
......
......@@ -49,6 +49,7 @@ export class SearchComponent implements OnInit {
* It uses the new search terms in the form, and asks for the default page (1) for this new query
*/
newSearch() {
this.results = undefined;
this.query = this.searchForm.get('search').value;
this.search();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment