-
-
Notifications
You must be signed in to change notification settings - Fork 424
fix(ui): don't show state before profile/likes finish loading #1910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,4 +44,23 @@ describe('PackageLikeCard', () => { | |
|
|
||
| expect(wrapper.find('span.truncate').text()).toBe('@scope/pkg') | ||
| }) | ||
|
|
||
| it('shows a loading skeleton instead of zero while like data is pending', async () => { | ||
| wrapper = await mountLikeCard('https://npmx.dev/package/vue') | ||
|
|
||
| const button = wrapper.find('button') | ||
| expect(button.text()).not.toContain('0') | ||
|
|
||
| const skeleton = button.find('.animate-pulse') | ||
| expect(skeleton.exists()).toBe(true) | ||
| }) | ||
|
|
||
| it('shows a neutral heart icon while like data is pending', async () => { | ||
| wrapper = await mountLikeCard('https://npmx.dev/package/vue') | ||
|
|
||
| const icon = wrapper.find('button span[aria-hidden]') | ||
| expect(icon.classes()).toContain('i-lucide-heart') | ||
| expect(icon.classes()).not.toContain('i-lucide-heart-plus') | ||
| expect(icon.classes()).not.toContain('i-lucide-heart-minus') | ||
| }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Read the full spec file to understand setup and mocking
cat -n test/nuxt/components/PackageLikeCard.spec.ts
# Also search for any mock or endpoint setup patterns
rg -n "registerEndpoint|mockNuxtImport|useFakeTimers|setTimeout|new Promise|beforeEach|vi\." test/nuxt/components/PackageLikeCard.spec.ts || echo "No timing control patterns found"Repository: npmx-dev/npmx.dev Length of output: 2780 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Find and read the LikeCard component
find . -name "LikeCard.vue" -type f | head -5Repository: npmx-dev/npmx.dev Length of output: 98 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Read the LikeCard component
cat -n ~/components/Package/LikeCard.vue 2>/dev/null || cat -n src/components/Package/LikeCard.vue 2>/dev/null || find . -path "*components/Package/LikeCard.vue" -exec cat -n {} \;Repository: npmx-dev/npmx.dev Length of output: 4465 Control fetch timing to stabilise pending-state assertions. The tests at lines 48–65 check pending-state UI (skeleton, neutral heart icon) immediately after mount. However, Introduce a deliberate delay in the endpoint response using Stabilisation example+import { registerEndpoint } from '@nuxt/test-utils/runtime'
+
+registerEndpoint('/api/social/likes/vue', async () => {
+ await new Promise(resolve => setTimeout(resolve, 50))
+ return { totalLikes: 12, userHasLiked: false }
+}) |
||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { mockNuxtImport, mountSuspended, registerEndpoint } from '@nuxt/test-utils/runtime' | ||
| import { describe, expect, it, vi, beforeEach } from 'vitest' | ||
|
|
||
| const { mockUseAtproto, mockUseProfileLikes } = vi.hoisted(() => ({ | ||
| mockUseAtproto: vi.fn(), | ||
| mockUseProfileLikes: vi.fn(), | ||
| })) | ||
|
|
||
| mockNuxtImport('useAtproto', () => mockUseAtproto) | ||
| mockNuxtImport('useProfileLikes', () => mockUseProfileLikes) | ||
|
|
||
| import ProfilePage from '~/pages/profile/[identity]/index.vue' | ||
|
|
||
| registerEndpoint('/api/social/profile/test-handle', () => ({ | ||
| displayName: 'Test User', | ||
| description: '', | ||
| website: '', | ||
| handle: 'test-handle', | ||
| recordExists: false, | ||
| })) | ||
|
|
||
| describe('Profile invite section', () => { | ||
| beforeEach(() => { | ||
| mockUseAtproto.mockReset() | ||
| mockUseProfileLikes.mockReset() | ||
| }) | ||
|
|
||
| it('does not show invite section while auth is still loading', async () => { | ||
| mockUseAtproto.mockReturnValue({ | ||
| user: ref(null), | ||
| pending: ref(true), | ||
| logout: vi.fn(), | ||
| }) | ||
|
|
||
| mockUseProfileLikes.mockReturnValue({ | ||
| data: ref({ records: [] }), | ||
| status: ref('success'), | ||
| }) | ||
|
|
||
| const wrapper = await mountSuspended(ProfilePage, { | ||
| route: '/profile/test-handle', | ||
| }) | ||
|
|
||
| expect(wrapper.text()).not.toContain("It doesn't look like they're using npmx yet") | ||
| }) | ||
|
|
||
| it('shows invite section after auth resolves for non-owner', async () => { | ||
| mockUseAtproto.mockReturnValue({ | ||
| user: ref({ handle: 'other-user' }), | ||
| pending: ref(false), | ||
| logout: vi.fn(), | ||
| }) | ||
|
|
||
| mockUseProfileLikes.mockReturnValue({ | ||
| data: ref({ records: [] }), | ||
| status: ref('success'), | ||
| }) | ||
|
|
||
| const wrapper = await mountSuspended(ProfilePage, { | ||
| route: '/profile/test-handle', | ||
| }) | ||
|
|
||
| expect(wrapper.text()).toContain("It doesn't look like they're using npmx yet") | ||
| }) | ||
|
|
||
| it('does not show invite section for profile owner', async () => { | ||
| mockUseAtproto.mockReturnValue({ | ||
| user: ref({ handle: 'test-handle' }), | ||
| pending: ref(false), | ||
| logout: vi.fn(), | ||
| }) | ||
|
|
||
| mockUseProfileLikes.mockReturnValue({ | ||
| data: ref({ records: [] }), | ||
| status: ref('success'), | ||
| }) | ||
|
|
||
| const wrapper = await mountSuspended(ProfilePage, { | ||
| route: '/profile/test-handle', | ||
| }) | ||
|
|
||
| expect(wrapper.text()).not.toContain("It doesn't look like they're using npmx yet") | ||
| }) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
rg -n "likesStatus|isLikeActionPending|likeAction|:disabled|aria-busy" app/components/Package/LikeCard.vue -C3Repository: npmx-dev/npmx.dev
Length of output: 2014
Prevent user interactions whilst initial likes data is still pending.
The UI displays a pending indicator but does not block the button. Users can click during the loading window, and
likeActionwill use default fallback values to compute the state change, risking incorrect optimistic updates based on uninitialised data.The
likeActionfunction only guardsisLikeActionPending(line 33) but does not check whetherlikesStatusis pending. Additionally, the button lacks both:disabledand:aria-busyattributes to reflect the pending state.Suggested fix
const likeAction = async () => { if (user.value?.handle == null) { authModal.open() return } - if (isLikeActionPending.value) return + if (likesStatus.value === 'pending' || isLikeActionPending.value) return<button `@click.prevent`="likeAction" type="button" + :disabled="likesStatus === 'pending' || isLikeActionPending" + :aria-busy="likesStatus === 'pending'" :title=" likesData?.userHasLiked ? $t('package.likes.unlike') : $t('package.likes.like') "