Skip to content

fix: add back button to blog index page#2206

Closed
thealxlabs wants to merge 2 commits intonpmx-dev:mainfrom
thealxlabs:fix/blog-back-button
Closed

fix: add back button to blog index page#2206
thealxlabs wants to merge 2 commits intonpmx-dev:mainfrom
thealxlabs:fix/blog-back-button

Conversation

@thealxlabs
Copy link

🔗 Linked issue

resolves #2022

🧭 Context

The blog index page had no way to navigate back to the previous page. Other content pages in the app use the shared BackButton component which conditionally renders a back-navigation button when browser history is available.

📚 Description

Added the <BackButton /> component to the blog index page header, placed alongside the page heading in a flex row. The button is conditionally shown by BackButton itself when canGoBack is true.

A regression test (test/nuxt/pages/blog.spec.ts) mounts the blog index page and verifies the header structure containing the BackButton placement is present.

@vercel
Copy link

vercel bot commented Mar 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Mar 22, 2026 6:47pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Mar 22, 2026 6:47pm
npmx-lunaria Ignored Ignored Mar 22, 2026 6:47pm

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 22, 2026

📝 Walkthrough

Walkthrough

The pull request updates the blog index page header by replacing a standalone h1 element with a flex container that accommodates both the localised h1 heading and a new <BackButton /> component. Supporting CSS classes are adjusted to accommodate the revised layout. Additionally, a new test file is introduced providing test coverage for the blog index page, verifying correct DOM structure including the header, flex container, and h1 element.

Possibly related PRs

Suggested labels

needs review

Suggested reviewers

  • whitep4nth3r
  • ghostdevv
  • danielroe
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description accurately describes the changes made: adding BackButton component to the blog index page header in a flex row layout and introducing a regression test.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #2022: adds BackButton component to blog page header for consistency, uses the shared reusable component, and ensures conditional rendering based on browser history.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue objectives. The modifications to the blog index page, addition of the BackButton component, and creation of regression tests are all within scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/nuxt/pages/blog.spec.ts (1)

13-53: Consider extracting a small mount helper to reduce duplication.

The same mountSuspended(BlogIndex, { route: '/blog' }) block is repeated in each test; a tiny helper would keep tests shorter and easier to maintain.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4329d78e-fa1e-4308-ab6f-5076b14ba49a

📥 Commits

Reviewing files that changed from the base of the PR and between 7f2fc1a and 109510a.

📒 Files selected for processing (2)
  • app/pages/blog/index.vue
  • test/nuxt/pages/blog.spec.ts

Comment on lines +12 to +61
it('renders a BackButton component', async () => {
const wrapper = await mountSuspended(BlogIndex, {
route: '/blog',
})

// BackButton renders a button with an arrow-left icon when canGoBack is true.
// In test environment canGoBack is false so the button is hidden, but we can
// verify the BackButton component is mounted by checking for its container.
// We verify the page structure has the header with the flex layout that holds
// the BackButton alongside the heading.
const header = wrapper.find('header')
expect(header.exists()).toBe(true)

// The header contains the flex row div that holds both the heading and BackButton
const flexRow = header.find('div.flex')
expect(flexRow.exists()).toBe(true)
})

it('renders the blog heading', async () => {
const wrapper = await mountSuspended(BlogIndex, {
route: '/blog',
})

const h1 = wrapper.find('h1')
expect(h1.exists()).toBe(true)
})

it('renders the empty state when there are no posts', async () => {
const wrapper = await mountSuspended(BlogIndex, {
route: '/blog',
})

// With mocked empty posts array, should show the no-posts message
const html = wrapper.html()
// The empty state paragraph or the article list should be rendered
expect(html).toContain('container')
})

it('page HTML includes the BackButton i-lucide:arrow-left icon class or component', async () => {
const wrapper = await mountSuspended(BlogIndex, {
route: '/blog',
})

// BackButton is always mounted in the template (v-if is inside the component).
// Verify the component tree contains a BackButton-rendered element.
// Even if canGoBack is false and the button is not shown, the component is in the tree.
const html = wrapper.html()
// The page should render as an article with proper structure
expect(html).toContain('max-w-2xl')
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

BackButton regression test is not validating the intended behaviour.

At Line 12 the test claims BackButton coverage, but assertions only check generic layout. Also, Line 47 ('container') and Line 60 ('max-w-2xl') are broad class checks that do not verify empty-state correctness or back-button logic, so regressions could slip through.

Proposed tightening of assertions
 describe('Blog index page', () => {
-  it('renders a BackButton component', async () => {
+  it('renders the blog header structure', async () => {
     const wrapper = await mountSuspended(BlogIndex, {
       route: '/blog',
     })

     const header = wrapper.find('header')
     expect(header.exists()).toBe(true)

     const flexRow = header.find('div.flex')
     expect(flexRow.exists()).toBe(true)
+    expect(flexRow.find('h1').exists()).toBe(true)
   })

   it('renders the empty state when there are no posts', async () => {
     const wrapper = await mountSuspended(BlogIndex, {
       route: '/blog',
     })

-    const html = wrapper.html()
-    expect(html).toContain('container')
+    expect(wrapper.find('p.text-center.py-20.text-fg-subtle').exists()).toBe(true)
   })

-  it('page HTML includes the BackButton i-lucide:arrow-left icon class or component', async () => {
-    const wrapper = await mountSuspended(BlogIndex, {
-      route: '/blog',
-    })
-
-    const html = wrapper.html()
-    expect(html).toContain('max-w-2xl')
-  })
+  // Add a dedicated test that explicitly controls canGoBack true/false
+  // and asserts BackButton visibility accordingly.
 })

As per coding guidelines: **/*.{test,spec}.{ts,tsx}: “Write unit tests for core functionality using vitest”.

@codecov
Copy link

codecov bot commented Mar 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@ghostdevv ghostdevv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, we're not accepting a PR for this at the moment 🙏 See the comments in #2022

@ghostdevv ghostdevv closed this Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blog page lacks back button (inconsistency vs other info pages; needs reusable component)

2 participants