Skip to content

Commit

Permalink
Merge branch 'main' into null-check-getinteractivecontent
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Dec 6, 2022
2 parents b9c6fc5 + 12f018e commit 363c7ff
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 72 deletions.
8 changes: 4 additions & 4 deletions packages/colors/examples/sass-modules/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
to-fast-properties "^2.0.0"

"@carbon/colors@file:../..":
version "10.35.0"
version "11.9.0"

"@hapi/[email protected]":
version "5.0.1"
Expand Down Expand Up @@ -1195,9 +1195,9 @@ debug@^2.2.0, debug@^2.3.3:
ms "2.0.0"

decode-uri-component@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=
version "0.2.2"
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.2.tgz#e69dbe25d37941171dd540e024c444cd5188e1e9"
integrity sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ==

decompress-response@^4.2.0:
version "4.2.1"
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/Notification/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ function NotificationIcon({ iconDescription, kind, notificationType }) {
}
return (
<IconForKind
className={`${prefix}--${notificationType}-notification__icon`}>
className={`${prefix}--${notificationType}-notification__icon`}
size={20}>
<title>{iconDescription}</title>
</IconForKind>
);
Expand Down
103 changes: 36 additions & 67 deletions packages/react/src/components/Switch/Switch-test.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,66 @@
/**
* Copyright IBM Corp. 2016, 2018
* Copyright IBM Corp. 2022
*
* 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 Switch from '../Switch';
import { shallow } from 'enzyme';

const prefix = 'cds';
import Switch from './Switch';
import userEvent from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';

describe('Switch', () => {
describe('component rendering', () => {
const buttonWrapper = shallow(
<Switch kind="button" icon={<svg />} text="test" />
);
describe('renders as expected - Component API', () => {
it('should spread extra props onto outermost element', () => {
const { container } = render(<Switch data-testid="test-id" />);

it('should render a button when kind is button', () => {
expect(buttonWrapper.is('button')).toEqual(true);
expect(container.firstChild).toHaveAttribute('data-testid', 'test-id');
});

it('should have the expected text', () => {
expect(buttonWrapper.text()).toEqual('test');
});
it('should support a custom `className` prop on the outermost element', () => {
const { container } = render(<Switch className="custom-class" />);

it('label should have the expected class', () => {
const className = `${prefix}--content-switcher__label`;
expect(buttonWrapper.find('span').hasClass(className)).toEqual(true);
expect(container.firstChild).toHaveClass('custom-class');
});

it('should have the expected class', () => {
const cls = `${prefix}--content-switcher-btn`;
it('should respect disabled prop', () => {
render(<Switch disabled />);

expect(buttonWrapper.hasClass(cls)).toEqual(true);
expect(screen.getByRole('tab')).toHaveAttribute('disabled');
});

it('should not have selected class', () => {
const selectedClass = `${prefix}--content-switcher--selected`;
it('should call onClick when expected', () => {
const onClick = jest.fn();
render(<Switch text="First section" onClick={onClick} />);

userEvent.click(screen.getByText('First section'));

expect(buttonWrapper.hasClass(selectedClass)).toEqual(false);
expect(onClick).toHaveBeenCalled();
});

it('should have a selected class when selected is set to true', () => {
const selected = true;
it('should call onKeyDown when expected', () => {
const onKeyDown = jest.fn();
render(<Switch text="First section" onKeyDown={onKeyDown} />);

buttonWrapper.setProps({ selected });
userEvent.type(screen.getByText('First section'), 'enter');

expect(
buttonWrapper.hasClass(`${prefix}--content-switcher--selected`)
).toEqual(true);
expect(onKeyDown).toHaveBeenCalled();
});
});

describe('events', () => {
const buttonOnClick = jest.fn();
const linkOnClick = jest.fn();
const buttonOnKey = jest.fn();
const linkOnKey = jest.fn();
const index = 1;
const name = 'first';
const text = 'test';

const buttonWrapper = shallow(
<Switch
index={index}
name={name}
kind="button"
onClick={buttonOnClick}
onKeyDown={buttonOnKey}
text={text}
/>
);

const linkWrapper = shallow(
<Switch
index={index}
name={name}
kind="anchor"
onClick={linkOnClick}
onKeyDown={linkOnKey}
text={text}
/>
);

it('should invoke button onClick handler', () => {
buttonWrapper.simulate('click', { preventDefault() {} });
expect(buttonOnClick).toHaveBeenCalledWith({ index, name, text });
it('should respect selected prop', () => {
render(<Switch selected />);

expect(screen.getByRole('tab')).toHaveClass(
'cds--content-switcher--selected'
);
expect(screen.getByRole('tab')).toHaveAttribute('aria-selected', 'true');
});

it('should invoke link onClick handler', () => {
linkWrapper.simulate('click', { preventDefault() {} });
expect(buttonOnClick).toHaveBeenCalledWith({ index, name, text });
it('should respect text prop', () => {
render(<Switch text="First section" />);

expect(screen.getByText('First section')).toBeInTheDocument();
});
});
});

0 comments on commit 363c7ff

Please sign in to comment.