From d193bfb1b4b415c6dd875e492e664676689908aa Mon Sep 17 00:00:00 2001 From: Riceball <42161586+riceball-tw@users.noreply.github.com> Date: Sat, 15 Jun 2024 13:46:45 +0800 Subject: [PATCH] test: basic post e2e (#77) * feat: Add data attribute for post e2e * feat: Add basic post e2e * fix: Type Error * fix: Syntax error --- cypress/e2e/post/post.cy.ts | 29 ++++++++++++++++++++++------- src/components/app/Utteranc.astro | 2 +- src/components/post/TagsList.astro | 4 ++-- src/pages/post/[...slug].astro | 1 + 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/cypress/e2e/post/post.cy.ts b/cypress/e2e/post/post.cy.ts index 3e32ce6c..9ecd921b 100644 --- a/cypress/e2e/post/post.cy.ts +++ b/cypress/e2e/post/post.cy.ts @@ -1,16 +1,31 @@ describe('Post is effective', () => { - it('Page is effective', () => { - cy.visit('/post/demo-post', { failOnStatusCode: false }); + beforeEach(() => { + cy.visit('/post/demo-post'); + }); - // Post Header + it('Header should visible and working', () => { cy.dataCy('post-icon-container').find('svg').should('exist'); cy.dataCy('post-title').should('have.prop', 'tagName', 'H1').should('not.be.empty'); cy.dataCy('post-subtitle').should('not.be.empty'); cy.dataCy('category').should('not.be.empty'); - cy.dataCy('tags') - .find('[data-cy=tag]') - .each(($tag) => { - cy.wrap($tag).should('not.be.empty'); + cy.dataCy('tag-link').each(($link) => { + cy.wrap($link).should('not.be.empty'); + cy.request('GET', $link.attr('href')).its('status').should('eq', 200); + }); + }); + + it('Comment should load', () => { + cy.dataCy('post-comment').scrollIntoView(); + cy.dataCy('post-comment').should('not.be.empty'); + }); + + it('Heading links should visible and working', () => { + cy.dataCy('post-content') + .find( + 'h2 .rehype-auto-link, h3 .rehype-auto-link, h4 .rehype-auto-link, h5 .rehype-auto-link, h6 .rehype-auto-link', + ) + .each(($link) => { + cy.request('GET', $link.attr('href')).its('status').should('eq', 200); }); }); }); diff --git a/src/components/app/Utteranc.astro b/src/components/app/Utteranc.astro index 53b5ede2..6e8d1bb5 100644 --- a/src/components/app/Utteranc.astro +++ b/src/components/app/Utteranc.astro @@ -1,4 +1,4 @@ -
+