style: update eslint rules
This commit is contained in:
parent
6d528ff2b8
commit
703a001fce
24
.eslintrc.js
24
.eslintrc.js
|
|
@ -6,27 +6,5 @@ module.exports = {
|
|||
sourceType: 'module',
|
||||
extraFileExtensions: ['.vue'],
|
||||
},
|
||||
extends: [
|
||||
'@mutoe/eslint-config-preset-vue',
|
||||
],
|
||||
rules: {
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['src/composable/*.ts', 'src/**/use*.ts'],
|
||||
rules: {
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: [
|
||||
'src/**/*.{cy,spec}.{js,ts,jsx,tsx}',
|
||||
],
|
||||
extends: [
|
||||
'plugin:cypress/recommended',
|
||||
'plugin:chai-friendly/recommended',
|
||||
],
|
||||
},
|
||||
],
|
||||
extends: '@mutoe/eslint-config-preset-vue',
|
||||
}
|
||||
|
|
|
|||
10
package.json
10
package.json
|
|
@ -26,7 +26,7 @@
|
|||
"vue-router": "^4.2.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@mutoe/eslint-config-preset-vue": "~2.1.2",
|
||||
"@mutoe/eslint-config-preset-vue": "~3.5.3",
|
||||
"@pinia/testing": "^0.1.3",
|
||||
"@testing-library/cypress": "^9.0.0",
|
||||
"@testing-library/user-event": "^14.4.3",
|
||||
|
|
@ -35,8 +35,7 @@
|
|||
"@vitest/coverage-v8": "^0.34.3",
|
||||
"concurrently": "^7.6.0",
|
||||
"cypress": "^13.1.0",
|
||||
"eslint": "^8.31.0",
|
||||
"eslint-plugin-chai-friendly": "^0.7.2",
|
||||
"eslint": "^8.48.0",
|
||||
"eslint-plugin-cypress": "^2.14.0",
|
||||
"happy-dom": "^11.0.2",
|
||||
"husky": "^8.0.2",
|
||||
|
|
@ -50,11 +49,6 @@
|
|||
"vitest-dom": "^0.1.0",
|
||||
"vue-tsc": "^1.8.8"
|
||||
},
|
||||
"overrides": {
|
||||
"@testing-library/cypress": {
|
||||
"cypress": "^13"
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
"src/**/*.{ts,vue,js}": "eslint --fix",
|
||||
"cypress/**/*.{ts,js}": "eslint --fix"
|
||||
|
|
|
|||
952
pnpm-lock.yaml
952
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
|
@ -1,5 +1,5 @@
|
|||
import { render } from '@testing-library/vue'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { renderOptions } from 'src/utils/test/test.utils'
|
||||
import AppFooter from './AppFooter.vue'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { fireEvent, render, waitFor } from '@testing-library/vue'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { renderOptions } from 'src/utils/test/test.utils.ts'
|
||||
import AppLink from './AppLink.vue'
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { AppRouteNames } from 'src/router'
|
||||
import type { RouteParams } from 'vue-router'
|
||||
import type { AppRouteNames } from 'src/router'
|
||||
|
||||
export interface AppLinkProps {
|
||||
name: AppRouteNames
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { render } from '@testing-library/vue'
|
||||
import { expect, describe, it } from 'vitest'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { renderOptions } from 'src/utils/test/test.utils.ts'
|
||||
import AppNavigation from './AppNavigation.vue'
|
||||
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import type { RouteParams } from 'vue-router'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import type { AppRouteNames } from 'src/router'
|
||||
import { useUserStore } from 'src/store/user'
|
||||
import { computed } from 'vue'
|
||||
import type { RouteParams } from 'vue-router'
|
||||
|
||||
interface NavLink {
|
||||
name: AppRouteNames
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { fireEvent, render } from '@testing-library/vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { renderOptions } from 'src/utils/test/test.utils.ts'
|
||||
import { describe, it, vi, expect } from 'vitest'
|
||||
import AppPagination from './AppPagination.vue'
|
||||
|
||||
describe('# AppPagination', () => {
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { limit } from 'src/services'
|
||||
import { computed, toRefs } from 'vue'
|
||||
import { limit } from 'src/services'
|
||||
|
||||
interface Props {
|
||||
page: number
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { render } from '@testing-library/vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import fixtures from 'src/utils/test/fixtures'
|
||||
import { asyncWrapper, renderOptions, setupMockServer } from 'src/utils/test/test.utils'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import ArticleDetail from './ArticleDetail.vue'
|
||||
|
||||
describe('# ArticleDetail', () => {
|
||||
|
|
|
|||
|
|
@ -13,14 +13,11 @@
|
|||
|
||||
<div class="container page">
|
||||
<div class="row article-content">
|
||||
<!-- eslint-disable vue/no-v-html -->
|
||||
<div
|
||||
class="col-md-12"
|
||||
v-html="articleHandledBody"
|
||||
/>
|
||||
<!-- eslint-enable vue/no-v-html -->
|
||||
<!-- eslint-disable vue/no-v-html -->
|
||||
<div class="col-md-12" v-html="articleHandledBody" />
|
||||
<!-- eslint-enable vue/no-v-html -->
|
||||
|
||||
<!-- TODO: abstract tag list component-->
|
||||
<!-- TODO: abstract tag list component -->
|
||||
<ul class="tag-list">
|
||||
<li
|
||||
v-for="tag in article.tagList"
|
||||
|
|
@ -45,11 +42,11 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import marked from 'src/plugins/marked'
|
||||
import { api } from 'src/services'
|
||||
import type { Article } from 'src/services/api'
|
||||
import { computed, reactive } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import ArticleDetailMeta from './ArticleDetailMeta.vue'
|
||||
|
||||
const route = useRoute()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { fireEvent, render } from '@testing-library/vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import fixtures from 'src/utils/test/fixtures'
|
||||
import { renderOptions } from 'src/utils/test/test.utils.ts'
|
||||
import { vi, describe, it, expect } from 'vitest'
|
||||
import ArticleDetailComment from './ArticleDetailComment.vue'
|
||||
|
||||
describe('# ArticleDetailComment', () => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { fireEvent, render } from '@testing-library/vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import fixtures from 'src/utils/test/fixtures'
|
||||
import { asyncWrapper, renderOptions, setupMockServer } from 'src/utils/test/test.utils'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import ArticleDetailComments from './ArticleDetailComments.vue'
|
||||
|
||||
describe('# ArticleDetailComments', () => {
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { api } from 'src/services'
|
||||
import type { Comment } from 'src/services/api'
|
||||
import { useUserStore } from 'src/store/user'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import ArticleDetailComment from './ArticleDetailComment.vue'
|
||||
import ArticleDetailCommentsForm from './ArticleDetailCommentsForm.vue'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { fireEvent, render } from '@testing-library/vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import ArticleDetailCommentsForm from 'src/components/ArticleDetailCommentsForm.vue'
|
||||
import fixtures from 'src/utils/test/fixtures'
|
||||
import { renderOptions, setupMockServer } from 'src/utils/test/test.utils.ts'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
describe('# ArticleDetailCommentsForm', () => {
|
||||
const server = setupMockServer(
|
||||
|
|
|
|||
|
|
@ -39,12 +39,12 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useProfile } from 'src/composable/useProfile'
|
||||
import { api } from 'src/services'
|
||||
import { useUserStore } from 'src/store/user'
|
||||
import { computed, ref } from 'vue'
|
||||
import type { Comment } from 'src/services/api'
|
||||
import { useUserStore } from 'src/store/user'
|
||||
|
||||
interface Props {
|
||||
articleSlug: string
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { fireEvent, render } from '@testing-library/vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { Profile } from 'src/services/api'
|
||||
import fixtures from 'src/utils/test/fixtures'
|
||||
import { renderOptions, setupMockServer } from 'src/utils/test/test.utils.ts'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import ArticleDetailMeta from './ArticleDetailMeta.vue'
|
||||
|
||||
const editButton = 'Edit article'
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, toRefs } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useFavoriteArticle } from 'src/composable/useFavoriteArticle'
|
||||
import { useFollow } from 'src/composable/useFollowProfile'
|
||||
|
|
@ -71,7 +72,6 @@ import { routerPush } from 'src/router'
|
|||
import { api } from 'src/services'
|
||||
import type { Article, Profile } from 'src/services/api'
|
||||
import { useUserStore } from 'src/store/user'
|
||||
import { computed, toRefs } from 'vue'
|
||||
|
||||
interface Props {
|
||||
article: Article
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { render } from '@testing-library/vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import fixtures from 'src/utils/test/fixtures'
|
||||
import { asyncWrapper, renderOptions, setupMockServer } from 'src/utils/test/test.utils'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import ArticlesList from './ArticlesList.vue'
|
||||
|
||||
describe('# ArticlesList', () => {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { fireEvent, render } from '@testing-library/vue'
|
||||
import { describe, it } from 'vitest'
|
||||
import ArticlesListArticlePreview from 'src/components/ArticlesListArticlePreview.vue'
|
||||
import fixtures from 'src/utils/test/fixtures'
|
||||
import { renderOptions, setupMockServer } from 'src/utils/test/test.utils.ts'
|
||||
import { describe, it } from 'vitest'
|
||||
|
||||
const favoriteButton = 'Favorite article'
|
||||
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useFavoriteArticle } from 'src/composable/useFavoriteArticle'
|
||||
import type { Article } from 'src/services/api'
|
||||
import { computed } from 'vue'
|
||||
|
||||
interface Props {
|
||||
article: Article
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { render } from '@testing-library/vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import ArticlesListNavigation from 'src/components/ArticlesListNavigation.vue'
|
||||
import fixtures from 'src/utils/test/fixtures'
|
||||
import { renderOptions } from 'src/utils/test/test.utils.ts'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
describe('# ArticlesListNavigation', () => {
|
||||
it('should render global feed item when passed global feed prop', () => {
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import type { RouteParams } from 'vue-router'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import type { ArticlesType } from 'src/composable/useArticles'
|
||||
import type { AppRouteNames } from 'src/router'
|
||||
import { computed } from 'vue'
|
||||
import type { RouteParams } from 'vue-router'
|
||||
import { useUserStore } from '../store/user'
|
||||
|
||||
interface ArticlesListNavLink {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { render } from '@testing-library/vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import PopularTags from 'src/components/PopularTags.vue'
|
||||
import { asyncWrapper, renderOptions, setupMockServer } from 'src/utils/test/test.utils'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
describe('# PopularTags', () => {
|
||||
const server = setupMockServer(
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import type { AppRouteNames } from 'src/router'
|
||||
import { pageToOffset, api } from 'src/services'
|
||||
import type { Article } from 'src/services/api'
|
||||
import useAsync from 'src/utils/use-async'
|
||||
import type { ComputedRef } from 'vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import type { AppRouteNames } from 'src/router'
|
||||
import { api, pageToOffset } from 'src/services'
|
||||
import type { Article } from 'src/services/api'
|
||||
import useAsync from 'src/utils/use-async'
|
||||
|
||||
export function useArticles () {
|
||||
const { articlesType, tag, username, metaChanged } = useArticlesMeta()
|
||||
|
|
@ -34,13 +34,14 @@ export function useArticles () {
|
|||
.then(res => res.data)
|
||||
}
|
||||
|
||||
if (responsePromise !== null) {
|
||||
const response = await responsePromise
|
||||
articles.value = response.articles
|
||||
articlesCount.value = response.articlesCount
|
||||
} else {
|
||||
if (responsePromise === null) {
|
||||
console.error(`Articles type "${articlesType.value}" not supported`)
|
||||
return
|
||||
}
|
||||
|
||||
const response = await responsePromise
|
||||
articles.value = response.articles
|
||||
articlesCount.value = response.articlesCount
|
||||
}
|
||||
|
||||
const changePage = (value: number): void => {
|
||||
|
|
@ -54,8 +55,11 @@ export function useArticles () {
|
|||
const { active: articlesDownloading, run: runWrappedFetchArticles } = useAsync(fetchArticles)
|
||||
|
||||
watch(metaChanged, async () => {
|
||||
if (page.value !== 1) changePage(1)
|
||||
else await runWrappedFetchArticles()
|
||||
if (page.value === 1) {
|
||||
await runWrappedFetchArticles()
|
||||
} else {
|
||||
changePage(1)
|
||||
}
|
||||
})
|
||||
|
||||
watch(page, runWrappedFetchArticles)
|
||||
|
|
@ -76,7 +80,7 @@ export function useArticles () {
|
|||
export type ArticlesType = 'global-feed' | 'my-feed' | 'tag-feed' | 'user-feed' | 'user-favorites-feed'
|
||||
|
||||
export const articlesTypes: ArticlesType[] = ['global-feed', 'my-feed', 'tag-feed', 'user-feed', 'user-favorites-feed']
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
||||
|
||||
export const isArticlesType = (type: any): type is ArticlesType => articlesTypes.includes(type)
|
||||
|
||||
const routeNameToArticlesType: Partial<Record<AppRouteNames, ArticlesType>> = {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ComputedRef } from 'vue'
|
||||
import { api } from 'src/services'
|
||||
import type { Article } from 'src/services/api'
|
||||
import useAsync from 'src/utils/use-async'
|
||||
import type { ComputedRef } from 'vue'
|
||||
|
||||
interface useFavoriteArticleProps {
|
||||
isFavorited: ComputedRef<boolean>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ComputedRef } from 'vue'
|
||||
import { api } from 'src/services'
|
||||
import type { Profile } from 'src/services/api'
|
||||
import useAsync from 'src/utils/use-async'
|
||||
import type { ComputedRef } from 'vue'
|
||||
|
||||
interface UseFollowProps {
|
||||
username: ComputedRef<string>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { api } from 'src/services'
|
||||
import type { Profile } from 'src/services/api'
|
||||
import type { ComputedRef } from 'vue'
|
||||
import { ref, watch } from 'vue'
|
||||
import { api } from 'src/services'
|
||||
import type { Profile } from 'src/services/api'
|
||||
|
||||
interface UseProfileProps {
|
||||
username: ComputedRef<string>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { api } from 'src/services'
|
||||
import { ref } from 'vue'
|
||||
import { api } from 'src/services'
|
||||
|
||||
export function useTags () {
|
||||
const tags = ref<string[]>([])
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
export const CONFIG = {
|
||||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
||||
API_HOST: import.meta.env.VITE_API_HOST || '',
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
|
||||
import App from './App.vue'
|
||||
|
||||
import { router } from './router'
|
||||
|
||||
import registerGlobalComponents from './plugins/global-components'
|
||||
import setAuthorizationToken from './plugins/set-authorization-token'
|
||||
import { router } from './router'
|
||||
|
||||
const app = createApp(App)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { render } from '@testing-library/vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import fixtures from 'src/utils/test/fixtures.ts'
|
||||
import { renderOptions, setupMockServer } from 'src/utils/test/test.utils'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import Article from './Article.vue'
|
||||
|
||||
describe('# Article', () => {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import userEvent from '@testing-library/user-event'
|
||||
import { fireEvent, render } from '@testing-library/vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { router } from 'src/router.ts'
|
||||
import fixtures from 'src/utils/test/fixtures.ts'
|
||||
import { renderOptions, setupMockServer } from 'src/utils/test/test.utils.ts'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import EditArticle from './EditArticle.vue'
|
||||
|
||||
describe('# EditArticle page', () => {
|
||||
|
|
|
|||
|
|
@ -68,10 +68,10 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { api } from 'src/services'
|
||||
import type { Article } from 'src/services/api'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { api } from 'src/services'
|
||||
import type { Article } from 'src/services/api'
|
||||
|
||||
interface FormState {
|
||||
title: string
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { fireEvent, render } from '@testing-library/vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { useUserStore } from 'src/store/user.ts'
|
||||
import fixtures from 'src/utils/test/fixtures.ts'
|
||||
import { createTestRouter, renderOptions, setupMockServer } from 'src/utils/test/test.utils.ts'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import Login from './Login.vue'
|
||||
|
||||
describe('# Login page', () => {
|
||||
|
|
|
|||
|
|
@ -62,11 +62,11 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue'
|
||||
import { routerPush } from 'src/router'
|
||||
import { api, isFetchError } from 'src/services'
|
||||
import type { LoginUser } from 'src/services/api'
|
||||
import { useUserStore } from 'src/store/user'
|
||||
import { reactive, ref } from 'vue'
|
||||
|
||||
const formRef = ref<HTMLFormElement | null>(null)
|
||||
const form: LoginUser = reactive({
|
||||
|
|
@ -87,12 +87,12 @@ const login = async () => {
|
|||
const result = await api.users.login({ user: form })
|
||||
updateUser(result.data.user)
|
||||
await routerPush('global-feed')
|
||||
} catch (e) {
|
||||
if (isFetchError(e)) {
|
||||
errors.value = e.error?.errors
|
||||
} catch (error) {
|
||||
if (isFetchError(error)) {
|
||||
errors.value = error.error?.errors
|
||||
return
|
||||
}
|
||||
console.error(e)
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { fireEvent, render } from '@testing-library/vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import Profile from 'src/pages/Profile.vue'
|
||||
import { router } from 'src/router.ts'
|
||||
import fixtures from 'src/utils/test/fixtures.ts'
|
||||
import { asyncWrapper, createTestRouter, flushPromises, renderOptions, setupMockServer } from 'src/utils/test/test.utils.ts'
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
|
||||
describe('# Profile page', () => {
|
||||
const server = setupMockServer(
|
||||
|
|
|
|||
|
|
@ -67,14 +67,14 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import ArticlesList from 'src/components/ArticlesList.vue'
|
||||
import { useFollow } from 'src/composable/useFollowProfile'
|
||||
import { useProfile } from 'src/composable/useProfile'
|
||||
import type { Profile } from 'src/services/api'
|
||||
import { useUserStore } from 'src/store/user'
|
||||
import { computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
const route = useRoute()
|
||||
const username = computed<string>(() => route.params.username as string)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { fireEvent, render } from '@testing-library/vue'
|
||||
import { createTestRouter, renderOptions, setupMockServer } from 'src/utils/test/test.utils.ts'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createTestRouter, renderOptions, setupMockServer } from 'src/utils/test/test.utils.ts'
|
||||
import Register from './Register.vue'
|
||||
|
||||
describe('# Register form', () => {
|
||||
|
|
|
|||
|
|
@ -69,11 +69,11 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue'
|
||||
import { routerPush } from 'src/router'
|
||||
import { api, isFetchError } from 'src/services'
|
||||
import type { NewUser } from 'src/services/api'
|
||||
import { useUserStore } from 'src/store/user'
|
||||
import { reactive, ref } from 'vue'
|
||||
|
||||
const formRef = ref<HTMLFormElement | null>(null)
|
||||
const form: NewUser = reactive({
|
||||
|
|
@ -95,9 +95,9 @@ const register = async () => {
|
|||
const result = await api.users.createUser({ user: form })
|
||||
updateUser(result.data.user)
|
||||
await routerPush('global-feed')
|
||||
} catch (e) {
|
||||
if (isFetchError(e)) {
|
||||
errors.value = e.error?.errors
|
||||
} catch (error) {
|
||||
if (isFetchError(error)) {
|
||||
errors.value = error.error?.errors
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { fireEvent, render, waitFor } from '@testing-library/vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { router } from 'src/router.ts'
|
||||
import { useUserStore } from 'src/store/user.ts'
|
||||
import fixtures from 'src/utils/test/fixtures.ts'
|
||||
import { renderOptions, setupMockServer } from 'src/utils/test/test.utils.ts'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import Settings from './Settings.vue'
|
||||
|
||||
describe('# Settings Page', () => {
|
||||
|
|
|
|||
|
|
@ -75,18 +75,19 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive } from 'vue'
|
||||
import { routerPush } from 'src/router'
|
||||
import { api } from 'src/services'
|
||||
import type { UpdateUser } from 'src/services/api'
|
||||
import { useUserStore } from 'src/store/user'
|
||||
import { computed, onMounted, reactive } from 'vue'
|
||||
|
||||
const form: UpdateUser = reactive({})
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
const onSubmit = async () => {
|
||||
const filteredForm = Object.entries(form).reduce((a, [k, v]) => v === null ? a : { ...a, [k]: v }, {})
|
||||
// eslint-disable-next-line unicorn/no-array-reduce
|
||||
const filteredForm = Object.entries(form).reduce((form, [k, v]) => v === null ? form : Object.assign(form, { [k]: v }), {})
|
||||
const userData = await api.user.updateCurrentUser({ user: filteredForm }).then(res => res.data.user)
|
||||
userStore.updateUser(userData)
|
||||
await routerPush('profile', { username: userData.username })
|
||||
|
|
@ -107,11 +108,11 @@ onMounted(async () => {
|
|||
})
|
||||
|
||||
const isButtonDisabled = computed(() =>
|
||||
form.image === userStore.user?.image &&
|
||||
form.username === userStore.user?.username &&
|
||||
form.bio === userStore.user?.bio &&
|
||||
form.email === userStore.user?.email &&
|
||||
!form.password,
|
||||
form.image === userStore.user?.image
|
||||
&& form.username === userStore.user?.username
|
||||
&& form.bio === userStore.user?.bio
|
||||
&& form.email === userStore.user?.email
|
||||
&& !form.password,
|
||||
)
|
||||
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import AppLink from 'src/components/AppLink.vue'
|
||||
import type { App } from 'vue'
|
||||
import AppLink from 'src/components/AppLink.vue'
|
||||
|
||||
export default function registerGlobalComponents (app: App): void {
|
||||
app.component('AppLink', AppLink)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { marked } from 'marked'
|
||||
/* eslint-disable array-element-newline */
|
||||
import insane from 'insane'
|
||||
import { marked } from 'marked'
|
||||
|
||||
export default (markdown?: string): string => {
|
||||
if (!markdown) return ''
|
||||
|
|
@ -7,9 +8,9 @@ export default (markdown?: string): string => {
|
|||
|
||||
return insane(html, {
|
||||
allowedTags: ['a', 'article', 'b', 'blockquote', 'br', 'caption', 'code', 'del', 'details', 'div', 'em',
|
||||
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'ins', 'kbd', 'li', 'main', 'ol',
|
||||
'p', 'pre', 'section', 'span', 'strike', 'strong', 'sub', 'summary', 'sup', 'table',
|
||||
'tbody', 'td', 'th', 'thead', 'tr', 'u', 'ul', 'input'],
|
||||
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'input', 'ins', 'kbd', 'li', 'main',
|
||||
'ol', 'p', 'pre', 'section', 'span', 'strike', 'strong', 'sub', 'summary', 'sup',
|
||||
'table', 'tbody', 'td', 'th', 'thead', 'tr', 'u', 'ul'],
|
||||
allowedAttributes: {
|
||||
a: ['href', 'name', 'target', 'title'],
|
||||
iframe: ['allowfullscreen', 'frameborder', 'src'],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
import type { RouteParams, RouteRecordRaw } from 'vue-router'
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
import Home from './pages/Home.vue'
|
||||
import { isAuthorized } from './store/user'
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ export const router = createRouter({
|
|||
})
|
||||
|
||||
export function routerPush (name: AppRouteNames, params?: RouteParams): ReturnType<typeof router.push> {
|
||||
return params !== undefined
|
||||
? router.push({ name, params })
|
||||
: router.push({ name })
|
||||
return params === undefined
|
||||
? router.push({ name })
|
||||
: router.push({ name, params })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { computed, ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { api } from 'src/services'
|
||||
import type { User } from 'src/services/api'
|
||||
import Storage from 'src/utils/storage'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
export const userStorage = new Storage<User>('user')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import { dateFilter } from 'src/utils/filters'
|
||||
import { expect, describe, it } from 'vitest'
|
||||
|
||||
describe('# Date filters', () => {
|
||||
it('should format date correctly', () => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { describe, it, expect } from 'vitest'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import params2query from './params-to-query'
|
||||
|
||||
describe('# params2query', () => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { describe, it, beforeAll, expect } from 'vitest'
|
||||
import { beforeAll, describe, expect, it } from 'vitest'
|
||||
import Storage from './storage'
|
||||
|
||||
describe('# Storage', () => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { Comment, Article, Profile, User } from 'src/services/api'
|
||||
import type { Article, Comment, Profile, User } from 'src/services/api'
|
||||
|
||||
const author: Profile = {
|
||||
username: 'mutoe',
|
||||
|
|
|
|||
|
|
@ -1,16 +1,15 @@
|
|||
/* eslint-disable unicorn/no-nested-ternary */
|
||||
import type { MockedRequest, DefaultBodyType } from 'msw'
|
||||
import { Suspense, defineComponent, h } from 'vue'
|
||||
import type { RouteLocationRaw, Router } from 'vue-router'
|
||||
import { createMemoryHistory, createRouter } from 'vue-router'
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import type { RenderOptions } from '@testing-library/vue'
|
||||
import type { DefaultBodyType, MockedRequest } from 'msw'
|
||||
import { matchRequestUrl, rest } from 'msw'
|
||||
import type { SetupServer } from 'msw/node'
|
||||
import { setupServer } from 'msw/node'
|
||||
import { routes } from 'src/router'
|
||||
import { afterAll, afterEach, beforeAll } from 'vitest'
|
||||
import { defineComponent, h, Suspense } from 'vue'
|
||||
import type { RouteLocationRaw, Router } from 'vue-router'
|
||||
import { createMemoryHistory, createRouter } from 'vue-router'
|
||||
import type { RenderOptions } from '@testing-library/vue'
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import AppLink from 'src/components/AppLink.vue'
|
||||
import { routes } from 'src/router'
|
||||
|
||||
export const createTestRouter = (base?: string): Router => createRouter({
|
||||
routes,
|
||||
|
|
@ -140,7 +139,7 @@ type Listener =
|
|||
* await server.waitForRequest('GET', '/api/articles/markdown')
|
||||
* })
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
|
||||
export function setupMockServer (...listeners: Listener[]) {
|
||||
const parseArgs = (args: Listener): [string, string, number, (object | null)] => {
|
||||
if (args.length === 4) return args
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { isRef } from 'vue'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import useAsync from 'src/utils/use-async'
|
||||
import { vi, expect, it, describe } from 'vitest'
|
||||
|
||||
describe('# Create async process', () => {
|
||||
const someProcess = (): Promise<null> => Promise.resolve(null)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { routerPush } from 'src/router'
|
||||
import { isFetchError } from 'src/services'
|
||||
import type { Ref } from 'vue'
|
||||
import { ref } from 'vue'
|
||||
import { routerPush } from 'src/router'
|
||||
import { isFetchError } from 'src/services'
|
||||
|
||||
interface UseAsync<T extends (...args: unknown[]) => unknown> {
|
||||
active: Ref<boolean>
|
||||
|
|
|
|||
Loading…
Reference in New Issue