feat: article editor core
This commit is contained in:
1 parent
d493a181e1
commit
a4734b2c91
55 files changed
+4186
-496
No files matched your search
@@ -65,7 +65,10 @@ describe('Nuxt UI shell foundation and router guards', () => {
|
||||
it('The first navigation to a non-public route resolves the session and shows AppBoot meanwhile', async () => {
|
||||
let resolveMe: (value: { verified: boolean }) => void = () => {}
|
||||
const getMe = vi.fn(
|
||||
() => new Promise<{ verified: boolean }>((resolve) => (resolveMe = resolve)),
|
||||
() =>
|
||||
new Promise<{ verified: boolean }>(
|
||||
(resolve) => (resolveMe = resolve),
|
||||
),
|
||||
)
|
||||
vi.mocked(useApi).mockReturnValue({ getMe })
|
||||
setUpSession()
|
||||
@@ -121,7 +124,9 @@ describe('Nuxt UI shell foundation and router guards', () => {
|
||||
await router.push('/article')
|
||||
mountApp()
|
||||
|
||||
await vi.waitFor(() => expect(router.currentRoute.value.path).toBe('/register/pending'))
|
||||
await vi.waitFor(() =>
|
||||
expect(router.currentRoute.value.path).toBe('/register/pending'),
|
||||
)
|
||||
})
|
||||
|
||||
it('A session-only route admits an unverified session', async () => {
|
||||
@@ -196,7 +201,9 @@ describe('Nuxt UI shell foundation and router guards', () => {
|
||||
)
|
||||
expect(app.text()).toContain('Home')
|
||||
|
||||
const primaryButton = app.findAll('button').find((button) => button.text() === 'Try again')
|
||||
const primaryButton = app
|
||||
.findAll('button')
|
||||
.find((button) => button.text() === 'Try again')
|
||||
await primaryButton?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
@@ -212,12 +219,16 @@ describe('Nuxt UI shell foundation and router guards', () => {
|
||||
const app = mountApp()
|
||||
|
||||
await vi.waitFor(() =>
|
||||
expect(app.find('[role="alert"] h1').text()).toBe('Something went wrong'),
|
||||
expect(app.find('[role="alert"] h1').text()).toBe(
|
||||
'Something went wrong',
|
||||
),
|
||||
)
|
||||
|
||||
expect(router.currentRoute.value.path).toBe('/article')
|
||||
|
||||
const primaryButton = app.findAll('button').find((button) => button.text() === 'Try again')
|
||||
const primaryButton = app
|
||||
.findAll('button')
|
||||
.find((button) => button.text() === 'Try again')
|
||||
await primaryButton?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
@@ -240,10 +251,14 @@ describe('Nuxt UI shell foundation and router guards', () => {
|
||||
await flushPromises()
|
||||
|
||||
const headings = app.findAll('h1')
|
||||
expect(headings.some((heading) => heading.text() === title)).toBe(true)
|
||||
expect(headings.some((heading) => heading.text() === title)).toBe(
|
||||
true,
|
||||
)
|
||||
expect(app.find('nav[aria-label="breadcrumb"]').text()).toBe(title)
|
||||
|
||||
const activeLink = app.find(`a[href="${path}"][aria-current="page"]`)
|
||||
const activeLink = app.find(
|
||||
`a[href="${path}"][aria-current="page"]`,
|
||||
)
|
||||
expect(activeLink.exists()).toBe(true)
|
||||
},
|
||||
)
|
||||
|
||||
+13
-3
@@ -11,7 +11,11 @@ export type AuthRequirement = 'public' | 'session' | 'verified' | 'any'
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [
|
||||
{ path: '/', component: () => import('@/views/RootView.vue'), meta: { auth: 'any' } },
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('@/views/RootView.vue'),
|
||||
meta: { auth: 'any' },
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
component: () => import('@/views/LoginView.vue'),
|
||||
@@ -94,7 +98,10 @@ export function resolveAuthRedirect(
|
||||
if (auth === 'any') {
|
||||
return { path: '/login' }
|
||||
}
|
||||
return { path: '/login', query: { redirect: to.fullPath, reason: 'expired' } }
|
||||
return {
|
||||
path: '/login',
|
||||
query: { redirect: to.fullPath, reason: 'expired' },
|
||||
}
|
||||
}
|
||||
|
||||
if (!account.verified) {
|
||||
@@ -141,7 +148,10 @@ router.afterEach((to) => {
|
||||
: Promise.resolve()
|
||||
|
||||
settled.then(() => {
|
||||
const destination = resolveAuthRedirect(router.currentRoute.value, session)
|
||||
const destination = resolveAuthRedirect(
|
||||
router.currentRoute.value,
|
||||
session,
|
||||
)
|
||||
if (destination !== true) {
|
||||
router.replace(destination)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user