You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DateRangeInput-test.tsx 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { shallow } from 'enzyme';
  21. import * as React from 'react';
  22. import { parseDate } from '../../../helpers/dates';
  23. import DateRangeInput from '../DateRangeInput';
  24. const dateA = parseDate('2018-01-17T00:00:00.000Z');
  25. const dateB = parseDate('2018-02-05T00:00:00.000Z');
  26. it('should render', () => {
  27. expect(
  28. shallow(<DateRangeInput onChange={jest.fn()} value={{ from: dateA, to: dateB }} />)
  29. ).toMatchSnapshot();
  30. expect(
  31. shallow(<DateRangeInput onChange={jest.fn()} minDate={dateA} maxDate={dateB} />)
  32. ).toMatchSnapshot('with min/max');
  33. expect(
  34. shallow(
  35. <DateRangeInput
  36. onChange={jest.fn()}
  37. minDate={dateA}
  38. maxDate={dateB}
  39. value={{ from: dateA, to: dateB }}
  40. />
  41. )
  42. ).toMatchSnapshot('with min/max and value');
  43. });
  44. it('should change', () => {
  45. const onChange = jest.fn();
  46. const wrapper = shallow(<DateRangeInput onChange={onChange} />);
  47. wrapper.find('DateInput[data-test="from"]').prop<Function>('onChange')(dateA);
  48. expect(onChange).lastCalledWith({ from: dateA, to: undefined });
  49. wrapper.setProps({ value: { from: dateA } });
  50. wrapper.find('DateInput[data-test="to"]').prop<Function>('onChange')(dateB);
  51. wrapper.update();
  52. expect(onChange).lastCalledWith({ from: dateA, to: dateB });
  53. });