Skip to content

Commit

Permalink
test(ai-label/pagination-skeleton): increase coverage (#17748)
Browse files Browse the repository at this point in the history
  • Loading branch information
ariellalgilmore authored Oct 16, 2024
1 parent eea76a2 commit 1c34943
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
45 changes: 44 additions & 1 deletion packages/react/src/components/AILabel/__tests__/AILabel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*/

import React from 'react';
import { AILabel } from '../';
import { AILabel, AILabelContent, AILabelActions } from '../';
import { Button } from '../../Button';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

const prefix = 'cds';

Expand Down Expand Up @@ -114,4 +116,45 @@ describe('AILabel', () => {
);
});
});

it('should handle revert click', async () => {
render(
<AILabel
revertActive
revertLabel="Test revert label"
onRevertClick={() => {}}
/>
);

await userEvent.click(screen.getByRole('button'));
});
});

describe('AILabelContent', () => {
it('should render with content', () => {
render(
<AILabel>
<AILabelContent>Children test</AILabelContent>
</AILabel>
);

expect(screen.getByText('Children test')).toBeInTheDocument();
});
});

describe('AILabelActions', () => {
it('should render with actions', () => {
render(
<AILabel>
<AILabelContent>
Children test
<AILabelActions>
<Button>View details</Button>
</AILabelActions>
</AILabelContent>
</AILabel>
);

expect(screen.getByText('View details')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import Pagination from './Pagination';
import Pagination from '../Pagination';
import userEvent from '@testing-library/user-event';
import { getAllByRole, render, screen } from '@testing-library/react';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright IBM Corp. 2016, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import { PaginationSkeleton } from '../Pagination.Skeleton';
import { render } from '@testing-library/react';

describe('PaginationSkeleton', () => {
it('should support a custom `className` prop on the outermost element', () => {
const { container } = render(
<PaginationSkeleton aria-label="test" className="test" />
);
expect(container.firstChild).toHaveClass('test');
});

it('should spread additional props on the outermost element', () => {
const { container } = render(
<PaginationSkeleton aria-label="test" data-testid="test" />
);
expect(container.firstChild).toHaveAttribute('data-testid', 'test');
});
});

0 comments on commit 1c34943

Please sign in to comment.