"Fossies" - the Fresh Open Source Software Archive

Member "graylog2-server-4.2.0/graylog2-web-interface/src/views/components/searchbar/date-time-picker/AbsoluteDateInput.test.tsx" (13 Oct 2021, 2065 Bytes) of package /linux/misc/graylog2-server-4.2.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TSX (TypeScript with React) source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * Copyright (C) 2020 Graylog, Inc.
    3  *
    4  * This program is free software: you can redistribute it and/or modify
    5  * it under the terms of the Server Side Public License, version 1,
    6  * as published by MongoDB, Inc.
    7  *
    8  * This program is distributed in the hope that it will be useful,
    9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   11  * Server Side Public License for more details.
   12  *
   13  * You should have received a copy of the Server Side Public License
   14  * along with this program. If not, see
   15  * <http://www.mongodb.com/licensing/server-side-public-license>.
   16  */
   17 import * as React from 'react';
   18 import { fireEvent, render, screen } from 'wrappedTestingLibrary';
   19 import moment from 'moment';
   20 
   21 import DateTime from 'logic/datetimes/DateTime';
   22 
   23 import AbsoluteDateInput from './AbsoluteDateInput';
   24 
   25 const dateTimeRange = '2020-04-08 13:22:46';
   26 
   27 const defaultProps = {
   28   name: 'test-absolute-date-input',
   29   disabled: false,
   30   onChange: jest.fn(),
   31   value: dateTimeRange,
   32   hasError: false,
   33 };
   34 
   35 describe('AbsoluteDateInput', () => {
   36   beforeAll(() => { jest.clearAllMocks(); });
   37 
   38   it('renders with minimal props', () => {
   39     render(<AbsoluteDateInput {...defaultProps} />);
   40 
   41     expect(screen).not.toBeNull();
   42   });
   43 
   44   it('calls onChange upon changing the input', () => {
   45     const { getByPlaceholderText } = render(<AbsoluteDateInput {...defaultProps} />);
   46 
   47     const input = getByPlaceholderText(DateTime.Formats.DATETIME);
   48 
   49     fireEvent.change(input, { target: { value: 'something' } });
   50 
   51     expect(defaultProps.onChange).toHaveBeenCalled();
   52   });
   53 
   54   it('pressing magic wand inserts current date', () => {
   55     const output = moment().format(DateTime.Formats.TIMESTAMP);
   56     defaultProps.onChange.mockReturnValueOnce(output);
   57     const { getByTitle } = render(<AbsoluteDateInput {...defaultProps} />);
   58 
   59     const insertCurrentDate = getByTitle('Insert current date');
   60 
   61     fireEvent.click(insertCurrentDate);
   62 
   63     expect(defaultProps.onChange).toHaveReturnedWith(output);
   64   });
   65 });