From 7c2b7f4b03ad543ec035a94738c6e96a1c4894ad Mon Sep 17 00:00:00 2001 From: Jeff MAURY Date: Wed, 6 Nov 2024 08:47:23 +0100 Subject: [PATCH] fix: remove path from recipe details (#2053) * fix: remove path from recipe details Fixes #1980 Signed-off-by: Jeff MAURY --- packages/frontend/src/lib/RecipeCard.spec.ts | 94 ++++++++++++++++++++ packages/frontend/src/lib/RecipeCard.svelte | 19 ++-- 2 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 packages/frontend/src/lib/RecipeCard.spec.ts diff --git a/packages/frontend/src/lib/RecipeCard.spec.ts b/packages/frontend/src/lib/RecipeCard.spec.ts new file mode 100644 index 000000000..12bbd0e8e --- /dev/null +++ b/packages/frontend/src/lib/RecipeCard.spec.ts @@ -0,0 +1,94 @@ +/********************************************************************** + * Copyright (C) 2024 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ***********************************************************************/ + +import '@testing-library/jest-dom/vitest'; +import { vi, test, expect, beforeEach } from 'vitest'; +import { screen, render } from '@testing-library/svelte'; +import { findLocalRepositoryByRecipeId } from '/@/utils/localRepositoriesUtils'; +import RecipeCard from './RecipeCard.svelte'; +import { writable, type Writable } from 'svelte/store'; +import type { LocalRepository } from '@shared/src/models/ILocalRepository'; +import { localRepositories } from '../stores/localRepositories'; + +vi.mock('/@/utils/localRepositoriesUtils', () => ({ + findLocalRepositoryByRecipeId: vi.fn(), +})); + +vi.mock('../stores/localRepositories', () => ({ + localRepositories: { + subscribe: vi.fn(), + unsubscribe: vi.fn(), + }, +})); + +vi.mock('../utils/client', async () => { + return { + studioClient: {}, + }; +}); + +const mockLocalRepositories: Writable = writable([]); + +const recipe = { + id: 'recipe 1', + name: 'Recipe 1', + readme: 'readme 1', + categories: [], + recommended: ['model1', 'model2'], + description: 'description 1', + repository: 'repo 1', +}; + +beforeEach(() => { + vi.resetAllMocks(); + vi.mocked(localRepositories).subscribe.mockImplementation(run => mockLocalRepositories.subscribe(run)); +}); + +test('recipe name and description', async () => { + // eslint-disable-next-line sonarjs/publicly-writable-directories + vi.mocked(findLocalRepositoryByRecipeId).mockReturnValue({ path: 'recipe1', sourcePath: '/tmp/recipe1', labels: {} }); + render(RecipeCard, { + recipe, + }); + + const name = screen.queryByLabelText('Recipe 1 name'); + expect(name).toBeInTheDocument(); + + const description = screen.queryByLabelText('Recipe 1 description'); + expect(description).toBeInTheDocument(); + + const reference = screen.queryByLabelText('Recipe 1 ref'); + expect(reference).not.toBeInTheDocument(); +}); + +test('recipe name, description and reference', async () => { + // eslint-disable-next-line sonarjs/publicly-writable-directories + vi.mocked(findLocalRepositoryByRecipeId).mockReturnValue({ path: 'recipe1', sourcePath: '/tmp/recipe1', labels: {} }); + render(RecipeCard, { + recipe: { ...recipe, ref: 'myref' }, + }); + + const name = screen.queryByLabelText('Recipe 1 name'); + expect(name).toBeInTheDocument(); + + const description = screen.queryByLabelText('Recipe 1 description'); + expect(description).toBeInTheDocument(); + + const reference = screen.queryByLabelText('Recipe 1 ref'); + expect(reference).toBeInTheDocument(); +}); diff --git a/packages/frontend/src/lib/RecipeCard.svelte b/packages/frontend/src/lib/RecipeCard.svelte index 900b90d69..267c14a77 100644 --- a/packages/frontend/src/lib/RecipeCard.svelte +++ b/packages/frontend/src/lib/RecipeCard.svelte @@ -1,7 +1,7 @@