-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: deduped last updated date component
- Loading branch information
Showing
6 changed files
with
76 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ugins/security_solution/public/timelines/components/timeline/footer/last_updated.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { useEventDetailsWidthContext } from '../../../../common/components/events_viewer/event_details_width_context'; | ||
import { FixedWidthLastUpdatedContainer } from './last_updated'; | ||
import { useKibana } from '../../../../common/lib/kibana'; | ||
import { createStartServicesMock } from '../../../../common/lib/kibana/kibana_react.mock'; | ||
|
||
jest.mock('../../../../common/components/events_viewer/event_details_width_context'); | ||
jest.mock('../../../../common/lib/kibana'); | ||
|
||
const mockEventDetailsWidthContainer = jest.fn().mockImplementation(() => { | ||
return 800; | ||
}); | ||
|
||
const mockUseLastUpdatedTimelinesPlugin = jest.fn().mockImplementation(() => { | ||
return `Updated 2 minutes ago`; | ||
}); | ||
|
||
describe('FixWidthLastUpdateContainer', () => { | ||
beforeEach(() => { | ||
(useKibana as jest.Mock).mockImplementation(() => { | ||
return { | ||
services: { | ||
...createStartServicesMock(), | ||
timelines: { | ||
getLastUpdated: mockUseLastUpdatedTimelinesPlugin, | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
(useEventDetailsWidthContext as jest.Mock).mockImplementation(mockEventDetailsWidthContainer); | ||
}); | ||
|
||
it('should return normal version when width is greater than 600', () => { | ||
render(<FixedWidthLastUpdatedContainer updatedAt={Date.now()} />); | ||
expect(screen.getByTestId('fixed-width-last-updated')).toHaveTextContent( | ||
'Updated 2 minutes ago' | ||
); | ||
expect(screen.getByTestId('fixed-width-last-updated')).toHaveStyle({ | ||
width: '200px', | ||
}); | ||
}); | ||
it('should return compact version when width is less than 600', () => { | ||
mockEventDetailsWidthContainer.mockReturnValueOnce(400); | ||
render(<FixedWidthLastUpdatedContainer updatedAt={Date.now()} />); | ||
expect(screen.getByTestId('fixed-width-last-updated')).toHaveTextContent( | ||
'Updated 2 minutes ago' | ||
); | ||
expect(screen.getByTestId('fixed-width-last-updated')).toHaveStyle({ | ||
width: '25px', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters