Skip to content

Commit

Permalink
fix (#273): update Labal unit test after merging develop
Browse files Browse the repository at this point in the history
  • Loading branch information
CorinaMurg committed Oct 18, 2024
1 parent f79a31c commit 5e155f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
30 changes: 13 additions & 17 deletions components/Label/Label.test.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Label } from './Label';
import { labelVariants } from './labelVariants';

const variantClasses = {
default: 'text-sm text-zinc-300 cursor-text flex-col gap-1.5',
secondary: 'text-zinc-50 cursor-pointer rounded-xl items-center py-4 px-3 border-2 border-zinc-800 peer-aria-checked:border-orange-600 peer-hover:bg-zinc-800 flex',
};

describe('Label', () => {
labelVariants.forEach((variant) => {
it(`renders correctly with variant ${variant}`, () => {
const disabledVariants = [true, false];

disabledVariants.forEach((disabled) => {
it(`renders correctly when disabled is ${disabled}`, () => {
render(
<Label data-testid="test-label" variant={variant}>
<Label data-testid="test-label" disabled={disabled}>
Test Label
</Label>
);

const label = screen.getByTestId('test-label');
expect(label).toBeInTheDocument();
if (variant) {
expect(label).toHaveClass(variantClasses[variant]);
}

const expectedClass = disabled ? 'opacity-50 cursor-not-allowed' : 'peer-aria-checked:border-accent peer-hover:border-white';
expect(label).toHaveClass(expectedClass);
});
});

it(`applies additional custom classes correctly`, () => {
it('applies additional custom classes correctly', () => {
const extraClasses = 'custom-class-label extra-custom-class';
render(
<Label
data-testid="custom-class-label"
className="custom-class-label extra-custom-class"
className={extraClasses}
>
Custom Test Label
</Label>
);

const labelCustom = screen.getByTestId('custom-class-label');
expect(labelCustom).toBeInTheDocument();
if (labelCustom.hasAttribute('className')) {
expect(labelCustom).toHaveClass('custom-class-label extra-custom-class');
}
expect(labelCustom).toHaveClass(extraClasses);
});
});

4 changes: 0 additions & 4 deletions components/Label/labelVariants.ts

This file was deleted.

0 comments on commit 5e155f8

Please sign in to comment.