mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-31 02:03:35 -04:00 
			
		
		
		
	fix: eslint errors and failing tests (#2078)
* fix eslint errors * fix failing tests
This commit is contained in:
		| @@ -26,7 +26,7 @@ module.exports = { | |||||||
|   ], |   ], | ||||||
|   // Re-add once we use nuxt bridge |   // Re-add once we use nuxt bridge | ||||||
|   // See https://v3.nuxtjs.org/getting-started/bridge#update-nuxtconfig |   // See https://v3.nuxtjs.org/getting-started/bridge#update-nuxtconfig | ||||||
|   ignorePatterns: ["nuxt.config.js"], |   ignorePatterns: ["nuxt.config.js", "lib/api/types/**/*.ts"], | ||||||
|   plugins: ["prettier"], |   plugins: ["prettier"], | ||||||
|   // add your custom rules here |   // add your custom rules here | ||||||
|   rules: { |   rules: { | ||||||
|   | |||||||
| @@ -95,7 +95,6 @@ export default defineComponent({ | |||||||
|     const domMadeThisForm = ref<VForm>(); |     const domMadeThisForm = ref<VForm>(); | ||||||
|     const newTimelineEvent = ref<RecipeTimelineEventIn>({ |     const newTimelineEvent = ref<RecipeTimelineEventIn>({ | ||||||
|       // @ts-expect-error - TS doesn't like the $auth global user attribute |       // @ts-expect-error - TS doesn't like the $auth global user attribute | ||||||
|       // eslint-disable-next-line |  | ||||||
|       subject: i18n.t("recipe.user-made-this", { user: $auth.user.fullName } as string), |       subject: i18n.t("recipe.user-made-this", { user: $auth.user.fullName } as string), | ||||||
|       eventType: "comment", |       eventType: "comment", | ||||||
|       eventMessage: "", |       eventMessage: "", | ||||||
|   | |||||||
| @@ -455,10 +455,8 @@ export default defineComponent({ | |||||||
|             correctedRect.startY - state.imagePosition.dy < element.top * state.imagePosition.scale && |             correctedRect.startY - state.imagePosition.dy < element.top * state.imagePosition.scale && | ||||||
|             correctedRect.startX - state.imagePosition.dx < element.left * state.imagePosition.scale && |             correctedRect.startX - state.imagePosition.dx < element.left * state.imagePosition.scale && | ||||||
|             correctedRect.startX + correctedRect.w > |             correctedRect.startX + correctedRect.w > | ||||||
|               // eslint-disable-next-line @typescript-eslint/restrict-plus-operands |  | ||||||
|               (element.left + element.width) * state.imagePosition.scale + state.imagePosition.dx && |               (element.left + element.width) * state.imagePosition.scale + state.imagePosition.dx && | ||||||
|             correctedRect.startY + correctedRect.h > |             correctedRect.startY + correctedRect.h > | ||||||
|               // eslint-disable-next-line @typescript-eslint/restrict-plus-operands |  | ||||||
|               (element.top + element.height) * state.imagePosition.scale + state.imagePosition.dy |               (element.top + element.height) * state.imagePosition.scale + state.imagePosition.dy | ||||||
|         ) |         ) | ||||||
|         .map((element, index, array) => { |         .map((element, index, array) => { | ||||||
| @@ -470,7 +468,6 @@ export default defineComponent({ | |||||||
|           ) { |           ) { | ||||||
|             separator = "\n"; |             separator = "\n"; | ||||||
|           } |           } | ||||||
|           // eslint-disable-next-line @typescript-eslint/restrict-plus-operands |  | ||||||
|           return element.text + separator; |           return element.text + separator; | ||||||
|         }) |         }) | ||||||
|         .join(""); |         .join(""); | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ | |||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script lang="ts"> | <script lang="ts"> | ||||||
| import { defineComponent, toRef } from "@nuxtjs/composition-api"; | import { defineComponent, toRef, useContext } from "@nuxtjs/composition-api"; | ||||||
| import { usePasswordStrength } from "~/composables/use-passwords"; | import { usePasswordStrength } from "~/composables/use-passwords"; | ||||||
|  |  | ||||||
| export default defineComponent({ | export default defineComponent({ | ||||||
| @@ -25,8 +25,9 @@ export default defineComponent({ | |||||||
|   }, |   }, | ||||||
|   setup(props) { |   setup(props) { | ||||||
|     const asRef = toRef(props, "value"); |     const asRef = toRef(props, "value"); | ||||||
|  |     const { i18n } = useContext(); | ||||||
|  |  | ||||||
|     const pwStrength = usePasswordStrength(asRef); |     const pwStrength = usePasswordStrength(asRef, i18n); | ||||||
|  |  | ||||||
|     return { |     return { | ||||||
|       pwStrength, |       pwStrength, | ||||||
|   | |||||||
| @@ -1,20 +1,16 @@ | |||||||
| import { ref } from "@nuxtjs/composition-api"; | import { ref } from "@nuxtjs/composition-api"; | ||||||
| import { describe, expect, test } from "vitest"; | import { describe, expect, test } from "vitest"; | ||||||
| import { usePasswordStrength } from "./use-passwords"; | import { usePasswordStrength } from "./use-passwords"; | ||||||
|  | import { stubI18n } from "~/tests/utils"; | ||||||
|  |  | ||||||
| // test("test usePasswordField", () => { |  | ||||||
| //   const { inputType, togglePasswordShow, passwordIcon } = usePasswordField(); |  | ||||||
| //   expect(inputType.value).toBe("password"); |  | ||||||
| //   expect(passwordIcon.value).toBe("mdi-eye"); |  | ||||||
| //   togglePasswordShow(); |  | ||||||
| //   expect(inputType.value).toBe("text"); |  | ||||||
| //   expect(passwordIcon.value).toBe("mdi-eye-off"); |  | ||||||
| // }); |  | ||||||
|  |  | ||||||
| describe("test usePasswordStrength", () => { | describe("test usePasswordStrength", () => { | ||||||
|   test("weak password", () => { |   test("weak password", () => { | ||||||
|     const password = ref("123456"); |     const pw = ref("123456"); | ||||||
|     const { score, strength, color } = usePasswordStrength(password); |  | ||||||
|  |     const result = usePasswordStrength(pw, stubI18n()); | ||||||
|  |     const { score, strength, color } = result | ||||||
|  |  | ||||||
|     expect(score.value).toBeGreaterThan(0); |     expect(score.value).toBeGreaterThan(0); | ||||||
|     expect(score.value).toBeLessThan(40); |     expect(score.value).toBeLessThan(40); | ||||||
|     expect(strength.value).toBe("Weak"); |     expect(strength.value).toBe("Weak"); | ||||||
| @@ -23,7 +19,7 @@ describe("test usePasswordStrength", () => { | |||||||
|  |  | ||||||
|   test("very strong password", () => { |   test("very strong password", () => { | ||||||
|     const password = ref("My~Secret~Not~So~Secret?123"); |     const password = ref("My~Secret~Not~So~Secret?123"); | ||||||
|     const { score, strength, color } = usePasswordStrength(password); |     const { score, strength, color } = usePasswordStrength(password, stubI18n()); | ||||||
|     expect(score.value).toBeGreaterThan(90); |     expect(score.value).toBeGreaterThan(90); | ||||||
|     expect(score.value).toBe(100); |     expect(score.value).toBe(100); | ||||||
|     expect(strength.value).toBe("Very Strong"); |     expect(strength.value).toBe("Very Strong"); | ||||||
|   | |||||||
| @@ -1,9 +1,9 @@ | |||||||
| import { computed, Ref, ref, useContext } from "@nuxtjs/composition-api"; | import { computed, Ref, ref, useContext } from "@nuxtjs/composition-api"; | ||||||
|  | import VueI18n from "vue-i18n"; | ||||||
| import { scorePassword } from "~/lib/validators"; | import { scorePassword } from "~/lib/validators"; | ||||||
|  |  | ||||||
| export function usePasswordField() { | export function usePasswordField() { | ||||||
|   const show = ref(false); |   const show = ref(false); | ||||||
|  |  | ||||||
|   const { $globals } = useContext(); |   const { $globals } = useContext(); | ||||||
|  |  | ||||||
|   const passwordIcon = computed(() => { |   const passwordIcon = computed(() => { | ||||||
| @@ -22,14 +22,8 @@ export function usePasswordField() { | |||||||
|   }; |   }; | ||||||
| } | } | ||||||
|  |  | ||||||
| export const usePasswordStrength = (password: Ref<string>) => { | export const usePasswordStrength = (password: Ref<string>, i18n: VueI18n) => { | ||||||
|   const { i18n } = useContext(); |   const score = computed(() => scorePassword(password.value)); | ||||||
|  |  | ||||||
|   const score = computed(() => { |  | ||||||
|     return scorePassword(password.value); |  | ||||||
|   }); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   const strength = computed(() => { |   const strength = computed(() => { | ||||||
|     if (score.value < 50) { |     if (score.value < 50) { | ||||||
|       return i18n.tc("user.password-strength-values.weak"); |       return i18n.tc("user.password-strength-values.weak"); | ||||||
|   | |||||||
| @@ -265,7 +265,7 @@ | |||||||
| <script lang="ts"> | <script lang="ts"> | ||||||
| import { computed, defineComponent, reactive, toRefs, watch } from "@nuxtjs/composition-api"; | import { computed, defineComponent, reactive, toRefs, watch } from "@nuxtjs/composition-api"; | ||||||
| import { isSameDay, addDays, subDays, parseISO, format } from "date-fns"; | import { isSameDay, addDays, subDays, parseISO, format } from "date-fns"; | ||||||
| import { SortableEvent } from "sortablejs"; // eslint-disable-line | import { SortableEvent } from "sortablejs"; | ||||||
| import draggable from "vuedraggable"; | import draggable from "vuedraggable"; | ||||||
| import { useMealplans, planTypeOptions } from "~/composables/use-group-mealplan"; | import { useMealplans, planTypeOptions } from "~/composables/use-group-mealplan"; | ||||||
| import { useRecipes, allRecipes } from "~/composables/recipes"; | import { useRecipes, allRecipes } from "~/composables/recipes"; | ||||||
|   | |||||||
| @@ -86,7 +86,7 @@ | |||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script lang="ts"> | <script lang="ts"> | ||||||
| import { defineComponent, ref, useAsync, useContext } from "@nuxtjs/composition-api"; | import { defineComponent, ref, useAsync } from "@nuxtjs/composition-api"; | ||||||
| import { useUserApi } from "~/composables/api"; | import { useUserApi } from "~/composables/api"; | ||||||
| import { PlanRulesCreate, PlanRulesOut } from "~/lib/api/types/meal-plan"; | import { PlanRulesCreate, PlanRulesOut } from "~/lib/api/types/meal-plan"; | ||||||
| import GroupMealPlanRuleForm from "~/components/Domain/Group/GroupMealPlanRuleForm.vue"; | import GroupMealPlanRuleForm from "~/components/Domain/Group/GroupMealPlanRuleForm.vue"; | ||||||
|   | |||||||
							
								
								
									
										19
									
								
								frontend/tests/utils.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								frontend/tests/utils.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | |||||||
|  | import VueI18n from "vue-i18n"; | ||||||
|  | import Vue from "vue"; | ||||||
|  |  | ||||||
|  | Vue.use(VueI18n) | ||||||
|  |  | ||||||
|  | function loadEnLocales() { | ||||||
|  |   // eslint-disable-next-line @typescript-eslint/no-var-requires | ||||||
|  |   return require("../lang/messages/en-US.json") as Record<string, string>; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export function stubI18n() { | ||||||
|  |   const i18n = new VueI18n({ | ||||||
|  |     locale: "en-US", | ||||||
|  |     messages: { | ||||||
|  |       "en-US": loadEnLocales(), | ||||||
|  |     }, | ||||||
|  |   }) | ||||||
|  |   return i18n | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user