-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move scroll button from search grid to search page (#360)
* Move scroll button from search grid to search page * Add debounce to scroll length check * Fix removing the debounced scroll listener * Rename browse-page test
- Loading branch information
Showing
4 changed files
with
64 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,25 @@ | ||
<template> | ||
<div> | ||
<SearchGridManualLoad | ||
:query="query" | ||
:search-term="query.q" | ||
data-testid="search-grid" | ||
@onLoadMoreImages="onLoadMoreImages" | ||
/> | ||
<ScrollButton data-testid="scroll-button" :show-btn="showScrollButton" /> | ||
</div> | ||
<SearchGridManualLoad | ||
:query="query" | ||
:search-term="query.q" | ||
data-testid="search-grid" | ||
@onLoadMoreImages="onLoadMoreImages" | ||
/> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'SearchGrid', | ||
props: ['searchTerm'], | ||
data: () => ({ | ||
showScrollButton: false, | ||
}), | ||
computed: { | ||
query() { | ||
return this.$store.state.query | ||
}, | ||
}, | ||
mounted() { | ||
document.addEventListener('scroll', this.checkScrollLength) | ||
}, | ||
beforeDestroy() { | ||
document.removeEventListener('scroll', this.checkScrollLength) | ||
}, | ||
methods: { | ||
onLoadMoreImages(searchParams) { | ||
this.$emit('onLoadMoreImages', searchParams) | ||
}, | ||
checkScrollLength() { | ||
this.showScrollButton = window.scrollY > 70 | ||
}, | ||
}, | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import BrowsePage from '~/pages/search' | ||
import render from '../../test-utils/render' | ||
|
||
const options = { | ||
stubs: { | ||
AppModal: true, | ||
FilterDisplay: true, | ||
NuxtChild: true, | ||
ScrollButton: true, | ||
SearchGridFilter: true, | ||
SearchGridForm: true, | ||
SearchTypeTabs: true, | ||
SearchGridManualLoad: true, | ||
}, | ||
mocks: { | ||
$store: { | ||
commit: jest.fn(), | ||
state: { query: { q: 'foo' }, isFilterVisible: false }, | ||
}, | ||
$router: { path: { name: 'search-image' } }, | ||
$route: { path: '/search/image' }, | ||
}, | ||
} | ||
|
||
describe('Search Grid Wrapper', () => { | ||
it('renders correct content', () => { | ||
const wrapper = render(BrowsePage, options) | ||
expect(wrapper.find('[data-testid="scroll-button"]').element).toBeDefined() | ||
window.scrollY = 50 | ||
wrapper.vm.checkScrollLength() | ||
expect(wrapper.vm.showScrollButton).toBe(false) | ||
}) | ||
|
||
it('renders the scroll button when the page scrolls down', () => { | ||
const wrapper = render(BrowsePage, options) | ||
window.scrollY = 80 | ||
wrapper.vm.checkScrollLength() | ||
expect(wrapper.vm.showScrollButton).toBe(true) | ||
}) | ||
}) |