|
| 1 | +/** |
| 2 | + * Copyright 2020 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +/** |
| 18 | + * External dependencies |
| 19 | + */ |
| 20 | +import { mount } from 'enzyme'; |
| 21 | +import '@testing-library/jest-dom/extend-expect'; |
| 22 | +import { render } from '@testing-library/react'; |
| 23 | + |
| 24 | +/** |
| 25 | + * Internal dependencies |
| 26 | + */ |
| 27 | +import Switch from '../../../../../assets/src/settings/components/integrations/switch'; |
| 28 | +import { SettingsProvider } from '../../../../../assets/src/settings/context'; |
| 29 | + |
| 30 | +const setup = props => { |
| 31 | + return render( |
| 32 | + <SettingsProvider> |
| 33 | + <Switch { ...props } /> |
| 34 | + </SettingsProvider> |
| 35 | + ); |
| 36 | +}; |
| 37 | + |
| 38 | +const baseProps = { |
| 39 | + id: 'material-settings__switch', |
| 40 | + checked: true, |
| 41 | + onChange: jest.fn(), |
| 42 | +}; |
| 43 | + |
| 44 | +describe( 'Settings: Switch', () => { |
| 45 | + const wrapper = mount( |
| 46 | + <SettingsProvider> |
| 47 | + <Switch { ...baseProps } /> |
| 48 | + </SettingsProvider> |
| 49 | + ); |
| 50 | + |
| 51 | + beforeEach( () => { |
| 52 | + baseProps.onChange.mockClear(); |
| 53 | + } ); |
| 54 | + |
| 55 | + it( 'matches snapshot', () => { |
| 56 | + const { container } = setup( baseProps ); |
| 57 | + expect( container ).toMatchSnapshot(); |
| 58 | + } ); |
| 59 | + |
| 60 | + it( 'should be checked', () => { |
| 61 | + const isChecked = wrapper.find( '.mdc-switch__native-control' ); |
| 62 | + |
| 63 | + expect( isChecked.props() ).toHaveProperty( 'aria-checked', true ); |
| 64 | + } ); |
| 65 | +} ); |
0 commit comments