Unverified Commit 8b9ce930 authored by Marcos Iglesias's avatar Marcos Iglesias Committed by GitHub

Fixes ordering issue on announcements on homepage (#619)

Signed-off-by: 's avatarMarcos Iglesias Valle <golodhros@gmail.com>
parent ebdcc0ac
import * as React from 'react';
import { Link, BrowserRouter } from 'react-router-dom';
import SanitizedHTML from 'react-sanitized-html';
import { mount } from 'enzyme';
import Card from '../../Card';
......@@ -8,27 +7,22 @@ import Card from '../../Card';
import AnnouncementsList, { AnnouncementsListProps } from '.';
const TWO_FAKE_ANNOUNCEMENTS = [
{
date: '12/31/1999',
title: 'Y2K',
html_content: '<div>The end of the world</div>',
},
{
date: '01/01/2000',
title: 'False Alarm',
html_content: '<div>Just kidding</div>',
},
];
const FOUR_FAKE_ANNOUNCEMENTS = [
{
date: '12/31/1999',
title: 'Y2K',
html_content: '<div>The end of the world</div>',
},
];
const FOUR_FAKE_ANNOUNCEMENTS = [
{
date: '01/01/2000',
title: 'False Alarm',
html_content: '<div>Just kidding</div>',
date: '01/01/2020',
title: 'New Test',
html_content: '<div>New test</div>',
},
{
date: '12/31/2009',
......@@ -36,9 +30,14 @@ const FOUR_FAKE_ANNOUNCEMENTS = [
html_content: '<div>Old test</div>',
},
{
date: '01/01/2020',
title: 'New Test',
html_content: '<div>New test</div>',
date: '01/01/2000',
title: 'False Alarm',
html_content: '<div>Just kidding</div>',
},
{
date: '12/31/1999',
title: 'Y2K',
html_content: '<div>The end of the world</div>',
},
];
const EMPTY_ANNOUNCEMENTS = [];
......@@ -171,6 +170,27 @@ describe('AnnouncementsList', () => {
const expected = 3;
const actual = wrapper.find(Card).length;
expect(actual).toEqual(expected);
wrapper.unmount();
});
it('should render them starting on the latest announcement', () => {
const { wrapper } = setup({
announcements: FOUR_FAKE_ANNOUNCEMENTS,
});
const firstCardDate = wrapper
.find(Card)
.at(0)
.find('.card-subtitle')
.text();
const lastCardDate = wrapper
.find(Card)
.at(1)
.find('.card-subtitle')
.text();
const actual = new Date(firstCardDate) >= new Date(lastCardDate);
const expected = true;
expect(actual).toEqual(expected);
});
});
......
......@@ -27,7 +27,7 @@ export interface AnnouncementsListProps {
const getLatestsAnnouncements = (announcements: AnnouncementPost[]) =>
announcements.length > ANNOUNCEMENT_LIST_THRESHOLD
? announcements.splice(announcements.length - ANNOUNCEMENT_LIST_THRESHOLD)
? announcements.slice(0, ANNOUNCEMENT_LIST_THRESHOLD)
: announcements;
const times = (numItems: number) => new Array(numItems).fill(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment