Skip to content

Commit

Permalink
chore: frontend testing setup (mealie-recipes#1739)
Browse files Browse the repository at this point in the history
* add vitest

* initialize lib w/ tests

* move to dev dep

* run tests in CI

* update file names

* move api folder to lib

* move api and api types to same folder

* update generator outpath

* rm husky

* i guess i _did_ need those types

* reorg types

* extract validators into testable components

* (WIP) start composable testing

* fix import type

* fix linter complaint

* simplify icon type def

* fix linter errors (maybe?)

* rename client file for sorting
  • Loading branch information
hay-kot authored Oct 22, 2022
1 parent 9f6bcc8 commit fcc5d99
Show file tree
Hide file tree
Showing 182 changed files with 902 additions and 487 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/partial-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ jobs:
run: yarn lint
working-directory: "frontend"

- name: Run tests 🧪
run: yarn test:ci
working-directory: "frontend"

build:
runs-on: ubuntu-latest

Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ develop-eggs/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
!frontend/src/components/Recipe/Parts/
Expand Down
2 changes: 1 addition & 1 deletion dev/code-generation/gen_ts_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def path_to_module(path: Path):
return str_path

schema_path = PROJECT_DIR / "mealie" / "schema"
types_dir = PROJECT_DIR / "frontend" / "types" / "api-types"
types_dir = PROJECT_DIR / "frontend" / "lib" / "api" / "types"

ignore_dirs = ["__pycache__", "static", "_mealie"]

Expand Down
1 change: 0 additions & 1 deletion frontend/.husky/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/components/Domain/Group/GroupExportData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<script lang="ts">
import { defineComponent, useContext } from "@nuxtjs/composition-api";
import { parseISO, formatDistanceToNow } from "date-fns";
import { GroupDataExport } from "~/types/api-types/group";
import { GroupDataExport } from "~/lib/api/types/group";
export default defineComponent({
props: {
exports: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Group/GroupMealPlanRuleForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<script lang="ts">
import { defineComponent, computed, useContext } from "@nuxtjs/composition-api";
import RecipeOrganizerSelector from "~/components/Domain/Recipe/RecipeOrganizerSelector.vue";
import { RecipeTag, RecipeCategory } from "~/types/api-types/group";
import { RecipeTag, RecipeCategory } from "~/lib/api/types/group";
export default defineComponent({
components: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Group/GroupWebhookEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<script lang="ts">
import { defineComponent, computed, ref } from "@nuxtjs/composition-api";
import { ReadWebhook } from "~/types/api-types/group";
import { ReadWebhook } from "~/lib/api/types/group";
import { timeLocalToUTC, timeUTCToLocal } from "~/composables/use-group-webhooks";
export default defineComponent({
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeActionMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
import { defineComponent, ref, useContext } from "@nuxtjs/composition-api";
import RecipeContextMenu from "./RecipeContextMenu.vue";
import RecipeFavoriteBadge from "./RecipeFavoriteBadge.vue";
import { Recipe } from "~/types/api-types/recipe";
import { Recipe } from "~/lib/api/types/recipe";
const SAVE_EVENT = "save";
const DELETE_EVENT = "delete";
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeAssets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import { defineComponent, reactive, useContext } from "@nuxtjs/composition-api";
import { useStaticRoutes, useUserApi } from "~/composables/api";
import { alert } from "~/composables/use-toast";
import { detectServerBaseUrl } from "~/composables/use-utils";
import { RecipeAsset } from "~/types/api-types/recipe";
import { RecipeAsset } from "~/lib/api/types/recipe";
export default defineComponent({
props: {
Expand Down
10 changes: 5 additions & 5 deletions frontend/components/Domain/Recipe/RecipeCardSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ import RecipeCard from "./RecipeCard.vue";
import RecipeCardMobile from "./RecipeCardMobile.vue";
import { useAsyncKey } from "~/composables/use-utils";
import { useLazyRecipes } from "~/composables/recipes";
import { Recipe } from "~/types/api-types/recipe";
import { Recipe } from "~/lib/api/types/recipe";
import { useUserSortPreferences } from "~/composables/use-users/preferences";
const REPLACE_RECIPES_EVENT = "replaceRecipes";
Expand Down Expand Up @@ -230,13 +230,13 @@ export default defineComponent({
page.value,
// we double-up the first call to avoid a bug with large screens that render the entire first page without scrolling, preventing additional loading
perPage.value*2,
perPage.value * 2,
preferences.value.orderBy,
preferences.value.orderDirection,
cookbook.value,
category.value,
tag.value,
tool.value,
tool.value
);
// since we doubled the first call, we also need to advance the page
Expand All @@ -263,7 +263,7 @@ export default defineComponent({
cookbook.value,
category.value,
tag.value,
tool.value,
tool.value
);
if (!newRecipes.length) {
hasMore.value = false;
Expand Down Expand Up @@ -325,7 +325,7 @@ export default defineComponent({
cookbook.value,
category.value,
tag.value,
tool.value,
tool.value
);
context.emit(REPLACE_RECIPES_EVENT, newRecipes);
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeChips.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<script lang="ts">
import { defineComponent } from "@nuxtjs/composition-api";
import { RecipeCategory, RecipeTag, RecipeTool } from "~/types/api-types/user";
import { RecipeCategory, RecipeTag, RecipeTool } from "~/lib/api/types/user";
export type UrlPrefixParam = "tags" | "categories" | "tools";
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeComments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<script lang="ts">
import { defineComponent, ref, toRefs, onMounted, reactive } from "@nuxtjs/composition-api";
import { useUserApi } from "~/composables/api";
import { RecipeCommentOut } from "~/types/api-types/recipe";
import { RecipeCommentOut } from "~/lib/api/types/recipe";
import UserAvatar from "~/components/Domain/User/UserAvatar.vue";
export default defineComponent({
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/Domain/Recipe/RecipeContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ import RecipeDialogShare from "./RecipeDialogShare.vue";
import { useUserApi } from "~/composables/api";
import { alert } from "~/composables/use-toast";
import { planTypeOptions } from "~/composables/use-group-mealplan";
import { ShoppingListSummary } from "~/types/api-types/group";
import { PlanEntryType } from "~/types/api-types/meal-plan";
import { ShoppingListSummary } from "~/lib/api/types/group";
import { PlanEntryType } from "~/lib/api/types/meal-plan";
import { useAxiosDownloader } from "~/composables/api/use-axios-download";
import { useCopy } from "~/composables/use-copy";
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/Domain/Recipe/RecipeDataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
<script lang="ts">
import { computed, defineComponent, onMounted, ref, useContext } from "@nuxtjs/composition-api";
import RecipeChip from "./RecipeChips.vue";
import { Recipe } from "~/types/api-types/recipe";
import { Recipe } from "~/lib/api/types/recipe";
import { useUserApi } from "~/composables/api";
import { UserOut } from "~/types/api-types/user";
import { UserOut } from "~/lib/api/types/user";
const INPUT_EVENT = "input";
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeDialogSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import { defineComponent, toRefs, reactive, ref, watch, useRoute } from "@nuxtjs/composition-api";
import RecipeCardMobile from "./RecipeCardMobile.vue";
import { useRecipes, allRecipes, useRecipeSearch } from "~/composables/recipes";
import { RecipeSummary } from "~/types/api-types/recipe";
import { RecipeSummary } from "~/lib/api/types/recipe";
const SELECTED_EVENT = "selected";
export default defineComponent({
components: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeDialogShare.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<script lang="ts">
import { defineComponent, computed, toRefs, reactive, useContext } from "@nuxtjs/composition-api";
import { useClipboard, useShare, whenever } from "@vueuse/core";
import { RecipeShareToken } from "~/types/api-types/recipe";
import { RecipeShareToken } from "~/lib/api/types/recipe";
import { useUserApi } from "~/composables/api";
import { alert } from "~/composables/use-toast";
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeFavoriteBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<script lang="ts">
import { computed, defineComponent, useContext } from "@nuxtjs/composition-api";
import { useUserApi } from "~/composables/api";
import { UserOut } from "~/types/api-types/user";
import { UserOut } from "~/lib/api/types/user";
export default defineComponent({
props: {
slug: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
import { computed, defineComponent, reactive, ref, toRefs, useContext } from "@nuxtjs/composition-api";
import { useFoodStore, useFoodData, useUnitStore, useUnitData } from "~/composables/store";
import { validators } from "~/composables/use-validators";
import { RecipeIngredient } from "~/types/api-types/recipe";
import { RecipeIngredient } from "~/lib/api/types/recipe";
export default defineComponent({
props: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeIngredients.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import { computed, defineComponent, reactive, toRefs } from "@nuxtjs/composition-api";
// @ts-ignore vue-markdown has no types
import { parseIngredientText } from "~/composables/recipes";
import { RecipeIngredient } from "~/types/api-types/recipe";
import { RecipeIngredient } from "~/lib/api/types/recipe";
export default defineComponent({
components: {},
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeInstructions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ import {
useContext,
computed,
} from "@nuxtjs/composition-api";
import { RecipeStep, IngredientReferences, RecipeIngredient, RecipeAsset } from "~/types/api-types/recipe";
import { RecipeStep, IngredientReferences, RecipeIngredient, RecipeAsset } from "~/lib/api/types/recipe";
import { parseIngredientText } from "~/composables/recipes";
import { uuid4, detectServerBaseUrl } from "~/composables/use-utils";
import { useUserApi, useStaticRoutes } from "~/composables/api";
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/Domain/Recipe/RecipeList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<script lang="ts">
import { defineComponent } from "@nuxtjs/composition-api";
import { RecipeSummary } from "~/types/api-types/recipe";
import { RecipeSummary } from "~/lib/api/types/recipe";
export default defineComponent({
props: {
Expand All @@ -30,4 +30,4 @@ export default defineComponent({
return {};
},
});
</script>
</script>
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeNotes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<script lang="ts">
import { defineComponent } from "@nuxtjs/composition-api";
import { RecipeNote } from "~/types/api-types/recipe";
import { RecipeNote } from "~/lib/api/types/recipe";
export default defineComponent({
props: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeNutrition.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<script lang="ts">
import { computed, defineComponent, useContext } from "@nuxtjs/composition-api";
import { Nutrition } from "~/types/api-types/recipe";
import { Nutrition } from "~/lib/api/types/recipe";
export default defineComponent({
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ import { until } from "@vueuse/core";
import { invoke } from "@vueuse/shared";
import draggable from "vuedraggable";
import { useUserApi, useStaticRoutes } from "~/composables/api";
import { OcrTsvResponse as NullableOcrTsvResponse } from "~/types/api-types/ocr";
import { OcrTsvResponse as NullableOcrTsvResponse } from "~/lib/api/types/ocr";
import { validators } from "~/composables/use-validators";
import { Recipe, RecipeIngredient, RecipeStep } from "~/types/api-types/recipe";
import { Recipe, RecipeIngredient, RecipeStep } from "~/lib/api/types/recipe";
import { Paths, Leaves, SelectedRecipeLeaves } from "~/types/ocr-types";
import BannerExperimental from "~/components/global/BannerExperimental.vue";
import RecipeDialogBulkAdd from "~/components/Domain/Recipe/RecipeDialogBulkAdd.vue";
Expand All @@ -157,7 +157,7 @@ import RecipeIngredientEditor from "~/components/Domain/Recipe/RecipeIngredientE
import RecipeOcrEditorPageCanvas from "~/components/Domain/Recipe/RecipeOcrEditorPage/RecipeOcrEditorPageParts/RecipeOcrEditorPageCanvas.vue";
import RecipeOcrEditorPageHelp from "~/components/Domain/Recipe/RecipeOcrEditorPage/RecipeOcrEditorPageParts/RecipeOcrEditorPageHelp.vue";
import { uuid4 } from "~/composables/use-utils";
import { NoUndefinedField } from "~/types/api";
import { NoUndefinedField } from "~/lib/api/types/non-generated";
// Temporary Shim until we have a better solution
// https://github.com/phillipdupuis/pydantic-to-typescript/issues/28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<script lang="ts">
import { defineComponent, reactive, useContext, ref, toRefs, watch } from "@nuxtjs/composition-api";
import { onMounted } from "vue-demi";
import { NoUndefinedField } from "~/types/api";
import { OcrTsvResponse as NullableOcrTsvResponse } from "~/types/api-types/ocr";
import { NoUndefinedField } from "~/lib/api/types/non-generated";
import { OcrTsvResponse as NullableOcrTsvResponse } from "~/lib/api/types/ocr";
import { CanvasModes, SelectedTextSplitModes, ImagePosition, Mouse, CanvasRect, ToolbarIcons } from "~/types/ocr-types";
// Temporary Shim until we have a better solution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import { computed, defineComponent, reactive, toRefs, useContext, watch } from "@nuxtjs/composition-api";
import { useUserApi } from "~/composables/api";
import { useCategoryStore, useTagStore, useToolStore } from "~/composables/store";
import { RecipeOrganizer, Organizer } from "~/types/recipe/organizers";
import { RecipeOrganizer, Organizer } from "~/lib/api/types/non-generated";
const CREATED_ITEM_EVENT = "created-item";
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Domain/Recipe/RecipeOrganizerPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import { defineComponent, computed, ref } from "@nuxtjs/composition-api";
import { useContextPresets } from "~/composables/use-context-presents";
import RecipeOrganizerDialog from "~/components/Domain/Recipe/RecipeOrganizerDialog.vue";
import { RecipeOrganizer } from "~/types/recipe/organizers";
import { RecipeOrganizer } from "~/lib/api/types/non-generated";
interface GenericItem {
id?: string;
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/Domain/Recipe/RecipeOrganizerSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
import { defineComponent, ref, useContext } from "@nuxtjs/composition-api";
import { computed, onMounted } from "vue-demi";
import RecipeOrganizerDialog from "./RecipeOrganizerDialog.vue";
import { RecipeCategory, RecipeTag } from "~/types/api-types/user";
import { RecipeTool } from "~/types/api-types/admin";
import { RecipeCategory, RecipeTag } from "~/lib/api/types/user";
import { RecipeTool } from "~/lib/api/types/admin";
import { useTagStore } from "~/composables/store/use-tag-store";
import { useCategoryStore, useToolStore } from "~/composables/store";
import { Organizer, RecipeOrganizer } from "~/types/recipe/organizers";
import { Organizer, RecipeOrganizer } from "~/lib/api/types/non-generated";
export default defineComponent({
components: {
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/Domain/Recipe/RecipePage/RecipePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ import RecipePageTitleContent from "./RecipePageParts/RecipePageTitleContent.vue
import RecipePageComments from "./RecipePageParts/RecipePageComments.vue";
import RecipePrintView from "~/components/Domain/Recipe/RecipePrintView.vue";
import { EditorMode, PageMode, usePageState, usePageUser } from "~/composables/recipe-page/shared-state";
import { NoUndefinedField } from "~/types/api";
import { Recipe } from "~/types/api-types/recipe";
import { NoUndefinedField } from "~/lib/api/types/non-generated";
import { Recipe } from "~/lib/api/types/recipe";
import { useRecipeMeta } from "~/composables/recipes";
import { useRouteQuery } from "~/composables/use-router";
import { useUserApi } from "~/composables/api";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
<script lang="ts">
import { defineComponent, ref, toRefs, onMounted, reactive } from "@nuxtjs/composition-api";
import { useUserApi } from "~/composables/api";
import { Recipe, RecipeCommentOut } from "~/types/api-types/recipe";
import { Recipe, RecipeCommentOut } from "~/lib/api/types/recipe";
import UserAvatar from "~/components/Domain/User/UserAvatar.vue";
import { NoUndefinedField } from "~/types/api";
import { NoUndefinedField } from "~/lib/api/types/non-generated";
import { usePageUser } from "~/composables/recipe-page/shared-state";
export default defineComponent({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<script lang="ts">
import { defineComponent, onUnmounted } from "@nuxtjs/composition-api";
import { clearPageState, usePageState, usePageUser } from "~/composables/recipe-page/shared-state";
import { NoUndefinedField } from "~/types/api";
import { Recipe } from "~/types/api-types/recipe";
import { NoUndefinedField } from "~/lib/api/types/non-generated";
import { Recipe } from "~/lib/api/types/recipe";
import { useUserApi } from "~/composables/api";
import RecipeImageUploadBtn from "~/components/Domain/Recipe/RecipeImageUploadBtn.vue";
import RecipeSettingsMenu from "~/components/Domain/Recipe/RecipeSettingsMenu.vue";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
<script lang="ts">
import { defineComponent, ref } from "@nuxtjs/composition-api";
import { usePageState } from "~/composables/recipe-page/shared-state";
import { NoUndefinedField } from "~/types/api";
import { Recipe } from "~/types/api-types/recipe";
import { NoUndefinedField } from "~/lib/api/types/non-generated";
import { Recipe } from "~/lib/api/types/recipe";
export default defineComponent({
props: {
recipe: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ import RecipeRating from "~/components/Domain/Recipe/RecipeRating.vue";
import RecipeActionMenu from "~/components/Domain/Recipe/RecipeActionMenu.vue";
import RecipeTimeCard from "~/components/Domain/Recipe/RecipeTimeCard.vue";
import { useStaticRoutes } from "~/composables/api";
import { Recipe } from "~/types/api-types/recipe";
import { NoUndefinedField } from "~/types/api";
import { Recipe } from "~/lib/api/types/recipe";
import { NoUndefinedField } from "~/lib/api/types/non-generated";
import { usePageState, usePageUser, PageMode, EditorMode } from "~/composables/recipe-page/shared-state";
export default defineComponent({
components: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
import draggable from "vuedraggable";
import { computed, defineComponent, ref } from "@nuxtjs/composition-api";
import { usePageState, usePageUser } from "~/composables/recipe-page/shared-state";
import { NoUndefinedField } from "~/types/api";
import { Recipe } from "~/types/api-types/recipe";
import { NoUndefinedField } from "~/lib/api/types/non-generated";
import { Recipe } from "~/lib/api/types/recipe";
import RecipeIngredientEditor from "~/components/Domain/Recipe/RecipeIngredientEditor.vue";
import RecipeDialogBulkAdd from "~/components/Domain/Recipe/RecipeDialogBulkAdd.vue";
import { uuid4 } from "~/composables/use-utils";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import { defineComponent } from "@nuxtjs/composition-api";
import { usePageState, usePageUser } from "~/composables/recipe-page/shared-state";
import { useToolStore } from "~/composables/store";
import { NoUndefinedField } from "~/types/api";
import { Recipe } from "~/types/api-types/recipe";
import { NoUndefinedField } from "~/lib/api/types/non-generated";
import { Recipe } from "~/lib/api/types/recipe";
import RecipeIngredients from "~/components/Domain/Recipe/RecipeIngredients.vue";
export default defineComponent({
Expand Down
Loading

0 comments on commit fcc5d99

Please sign in to comment.