OptionDescription.test.jsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import '@testing-library/jest-dom';
  20. import { screen, render, fireEvent, act } from '@superset-ui/core/spec';
  21. import OptionDescription from '../src/OptionDescription';
  22. const defaultProps = {
  23. option: {
  24. label: 'Some option',
  25. description: 'Description for some option',
  26. },
  27. };
  28. beforeEach(() => {
  29. jest.useFakeTimers();
  30. });
  31. afterEach(() => {
  32. jest.useRealTimers();
  33. });
  34. describe('OptionDescription', () => {
  35. beforeEach(() => {
  36. const props = { option: { ...defaultProps.option } };
  37. render(<OptionDescription {...props} />);
  38. });
  39. it('renders an InfoTooltip', () => {
  40. const tooltipTrigger = screen.getByLabelText('Show info tooltip');
  41. expect(tooltipTrigger).toBeInTheDocument();
  42. // Perform delayed mouse hovering so tooltip could pop out
  43. fireEvent.mouseOver(tooltipTrigger);
  44. act(() => jest.runAllTimers());
  45. const tooltip = screen.getByRole('tooltip');
  46. expect(tooltip).toBeInTheDocument();
  47. expect(tooltip).toHaveTextContent('Description for some option');
  48. });
  49. it('renders a span with the label', () => {
  50. expect(
  51. screen.getByText('Some option', { selector: 'span' }),
  52. ).toBeInTheDocument();
  53. });
  54. });