generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from eea/develop
Release
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
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
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,77 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { unmountComponentAtNode } from 'react-dom'; | ||
import View from './View'; | ||
import moment from 'moment'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
jest.mock('@plone/volto/helpers/Loadable/Loadable', () => ({ | ||
injectLazyLibs: () => (component) => component, | ||
})); | ||
|
||
jest.mock('moment', () => { | ||
const moment = jest.requireActual('moment'); | ||
|
||
return { default: moment }; | ||
}); | ||
|
||
describe('View and Timeline components', () => { | ||
let container = null; | ||
|
||
beforeEach(() => { | ||
container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
}); | ||
|
||
afterEach(() => { | ||
unmountComponentAtNode(container); | ||
container.remove(); | ||
container = null; | ||
}); | ||
|
||
it('should render empty timeline in edit mode', () => { | ||
render(<View data={{ items: undefined }} mode="edit" />, container); | ||
|
||
expect(screen.getByText('Add Timeline items')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render timeline item with correct data', () => { | ||
const item = { | ||
datetime: '2023-01-01', | ||
title: 'Test Event', | ||
description: 'Test Description', | ||
color: 'blue', | ||
icon: 'star', | ||
}; | ||
const data = { items: [item], reversed: false }; | ||
|
||
const { getByText } = render( | ||
<View data={data} mode="view" moment={moment} />, | ||
container, | ||
); | ||
|
||
expect(getByText('Test Event')).toBeInTheDocument(); | ||
expect(getByText('Test Description')).toBeInTheDocument(); | ||
expect(getByText('Jan 1, 2023 12:00 AM')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render timeline item with correct data', () => { | ||
const item = { | ||
datetime: '2023-01-01', | ||
title: 'Test Event', | ||
description: 'Test Description', | ||
color: undefined, | ||
icon: 'star', | ||
}; | ||
const data = { items: [item], reversed: true, hideTime: true }; | ||
|
||
const { getByText } = render( | ||
<View data={data} mode="view" moment={moment} />, | ||
container, | ||
); | ||
|
||
expect(getByText('Test Event')).toBeInTheDocument(); | ||
expect(getByText('Test Description')).toBeInTheDocument(); | ||
expect(getByText('Jan 1, 2023')).toBeInTheDocument(); | ||
}); | ||
}); |