From 04fd61336b1deb13ede5eb34fdf59ce319ff7212 Mon Sep 17 00:00:00 2001 From: jordan <jordanishanda@yahoo.com> Date: Sun, 6 Oct 2019 22:48:52 +0700 Subject: [PATCH 1/4] [RED] Failed test current date --- assets/js/__test__/components/TopMenu-test.jsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/assets/js/__test__/components/TopMenu-test.jsx b/assets/js/__test__/components/TopMenu-test.jsx index b3398263..5b310df7 100644 --- a/assets/js/__test__/components/TopMenu-test.jsx +++ b/assets/js/__test__/components/TopMenu-test.jsx @@ -3,6 +3,7 @@ import React from 'react'; import ReactTestUtils from 'react-addons-test-utils'; import fetchMock from 'fetch-mock'; import TopMenu from '../../components/TopMenu'; +import moment from 'moment'; describe('TopMenu', () => { fetchMock.restore(); @@ -214,5 +215,17 @@ describe('TopMenu', () => { topmenu.handleItemClick(new Event('click'), 'undefined'); expect(topmenu.state.activeItem).to.equal(undefined); }); + + it('changes the activeItem when item is clicked 2', () => { + // const serverDate = document.getElementById('serverDate'); + // const currentDate = document.getElementById('currentDate'); + const date = new Date(); + const expectedDate = moment(date).format('dddd') + ', ' + moment(date).format('LL'); + const topMenu = ReactTestUtils.renderIntoDocument( + <TopMenu user={adminUser2}> + <div> test </div> + </TopMenu>); + expect(topMenu.state.currentDate).to.equal(expectedDate); + }); }); -- GitLab From 8f6cf1e67ce485d74a152ef1bf5c54905f6bc5f9 Mon Sep 17 00:00:00 2001 From: jordan <jordanishanda@yahoo.com> Date: Sun, 6 Oct 2019 22:57:16 +0700 Subject: [PATCH 2/4] [RED] Failed test current date --- assets/js/__test__/components/TopMenu-test.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/__test__/components/TopMenu-test.jsx b/assets/js/__test__/components/TopMenu-test.jsx index 5b310df7..f260c6df 100644 --- a/assets/js/__test__/components/TopMenu-test.jsx +++ b/assets/js/__test__/components/TopMenu-test.jsx @@ -216,7 +216,7 @@ describe('TopMenu', () => { expect(topmenu.state.activeItem).to.equal(undefined); }); - it('changes the activeItem when item is clicked 2', () => { + it('TopMenu state contain right current date time', () => { // const serverDate = document.getElementById('serverDate'); // const currentDate = document.getElementById('currentDate'); const date = new Date(); -- GitLab From a580a650fd71846a4eea14a9f0876087694ac617 Mon Sep 17 00:00:00 2001 From: jordan <jordanishanda@yahoo.com> Date: Sun, 6 Oct 2019 23:02:23 +0700 Subject: [PATCH 3/4] [GREEN] implement current date state in TopMenu component --- assets/js/components/TopMenu.jsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/assets/js/components/TopMenu.jsx b/assets/js/components/TopMenu.jsx index e2229ecc..30d0591d 100644 --- a/assets/js/components/TopMenu.jsx +++ b/assets/js/components/TopMenu.jsx @@ -3,6 +3,7 @@ import { Menu, Image, Popup, Button, Card } from 'semantic-ui-react'; import { Link, browserHistory } from 'react-router'; import Server from '../lib/Server'; import Storage from '../lib/Storage'; +import moment from 'moment'; const defaultPicture = 'https://semantic-ui.com/images/avatar/small/elliot.jpg'; @@ -35,7 +36,11 @@ export default class TopMenu extends React.Component { constructor(props) { super(props); /* istanbul ignore next */ - this.state = { activeItem: 'Beranda', logoutLoading: false }; + this.state = { + activeItem: 'Beranda', + logoutLoading: false, + currentDate: moment(new Date()).format('dddd') + ', ' + moment(new Date()).format('LL'), + }; this.logout = this.logout.bind(this); this.logoutCompany = this.logoutCompany.bind(this); } -- GitLab From 988b62df37fdbbfb33c8f3314ec2892c306c1006 Mon Sep 17 00:00:00 2001 From: jordan <jordanishanda@yahoo.com> Date: Sun, 6 Oct 2019 23:18:47 +0700 Subject: [PATCH 4/4] [REFACTOR] change locale to indonesia and show it on topmenu --- assets/js/__test__/components/TopMenu-test.jsx | 3 +-- assets/js/components/TopMenu.jsx | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/assets/js/__test__/components/TopMenu-test.jsx b/assets/js/__test__/components/TopMenu-test.jsx index f260c6df..aa05f375 100644 --- a/assets/js/__test__/components/TopMenu-test.jsx +++ b/assets/js/__test__/components/TopMenu-test.jsx @@ -217,8 +217,7 @@ describe('TopMenu', () => { }); it('TopMenu state contain right current date time', () => { - // const serverDate = document.getElementById('serverDate'); - // const currentDate = document.getElementById('currentDate'); + moment.locale('id'); const date = new Date(); const expectedDate = moment(date).format('dddd') + ', ' + moment(date).format('LL'); const topMenu = ReactTestUtils.renderIntoDocument( diff --git a/assets/js/components/TopMenu.jsx b/assets/js/components/TopMenu.jsx index 30d0591d..5c0f896c 100644 --- a/assets/js/components/TopMenu.jsx +++ b/assets/js/components/TopMenu.jsx @@ -36,6 +36,7 @@ export default class TopMenu extends React.Component { constructor(props) { super(props); /* istanbul ignore next */ + moment.locale('id'); this.state = { activeItem: 'Beranda', logoutLoading: false, @@ -81,6 +82,9 @@ export default class TopMenu extends React.Component { <Menu color="blue" pointing secondary> <Image as={Link} size="small" src="/assets/img/logo.png" to="/home" /> <Menu.Menu position="right"> + <Menu.Item style={{ margin: '3px' }}> + { this.state.currentDate } + </Menu.Item> <Menu.Item as={Link} to="/home" name="Beranda" active={activeItem === 'Beranda'} onClick={this.handleItemClick} /> { this.props.user.role === 'student' && <Menu.Item as={Link} to="/profil-mahasiswa" name="Profil" active={activeItem === 'Profil'} onClick={this.handleItemClick} /> } -- GitLab