Skip to content

Commit

Permalink
Merge pull request #12 from eea/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
avoinea committed Jul 24, 2023
2 parents 4bbc72c + 7a5ecec commit d60955e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

### [1.1.2](https://github.com/eea/volto-timeline-block/compare/1.1.1...1.1.2) - 24 July 2023

### [1.1.1](https://github.com/eea/volto-timeline-block/compare/1.1.0...1.1.1) - 12 June 2023

#### :hammer_and_wrench: Others
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-timeline-block",
"version": "1.1.1",
"version": "1.1.2",
"description": "@eeacms/volto-timeline-block: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
77 changes: 77 additions & 0 deletions src/TimelineBlock/View.test.jsx
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();
});
});

0 comments on commit d60955e

Please sign in to comment.