feat(test): add e2e tests for Search

This commit is contained in:
Phan An 2021-01-04 17:42:21 +01:00
parent 2235063e93
commit bd70cd5bac
4 changed files with 92 additions and 1 deletions

View file

@ -0,0 +1,20 @@
{
"results": {
"songs": [
"2e8f1fadf1544522b1cd4efb97adedf8",
"44b395ba4e760f149b542aafc0451534",
"4cf008da0ad2349a5b8aaeb037f306bf",
"60a3f37eaa83e7cb8508f7513ae46bf7",
"79bdde00e9c9b34bffe06fd4026f9551",
"81d48670ee43f7eee30fc6c1f01d7ba8"
],
"artists": [
3
],
"albums": [
4,
8,
9
]
}
}

View file

@ -0,0 +1,11 @@
{
"songs": [
"2e8f1fadf1544522b1cd4efb97adedf8",
"44b395ba4e760f149b542aafc0451534",
"4cf008da0ad2349a5b8aaeb037f306bf",
"60a3f37eaa83e7cb8508f7513ae46bf7",
"79bdde00e9c9b34bffe06fd4026f9551",
"81d48670ee43f7eee30fc6c1f01d7ba8",
"af651d9c5e27dae14e1d7822663cc8a5"
]
}

View file

@ -0,0 +1,60 @@
context('Searching', () => {
beforeEach(() => {
cy.$login()
cy.get('#searchForm [name=q]').as('searchInput')
})
it('shows the search screen when search box receives focus', () => {
cy.get('@searchInput').focus()
cy.get('#searchExcerptsWrapper').within(() => cy.get('[data-test=placeholder]').should('be.visible'))
})
it('performs an excerpt search', () => {
cy.intercept('GET', '/api/search?q=foo', {
fixture: 'search-excerpts.get.200.json'
})
cy.get('@searchInput').type('foo')
cy.get('#searchExcerptsWrapper').within(() => {
cy.$findInTestId('song-excerpts [data-test=song-card]').should('have.length', 6)
cy.$findInTestId('artist-excerpts [data-test=artist-card]').should('have.length', 1)
cy.$findInTestId('album-excerpts [data-test=album-card]').should('have.length', 3)
})
})
it('has a button to view all matching songs', () => {
cy.intercept('GET', '/api/search?q=foo', {
fixture: 'search-excerpts.get.200.json'
})
cy.intercept('GET', '/api/search/songs?q=foo', {
fixture: 'search-songs.get.200.json'
})
cy.get('@searchInput').type('foo')
cy.get('#searchExcerptsWrapper [data-test=view-all-songs-btn]').click()
cy.url().should('contain', '/#!/search/songs/foo')
cy.get('#songResultsWrapper').within(() => {
cy.get('.screen-header').should('contain.text', 'Showing Songs for foo')
cy.get('tr.song-item').should('have.length', 7)
})
})
it('does not have a View All button if no songs are found', () => {
cy.fixture('search-excerpts.get.200.json').then(data => {
data.results.songs = []
cy.intercept('GET', '/api/search?q=foo', {
statusCode: 200,
body: data
}).as('search')
})
cy.get('@searchInput').type('foo')
cy.wait('@search')
cy.get('#searchExcerptsWrapper [data-test=view-all-songs-btn]').should('not.exist')
cy.findByTestId('song-excerpts').findByText('None found.').should('be.visible')
})
})

@ -1 +1 @@
Subproject commit cb92152218670abe2aa16a80b8e248249b4b8a56
Subproject commit d1ba4b2c17e9cfb81b1e0c00cd2464f5549ea85b