From 87a32b412f0e788e17375d10c8d522138fdb0a16 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 5 Mar 2021 15:44:15 +0100 Subject: [PATCH] Added short URL title to visits header --- src/index.scss | 3 +- src/utils/base.scss | 2 +- src/visits/ShortUrlVisitsHeader.tsx | 5 +-- test/visits/ShortUrlVisitsHeader.test.tsx | 39 +++++++++++++++-------- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/index.scss b/src/index.scss index 65ebc4f1..5bcc10ae 100644 --- a/src/index.scss +++ b/src/index.scss @@ -61,7 +61,8 @@ body, .dropdown-divider, .dropdown-menu, .list-group-item, -.modal-content { +.modal-content, +hr { border-color: var(--border-color); } diff --git a/src/utils/base.scss b/src/utils/base.scss index d5c52b2c..ba6ff54c 100644 --- a/src/utils/base.scss +++ b/src/utils/base.scss @@ -18,7 +18,7 @@ $mediumGrey: #dee2e6; $textPlaceholder: #6c757d; // Misc -$headerHeight: 57px; +$headerHeight: 56px; $asideMenuWidth: 260px; $footer-height: 2.3rem; $footer-margin: .8rem; diff --git a/src/visits/ShortUrlVisitsHeader.tsx b/src/visits/ShortUrlVisitsHeader.tsx index d5e8973c..38826b8e 100644 --- a/src/visits/ShortUrlVisitsHeader.tsx +++ b/src/visits/ShortUrlVisitsHeader.tsx @@ -17,6 +17,7 @@ const ShortUrlVisitsHeader = ({ shortUrlDetail, shortUrlVisits, goBack }: ShortU const { visits } = shortUrlVisits; const shortLink = shortUrl?.shortUrl ?? ''; const longLink = shortUrl?.longUrl ?? ''; + const title = shortUrl?.title; const renderDate = () => !shortUrl ? Loading... : ( @@ -39,9 +40,9 @@ const ShortUrlVisitsHeader = ({ shortUrlDetail, shortUrlVisits, goBack }: ShortU
Created: {renderDate()}
- Long URL:{' '} + {`${title ? 'Title' : 'Long URL'}: `} {loading && Loading...} - {!loading && } + {!loading && {title ?? longLink}}
); diff --git a/test/visits/ShortUrlVisitsHeader.test.tsx b/test/visits/ShortUrlVisitsHeader.test.tsx index cd68cfd2..c2701eba 100644 --- a/test/visits/ShortUrlVisitsHeader.test.tsx +++ b/test/visits/ShortUrlVisitsHeader.test.tsx @@ -8,35 +8,48 @@ import { ShortUrlVisits } from '../../src/visits/reducers/shortUrlVisits'; describe('', () => { let wrapper: ShallowWrapper; - const shortUrlDetail = Mock.of({ - shortUrl: { - shortUrl: 'https://doma.in/abc123', - longUrl: 'https://foo.bar/bar/foo', - dateCreated: '2018-01-01T10:00:00+01:00', - }, - loading: false, - }); + const dateCreated = '2018-01-01T10:00:00+01:00'; + const longUrl = 'https://foo.bar/bar/foo'; const shortUrlVisits = Mock.of({ visits: [{}, {}, {}], }); const goBack = jest.fn(); + const createWrapper = (title?: string | null) => { + const shortUrlDetail = Mock.of({ + shortUrl: { + shortUrl: 'https://doma.in/abc123', + longUrl, + dateCreated, + title, + }, + loading: false, + }); - beforeEach(() => { wrapper = shallow( , ); - }); + + return wrapper; + }; + + beforeEach(() => createWrapper()); afterEach(() => wrapper.unmount()); it('shows when the URL was created', () => { const moment = wrapper.find(Moment).first(); - expect(moment.prop('children')).toEqual(shortUrlDetail.shortUrl?.dateCreated); + expect(moment.prop('children')).toEqual(dateCreated); }); - it('shows the long URL', () => { + it.each([ + [ null, longUrl ], + [ undefined, longUrl ], + [ 'My cool title', 'My cool title' ], + ])('shows the long URL and title', (title, expectedContent) => { + const wrapper = createWrapper(title); const longUrlLink = wrapper.find(ExternalLink).last(); - expect(longUrlLink.prop('href')).toEqual(shortUrlDetail.shortUrl?.longUrl); + expect(longUrlLink.prop('href')).toEqual(longUrl); + expect(longUrlLink.prop('children')).toEqual(expectedContent); }); });