"Fossies" - the Fresh Open Source Software Archive

Member "graylog2-server-4.2.0/graylog2-web-interface/src/views/components/searchbar/date-time-picker/AbsoluteCalendar.test.tsx" (13 Oct 2021, 2546 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 { render, screen } from 'wrappedTestingLibrary';
   19 import { Formik, Form } from 'formik';
   20 
   21 import AbsoluteCalendar from './AbsoluteCalendar';
   22 
   23 const defaultProps = {
   24   disabled: false,
   25   nextTimeRange: {
   26     type: 'absolute',
   27     from: '1955-05-11 06:15:00',
   28     to: '1985-10-25 08:18:00',
   29   },
   30 } as const;
   31 
   32 const renderWithForm = (element) => render((
   33   <Formik initialValues={{ nextTimeRange: defaultProps.nextTimeRange }}
   34           onSubmit={() => {}}>
   35     <Form>
   36       {element}
   37     </Form>
   38   </Formik>
   39 ));
   40 
   41 describe('AbsoluteCalendar', () => {
   42   it('renders `from` date', () => {
   43     renderWithForm(<AbsoluteCalendar {...defaultProps} range="from" />);
   44 
   45     const monthYear = screen.getByText('May 1955');
   46     const inputHour = screen.getByRole('spinbutton', { name: /from hour/i });
   47     const inputMinute = screen.getByRole('spinbutton', { name: /from minutes/i });
   48     const inputSeconds = screen.getByRole('spinbutton', { name: /from seconds/i });
   49 
   50     expect(monthYear).not.toBeNull();
   51     // @ts-ignore
   52     expect(inputHour.value).toBe('06');
   53     // @ts-ignore
   54     expect(inputMinute.value).toBe('15');
   55     // @ts-ignore
   56     expect(inputSeconds.value).toBe('00');
   57   });
   58 
   59   it('renders `to` date', () => {
   60     renderWithForm(<AbsoluteCalendar {...defaultProps} range="to" startDate={new Date(defaultProps.nextTimeRange.from)} />);
   61 
   62     const monthYear = screen.getByText('October 1985');
   63     const inputHour = screen.getByRole('spinbutton', { name: /to hour/i });
   64     const inputMinute = screen.getByRole('spinbutton', { name: /to minutes/i });
   65     const inputSeconds = screen.getByRole('spinbutton', { name: /to seconds/i });
   66 
   67     expect(monthYear).not.toBeNull();
   68     // @ts-ignore
   69     expect(inputHour.value).toBe('08');
   70     // @ts-ignore
   71     expect(inputMinute.value).toBe('18');
   72     // @ts-ignore
   73     expect(inputSeconds.value).toBe('00');
   74   });
   75 });