diff --git a/tests/e2e/integration/news.spec.js b/tests/e2e/integration/news.spec.js index 7683ac9c..120d30b2 100644 --- a/tests/e2e/integration/news.spec.js +++ b/tests/e2e/integration/news.spec.js @@ -1,39 +1,47 @@ /// +// cy.location api 只能在 history 模式下使用,参考 router/index.ts context('News Music Basic', () => { beforeEach(() => { cy.visit('/') }) it('Automatically jump to the recommended page when music is found', () => { - cy.location().should(loc => { - expect(loc.pathname).to.eq('/music/recommend') - }) + // cy.location().should(loc => { + // expect(loc.pathname).to.eq('/music/recommend') + // }) + cy.hash().should('eq', '#/music/recommend') }) it('Discover music secondary routing test', () => { cy.get('.secondary-bar-link:nth-child(2)').click() - cy.location().should(loc => { - expect(loc.pathname).to.eq('/music/songlist') - expect(loc.search).to.have.string('tag=all') - }) + // cy.location().should(loc => { + // expect(loc.pathname).to.eq('/music/songlist') + // expect(loc.search).to.have.string('tag=all') + // }) + cy.hash().should('match', /^#\/music\/songlist.+tag\=all/) cy.get('.secondary-bar-link:nth-child(3)').click() - cy.location().should(loc => { - expect(loc.pathname).to.eq('/music/toplist') - }) + // cy.location().should(loc => { + // expect(loc.pathname).to.eq('/music/toplist') + // }) + cy.hash().should('have.string', '#/music/toplist') cy.get('.secondary-bar-link:nth-child(4)').click() - cy.location().should(loc => { - expect(loc.pathname).to.eq('/music/artists') - }) + // cy.location().should(loc => { + // expect(loc.pathname).to.eq('/music/artists') + // }) + cy.hash().should('have.string', '#/music/artists') }) it('Jump to playlist', () => { cy.get('.song-list-container:nth-child(2)').click() - cy.location().should(loc => { - expect(loc.pathname).to.have.string('/list/song/') - }) + // cy.location().should(loc => { + // expect(loc.pathname).to.have.string('/list/song/') + // }) + cy.hash().should('have.string', '#/list/song') + + // rule album cy.get('.bg-img img') .invoke('attr', 'src') .then(src => { @@ -46,7 +54,8 @@ context('News Music Basic', () => { }) it('Fine playlist filtering', () => { - cy.visit('/music/songlist?tag=all') + // cy.visit('/music/songlist?tag=all') + cy.visit('/#/music/songlist?tag=all') cy.get('.song-list') .children() .should('have.length.greaterThan', 0) @@ -59,7 +68,8 @@ context('News Music Basic', () => { }) it('Singer filter', () => { - cy.visit('/music/artists') + // cy.visit('/music/artists') + cy.visit('/#/music/artists') cy.get('.artists-content ul') .children() .should('have.length.greaterThan', 0) @@ -78,43 +88,51 @@ context('News Music Basic', () => { }) it('Singer details', () => { - cy.visit('/music/artists') + // cy.visit('/music/artists') + cy.visit('/#/music/artists') cy.get('.artists-content li:first-child').click() - cy.location().should(loc => { - expect(loc.pathname).to.match(/artist\/\d+\/album/) - }) + // cy.location().should(loc => { + // expect(loc.pathname).to.match(/artist\/\d+\/album/) + // }) + cy.hash().should('match', /#\/artist\/\d+\/album/) cy.contains('.secondary-bar-link-active', '专辑') }) - // it('Double click to play the song', () => { - // cy.visit('/music/toplist') - - // // https://github.com/cypress-io/cypress/issues/14269 - // // Found it is a cache problem - // // Solution: Use a timestamp to ensure that the URL cannot hit the browser cache - // cy.intercept(/\/api\/song\/url/).as('getUrl') - // cy.intercept(/\/api\/song\/detail/).as('getDetail') - // cy.intercept(/\/api\/lyric/).as('getLyric') - // cy.get( - // '.toplist-expansion-contanier:first-child .none-select:first-child' - // ).dblclick() - - // cy.wait(['@getUrl', '@getDetail', '@getLyric'], { - // requestTimeout: 20 * 1000 - // }).then(() => { - // // Possibly due to insufficient performance in the ci automatic test - // cy.wait(1000).then(() => { - // cy.get('source') - // .invoke('attr', 'src') - // .then(src => { - // expect(src).to.have.string('.mp3') - // }) - - // // pause music - // cy.get('.music-command-group button:nth-child(3)').click() - // }) - // }) - // }) + it('Double click to play the song', () => { + // cy.visit('/music/toplist') + cy.visit('/#/music/toplist') + + // https://github.com/cypress-io/cypress/issues/14269 + // Found it is a cache problem + // Solution: Use a timestamp to ensure that the URL cannot hit the browser cache + cy.intercept(/\/api\/song\/url/).as('getUrl') + cy.intercept(/\/api\/song\/detail/).as('getDetail') + cy.intercept(/\/api\/lyric/).as('getLyric') + cy.get( + '.toplist-expansion-contanier:first-child .none-select:first-child' + ).dblclick() + + cy.wait(['@getUrl', '@getDetail', '@getLyric'], { + requestTimeout: 20 * 1000 + }).then(() => { + // Possibly due to insufficient performance in the ci automatic test + cy.wait(1000).then(() => { + cy.get('audio') + .invoke('attr', 'src') + .then(src => { + expect(src).to.have.string('.mp3') + }) + + // pause music + const playPauesBtn = cy.get('.music-command-group button:nth-child(3)') + playPauesBtn.click() + playPauesBtn + .find('use') + .invoke('attr', 'href') + .then(icon => expect(icon).to.have.string('#icon-play')) + }) + }) + }) })