Skip to content

Commit

Permalink
test: added tests
Browse files Browse the repository at this point in the history
Signed-off-by: Evzen Gasta <evzen.ml@seznam.cz>
  • Loading branch information
gastoner committed Feb 17, 2025
1 parent 5709fa5 commit 33c1413
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/frontend/src/lib/Badge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test('print Badge with custom text and default background', async () => {
});

test('print Badge with custom text and custom background', async () => {
render(Badge, { icon: faTrash, content: 'custom-text', background: 'bg-[var(--pd-label-text)]' });
render(Badge, { icon: faTrash, content: 'custom-text', backgroundColor: 'bg-[var(--pd-label-text)]' });

const badgeContent = screen.getByText('custom-text');
expect(badgeContent).toBeInTheDocument();
Expand Down
90 changes: 90 additions & 0 deletions packages/frontend/src/lib/RecipeCardTags.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**********************************************************************
* Copyright (C) 2025 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 { screen, render } from '@testing-library/svelte';
import { beforeAll, expect, test, vi } from 'vitest';
import RecipeCardTags from './RecipeCardTags.svelte';
import userEvent from '@testing-library/user-event';

const recipe = {
id: 'recipe1',
name: 'recipe1',
description: 'description',
repository: 'repository',
readme: 'readme',
categories: ['natural-language-processing', 'audio'],
languages: ['java', 'python'],
frameworks: ['langchain', 'vectordb'],
backend: 'whisper-cpp',
};

class ResizeObserver {
observe = vi.fn();
disconnect = vi.fn();
unobserve = vi.fn();
}

beforeAll(() => {
Object.defineProperty(window, 'ResizeObserver', { value: ResizeObserver });
});

test('Should render tags', () => {
render(RecipeCardTags, { recipe: recipe });

const category1 = screen.getByText('Natural Language Processing');
expect(category1).toBeVisible();

const category2 = screen.getByText('Audio');
expect(category2).toBeVisible();

const language1 = screen.getByText('Java');
expect(language1).toBeVisible();

const language2 = screen.getByText('Python');
expect(language2).toBeVisible();

const framework1 = screen.getByText('langchain');
expect(framework1).toBeVisible();

const framework2 = screen.getByText('vectordb');
expect(framework2).toBeVisible();

const backend = screen.getByText('whisper-cpp');
expect(backend).toBeVisible();
});

test("Button should be visible with '+ X more'", () => {

Check failure on line 72 in packages/frontend/src/lib/RecipeCardTags.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / windows-2022

Strings must use singlequote

Check failure on line 72 in packages/frontend/src/lib/RecipeCardTags.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / ubuntu-22.04

Strings must use singlequote

Check failure on line 72 in packages/frontend/src/lib/RecipeCardTags.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / macos-14

Strings must use singlequote
render(RecipeCardTags, { recipe: recipe });

const button = screen.getByRole('button');
expect(button).toBeVisible();
expect(button).toHaveTextContent('more');
});

test('Clicking on button should show all the tags', async () => {
render(RecipeCardTags, { recipe: recipe });

const button = screen.getByRole('button');
expect(button).toBeVisible();
expect(button).toHaveTextContent('more');

// Clicking on the button
await userEvent.click(button);
expect(button).toHaveTextContent('Show less');
});

0 comments on commit 33c1413

Please sign in to comment.