From ab9a6fd21a9ed1870627967b421c8c722d8e3730 Mon Sep 17 00:00:00 2001 From: Quentin Somazzi Date: Thu, 18 Jul 2019 16:01:55 +0200 Subject: [PATCH] Add possibility to remove header from widgets --- package.json | 2 +- src/components/CustomJson.js | 8 +++++--- src/components/JsonKeys.js | 8 +++++--- src/components/JsonStatus.js | 15 +++++++++------ test/components/JsonKeys.test.js | 5 ++--- .../__snapshots__/JsonKeys.test.js.snap | 8 -------- yarn.lock | 7 ++++--- 7 files changed, 26 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index e033cf0..d957020 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "jest": "^23.4.2", "lint-staged": "^7.2.0", "nock": "^9.0.14", - "prettier": "^1.5.3", + "prettier": "1.18.2", "react": "^16.4.0", "react-dom": "^16.4.0", "react-test-renderer": "^16.4.0", diff --git a/src/components/CustomJson.js b/src/components/CustomJson.js index 5b12786..dbf291d 100644 --- a/src/components/CustomJson.js +++ b/src/components/CustomJson.js @@ -26,7 +26,7 @@ export default class CustomJson extends Component { } render() { - const { title, url, apiData, apiError, template } = this.props + const { title, apiData, apiError, template } = this.props let body = if (apiData && !apiError) { @@ -34,10 +34,12 @@ export default class CustomJson extends Component { body =
} + const hasHeader = title && title.length > 0 + return ( - - + {hasHeader && } + {body} diff --git a/src/components/JsonKeys.js b/src/components/JsonKeys.js index 3b22e7a..7b297f6 100644 --- a/src/components/JsonKeys.js +++ b/src/components/JsonKeys.js @@ -29,7 +29,7 @@ export default class JsonKeys extends Component { } render() { - const { title, url, keys, apiData, apiError } = this.props + const { title, keys, apiData, apiError } = this.props let body = if (apiData && !apiError) { @@ -49,10 +49,12 @@ export default class JsonKeys extends Component { ) } + const hasHeader = title && title.length > 0 + return ( - - + {hasHeader && } + {body} diff --git a/src/components/JsonStatus.js b/src/components/JsonStatus.js index d89b732..f76d093 100644 --- a/src/components/JsonStatus.js +++ b/src/components/JsonStatus.js @@ -44,7 +44,7 @@ export default class JsonStatus extends Component { } render() { - const { title, url, statuses, apiData, apiError, theme } = this.props + const { title, statuses, apiData, apiError, theme } = this.props let body let currentStatus = 'unknown' @@ -63,9 +63,10 @@ export default class JsonStatus extends Component { color: theme.colors.failure, }} > - invalid assertion:
- '{status.assert}'
- should conform to:
+ invalid assertion: +
'{status.assert}'
+ should conform to: +
{'/^(equals|contains|matches)\\((.+),(.+)\\)$/'}
) @@ -122,10 +123,12 @@ export default class JsonStatus extends Component { body = } + const hasHeader = title && title.length > 0 + return ( - - + {hasHeader && } + {body} diff --git a/test/components/JsonKeys.test.js b/test/components/JsonKeys.test.js index 43d9a8a..3a8a528 100644 --- a/test/components/JsonKeys.test.js +++ b/test/components/JsonKeys.test.js @@ -50,11 +50,10 @@ it('should display loader if no apiData available', () => { }) describe('title', () => { - it('should display url by default', () => { + it('should display no header by default', () => { const wrapper = Enzyme.shallow() - const header = wrapper.find(WidgetHeader) - expect(header.prop('title')).toBe('http://fake.io') + expect(wrapper.find(WidgetHeader).exists()).toBeFalsy() }) it('should support override', () => { diff --git a/test/components/__snapshots__/JsonKeys.test.js.snap b/test/components/__snapshots__/JsonKeys.test.js.snap index 6c7bfae..dba7b50 100644 --- a/test/components/__snapshots__/JsonKeys.test.js.snap +++ b/test/components/__snapshots__/JsonKeys.test.js.snap @@ -8,14 +8,6 @@ exports[`should render as expected 1`] = `
-
- - http://fake.io - -