koel/cypress/integration/searching.spec.ts

61 lines
2 KiB
TypeScript
Raw Normal View History

2021-01-04 16:42:21 +00:00
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.findByTestId('screen-empty-state').should('be.visible'))
2021-01-04 16:42:21 +00:00
})
it('performs an excerpt search', () => {
2021-05-23 11:42:18 +00:00
cy.intercept('/api/search?q=foo', {
2021-01-04 16:42:21 +00:00
fixture: 'search-excerpts.get.200.json'
})
cy.get('@searchInput').type('foo')
cy.get('#searchExcerptsWrapper').within(() => {
cy.$findInTestId('song-excerpts [data-testid=song-card]').should('have.length', 6)
cy.$findInTestId('artist-excerpts [data-testid=artist-card]').should('have.length', 1)
cy.$findInTestId('album-excerpts [data-testid=album-card]').should('have.length', 3)
2021-01-04 16:42:21 +00:00
})
})
it('has a button to view all matching songs', () => {
2021-05-23 11:42:18 +00:00
cy.intercept('/api/search?q=foo', {
2021-01-04 16:42:21 +00:00
fixture: 'search-excerpts.get.200.json'
})
2021-05-23 11:42:18 +00:00
cy.intercept('/api/search/songs?q=foo', {
2021-01-04 16:42:21 +00:00
fixture: 'search-songs.get.200.json'
})
cy.get('@searchInput').type('foo')
cy.get('#searchExcerptsWrapper [data-testid=view-all-songs-btn]').click()
2021-01-04 16:42:21 +00:00
cy.url().should('contain', '/#!/search/songs/foo')
cy.get('#songResultsWrapper').within(() => {
cy.get('.screen-header').should('contain.text', 'Showing Songs for foo')
2022-04-26 09:46:31 +00:00
cy.get('.song-item').should('have.length', 7)
2021-01-04 16:42:21 +00:00
})
})
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 = []
2021-05-23 11:42:18 +00:00
cy.intercept('/api/search?q=foo', {
2021-01-04 16:42:21 +00:00
statusCode: 200,
body: data
}).as('search')
})
cy.get('@searchInput').type('foo')
cy.wait('@search')
cy.get('#searchExcerptsWrapper [data-testid=view-all-songs-btn]').should('not.exist')
2021-01-04 16:42:21 +00:00
cy.findByTestId('song-excerpts').findByText('None found.').should('be.visible')
})
})