Skip to content

Commit

Permalink
fixup! Feat(web-react): ReactNode type for labels #DS-1632
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelklibani committed Jan 22, 2025
1 parent 6a2273b commit b97f5e5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,31 @@ describe('Checkbox', () => {
it('should have text classname', () => {
render(<Checkbox id="checkbox" label="Label" />);

const element = screen.getByRole('checkbox').nextElementSibling;

expect(element).toHaveClass('Checkbox__text');
expect(screen.getByRole('checkbox').nextElementSibling).toHaveClass('Checkbox__text');
});

it('should have label classname', () => {
render(<Checkbox id="checkbox" label="Label" />);

const element = screen.getByRole('checkbox').nextElementSibling?.firstChild;

expect(element).toHaveClass('Checkbox__label');
expect(screen.getByRole('checkbox').nextElementSibling?.firstChild).toHaveClass('Checkbox__label');
});

it('should have hidden classname', () => {
render(<Checkbox id="checkbox" label="Label" isLabelHidden />);

const element = screen.getByRole('checkbox').nextElementSibling?.firstChild;

expect(element).toHaveClass('Checkbox__label--hidden');
expect(screen.getByRole('checkbox').nextElementSibling?.firstChild).toHaveClass('Checkbox__label--hidden');
});

it('should have required classname', () => {
render(<Checkbox id="checkbox" label="Label" isRequired />);

const element = screen.getByRole('checkbox').nextElementSibling?.firstChild;

expect(element).toHaveClass('Checkbox__label--required');
expect(screen.getByRole('checkbox').nextElementSibling?.firstChild).toHaveClass('Checkbox__label--required');
});

it('should have input classname', () => {
render(<Checkbox id="checkbox" label="Label" />);

const element = screen.getByRole('checkbox');

expect(element).toHaveClass('Checkbox__input');
expect(screen.getByRole('checkbox')).toHaveClass('Checkbox__input');
});

it('should have helper text', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ describe('FieldGroup', () => {
</FieldGroup>,
);

const element = screen.getAllByText('Label')[1];

expect(element).toHaveClass('FieldGroup__label--required');
expect(screen.getAllByText('Label')[1]).toHaveClass('FieldGroup__label--required');
});

it('should have className isDisabled', () => {
Expand All @@ -77,9 +75,7 @@ describe('FieldGroup', () => {
</FieldGroup>,
);

const element = screen.getByRole('group');

expect(element).toHaveAttribute('disabled');
expect(screen.getByRole('group')).toHaveAttribute('disabled');
});

it('should not have visible label', () => {
Expand All @@ -89,9 +85,7 @@ describe('FieldGroup', () => {
</FieldGroup>,
);

const element = screen.getAllByText('Label')[1];

expect(element).toBeUndefined();
expect(screen.getAllByText('Label')[1]).toBeUndefined();
});

it('should have className isFluid', () => {
Expand All @@ -101,9 +95,7 @@ describe('FieldGroup', () => {
</FieldGroup>,
);

const element = screen.getByRole('group');

expect(element).toHaveClass('FieldGroup--fluid');
expect(screen.getByRole('group')).toHaveClass('FieldGroup--fluid');
});

it('should have helper text', () => {
Expand All @@ -126,9 +118,7 @@ describe('FieldGroup', () => {
</FieldGroup>,
);

const element = screen.getByText('helper text');

expect(element).toHaveAttribute('id', 'example-field-group__helperText');
expect(screen.getByText('helper text')).toHaveAttribute('id', 'example-field-group__helperText');
});

it('should render with html tags', () => {
Expand Down
24 changes: 6 additions & 18 deletions packages/web-react/src/components/Select/__tests__/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ describe('Select', () => {
</Select>,
);

const element = screen.getByText('Label');

expect(element).toHaveClass('Select__label');
expect(screen.getByText('Label')).toHaveClass('Select__label');
});

it('should have hidden classname', () => {
Expand All @@ -45,9 +43,7 @@ describe('Select', () => {
</Select>,
);

const element = screen.getByText('Label');

expect(element).toHaveClass('Select__label--hidden');
expect(screen.getByText('Label')).toHaveClass('Select__label--hidden');
});

it('should have required classname', () => {
Expand All @@ -57,9 +53,7 @@ describe('Select', () => {
</Select>,
);

const element = screen.getByText('Label');

expect(element).toHaveClass('Select__label--required');
expect(screen.getByText('Label')).toHaveClass('Select__label--required');
});

it('should have input classname', () => {
Expand All @@ -69,9 +63,7 @@ describe('Select', () => {
</Select>,
);

const element = screen.getByLabelText('Label');

expect(element).toHaveClass('Select__input');
expect(screen.getByLabelText('Label')).toHaveClass('Select__input');
});

it('should have helper text', () => {
Expand All @@ -81,9 +73,7 @@ describe('Select', () => {
</Select>,
);

const element = screen.getByText('Label').parentElement?.lastChild;

expect(element).toHaveTextContent('helper text');
expect(screen.getByText('Label').parentElement?.lastChild).toHaveTextContent('helper text');
});

it('should have fluid classname', () => {
Expand All @@ -93,9 +83,7 @@ describe('Select', () => {
</Select>,
);

const element = screen.getByText('Label').parentElement;

expect(element).toHaveClass('Select--fluid');
expect(screen.getByText('Label').parentElement).toHaveClass('Select--fluid');
});

it('should render label with html tags', () => {
Expand Down

0 comments on commit b97f5e5

Please sign in to comment.