|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +import React from 'react'; |
| 9 | +import { render, screen } from '@testing-library/react'; |
| 10 | +import { useEventDetailsWidthContext } from '../../../../common/components/events_viewer/event_details_width_context'; |
| 11 | +import { FixedWidthLastUpdatedContainer } from './last_updated'; |
| 12 | +import { useKibana } from '../../../../common/lib/kibana'; |
| 13 | +import { createStartServicesMock } from '../../../../common/lib/kibana/kibana_react.mock'; |
| 14 | + |
| 15 | +jest.mock('../../../../common/components/events_viewer/event_details_width_context'); |
| 16 | +jest.mock('../../../../common/lib/kibana'); |
| 17 | + |
| 18 | +const mockEventDetailsWidthContainer = jest.fn().mockImplementation(() => { |
| 19 | + return 800; |
| 20 | +}); |
| 21 | + |
| 22 | +const mockUseLastUpdatedTimelinesPlugin = jest.fn().mockImplementation(() => { |
| 23 | + return `Updated 2 minutes ago`; |
| 24 | +}); |
| 25 | + |
| 26 | +describe('FixWidthLastUpdateContainer', () => { |
| 27 | + beforeEach(() => { |
| 28 | + (useKibana as jest.Mock).mockImplementation(() => { |
| 29 | + return { |
| 30 | + services: { |
| 31 | + ...createStartServicesMock(), |
| 32 | + timelines: { |
| 33 | + getLastUpdated: mockUseLastUpdatedTimelinesPlugin, |
| 34 | + }, |
| 35 | + }, |
| 36 | + }; |
| 37 | + }); |
| 38 | + |
| 39 | + (useEventDetailsWidthContext as jest.Mock).mockImplementation(mockEventDetailsWidthContainer); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should return normal version when width is greater than 600', () => { |
| 43 | + render(<FixedWidthLastUpdatedContainer updatedAt={Date.now()} />); |
| 44 | + expect(screen.getByTestId('fixed-width-last-updated')).toHaveTextContent( |
| 45 | + 'Updated 2 minutes ago' |
| 46 | + ); |
| 47 | + expect(screen.getByTestId('fixed-width-last-updated')).toHaveStyle({ |
| 48 | + width: '200px', |
| 49 | + }); |
| 50 | + }); |
| 51 | + it('should return compact version when width is less than 600', () => { |
| 52 | + mockEventDetailsWidthContainer.mockReturnValueOnce(400); |
| 53 | + render(<FixedWidthLastUpdatedContainer updatedAt={Date.now()} />); |
| 54 | + expect(screen.getByTestId('fixed-width-last-updated')).toHaveTextContent( |
| 55 | + 'Updated 2 minutes ago' |
| 56 | + ); |
| 57 | + expect(screen.getByTestId('fixed-width-last-updated')).toHaveStyle({ |
| 58 | + width: '25px', |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments