-
-
Notifications
You must be signed in to change notification settings - Fork 526
docs(ui): add stories for Profile page #3209
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wingkwong
wants to merge
3
commits into
npmx-dev:main
Choose a base branch
from
wingkwong:docs/profile-storybook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import Profile from './index.vue' | ||
| import type { Meta, StoryObj } from '@storybook-vue/nuxt' | ||
| import { expect, userEvent } from 'storybook/test' | ||
| import { pageDecorator } from '../../../../.storybook/decorators' | ||
| import { | ||
| mockAuthSessionHandler, | ||
| mockPackageLikesHandler, | ||
| mockProfile, | ||
| mockProfileHandle, | ||
| mockProfileHandler, | ||
| mockProfileLikesHandler, | ||
| mockUpdateProfileHandler, | ||
| } from '../../../storybook/mocks/handlers/profile' | ||
| import { renderPageAt } from '../../../storybook/render-page' | ||
|
|
||
| const PROFILE_PATH = `/profile/${mockProfileHandle}` | ||
|
|
||
| const meta = { | ||
| component: Profile, | ||
|
|
||
| render: renderPageAt(Profile, PROFILE_PATH), | ||
|
|
||
| beforeEach({ msw }) { | ||
| msw.use( | ||
| mockProfileHandler(), | ||
| mockProfileLikesHandler(), | ||
| mockPackageLikesHandler, | ||
| mockAuthSessionHandler(), | ||
| mockUpdateProfileHandler, | ||
| ) | ||
| }, | ||
|
|
||
| parameters: { | ||
| layout: 'fullscreen', | ||
| }, | ||
|
|
||
| decorators: [pageDecorator], | ||
| } satisfies Meta<typeof Profile> | ||
|
|
||
| export default meta | ||
| type Story = StoryObj<typeof meta> | ||
|
|
||
| /** Public profile with profile metadata and several liked packages. */ | ||
| export const Default: Story = {} | ||
|
|
||
| /** Authenticated as the profile owner so the edit action is available. */ | ||
| export const Owner: Story = { | ||
| beforeEach({ msw }) { | ||
| msw.use(mockAuthSessionHandler(mockProfileHandle)) | ||
| }, | ||
| } | ||
|
|
||
| /** Owner profile with the edit form opened and its editable controls visible. */ | ||
| export const Editing: Story = { | ||
| ...Owner, | ||
| play: async ({ canvas }) => { | ||
| await userEvent.click(await canvas.findByRole('button', { name: /edit/i })) | ||
|
|
||
| await expect(canvas.getByText(/display name/i)).toBeVisible() | ||
| await expect(await canvas.findByDisplayValue(mockProfile.displayName)).toBeVisible() | ||
| await expect(canvas.getByText(/description/i)).toBeVisible() | ||
| await expect(canvas.getByDisplayValue(mockProfile.description ?? '')).toBeVisible() | ||
| await expect(canvas.getByText(/website/i)).toBeVisible() | ||
| await expect(canvas.getByDisplayValue(mockProfile.website ?? '')).toBeVisible() | ||
| await expect(canvas.getByRole('button', { name: /cancel/i })).toBeVisible() | ||
| await expect(canvas.getByRole('button', { name: /save/i })).toBeVisible() | ||
| }, | ||
| } | ||
|
|
||
| /** Missing npmx profile record with no likes; authenticated as another user so the invite section appears. */ | ||
| export const Invite: Story = { | ||
| beforeEach({ msw }) { | ||
| msw.use( | ||
| mockProfileHandler({ recordExists: false }), | ||
| mockProfileLikesHandler([]), | ||
| mockAuthSessionHandler('other-user.test'), | ||
| ) | ||
| }, | ||
| } | ||
|
|
||
| /** Existing profile with no liked packages and no invite section. */ | ||
| export const WithoutLikes: Story = { | ||
| beforeEach({ msw }) { | ||
| msw.use(mockProfileLikesHandler([])) | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { http, HttpResponse } from 'msw' | ||
| import type { NPMXProfile, PackageLikes } from '#shared/types/social' | ||
|
|
||
| export const mockProfileHandle = 'mock-steward' | ||
|
|
||
| export const mockProfile: NPMXProfile = { | ||
| displayName: mockProfileHandle, | ||
| description: 'Maintains small tools for package metadata, docs, and release workflows.', | ||
| website: `https://github.com/${mockProfileHandle}`, | ||
| handle: mockProfileHandle, | ||
| recordExists: true, | ||
| } | ||
|
|
||
| export const mockLikedPackages = [ | ||
| 'https://npmx.dev/package/nuxt', | ||
| 'https://npmx.dev/package/vitest', | ||
| ] | ||
|
|
||
| export function createMockAuthSession(handle: string) { | ||
| return { | ||
| did: `did:plc:${handle}`, | ||
| handle, | ||
| pds: 'https://bsky.social', | ||
| } | ||
| } | ||
|
|
||
| export function mockProfileHandler(overrides: Partial<NPMXProfile> = {}) { | ||
| return http.get(`/api/social/profile/${mockProfileHandle}`, () => | ||
| HttpResponse.json({ | ||
| ...mockProfile, | ||
| ...overrides, | ||
| }), | ||
| ) | ||
| } | ||
|
|
||
| export function mockProfileLikesHandler(likes = mockLikedPackages) { | ||
| return http.get(`/api/social/profile/${mockProfileHandle}/likes`, () => | ||
| HttpResponse.json({ | ||
| cursor: null, | ||
| likes, | ||
| }), | ||
| ) | ||
| } | ||
|
|
||
| export const mockPackageLikesHandler = http.get('/api/social/likes/:pkg', ({ params }) => { | ||
| const pkg = String(params.pkg) | ||
| const response: PackageLikes = { | ||
| totalLikes: | ||
| { | ||
| nuxt: 128, | ||
| vitest: 96, | ||
| }[pkg] ?? 12, | ||
| userHasLiked: false, | ||
| topLikedRank: null, | ||
| } | ||
|
|
||
| return HttpResponse.json(response) | ||
| }) | ||
|
|
||
| export function mockAuthSessionHandler(handle: string | null = null) { | ||
| return http.get('/api/auth/session', () => | ||
| HttpResponse.json(handle ? createMockAuthSession(handle) : null), | ||
| ) | ||
| } | ||
|
|
||
| export const mockUpdateProfileHandler = http.put(`/api/social/profile/${mockProfileHandle}`, () => | ||
| HttpResponse.text('ok'), | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { clearNuxtData, useRouter } from '#app' | ||
| import { PageRouteSymbol } from '#app/components/injections' | ||
| import { h, provide, shallowReactive, Suspense } from 'vue' | ||
| import type { Component } from 'vue' | ||
| import type { RouteLocationRaw } from 'vue-router' | ||
|
|
||
| export function renderPageAt(component: Component, path: RouteLocationRaw) { | ||
| return () => ({ | ||
| setup() { | ||
| clearNuxtData() | ||
|
|
||
| const router = useRouter() | ||
| const routeForStory = shallowReactive(router.resolve(path)) | ||
| provide(PageRouteSymbol, routeForStory) | ||
|
|
||
| if (router.currentRoute.value.fullPath !== routeForStory.fullPath) { | ||
| router.replace(path).catch(() => {}) | ||
| } | ||
|
|
||
| return () => | ||
| h(Suspense, null, { | ||
| default: () => h(component), | ||
| }) | ||
| }, | ||
| }) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.