diff --git a/package.json b/package.json index 2d5fd3c5ba..672bb3ead9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@reapit/elements", - "version": "0.5.23", + "version": "0.5.24", "description": "A collection of React components and utilities for building apps for Reapit Marketplace", "main": "dist/index.js", "umd:main": "dist/elements.umd.production.js", diff --git a/src/components/Info/__tests__/__snapshots__/index.tsx.snap b/src/components/Info/__tests__/__snapshots__/index.tsx.snap index 43cfd472fa..dd9b15f772 100644 --- a/src/components/Info/__tests__/__snapshots__/index.tsx.snap +++ b/src/components/Info/__tests__/__snapshots__/index.tsx.snap @@ -30,14 +30,14 @@ exports[`Info should match a snapshot for variant CLIENT_APPS_EMPTY 1`] = ` exports[`Info should match a snapshot for variant DEVELOPER_APPS_EMPTY 1`] = ` `; exports[`Info should match a snapshot for variant INSTALLED_APPS_EMPTY 1`] = ` `; diff --git a/src/components/Info/__tests__/index.tsx b/src/components/Info/__tests__/index.tsx index 57ef573202..ec7b1a8fa9 100644 --- a/src/components/Info/__tests__/index.tsx +++ b/src/components/Info/__tests__/index.tsx @@ -2,6 +2,8 @@ import * as React from 'react' import { shallow } from 'enzyme' import toJson from 'enzyme-to-json' import { Info, InfoType } from '..' +import { infoText } from '../index' +import Alert from '../../Alert' const variants: InfoType[] = [ '404', @@ -18,4 +20,13 @@ describe('Info', () => { expect(toJson(shallow())).toMatchSnapshot() }) }) + + variants.forEach(variant => { + it(`should have message \"${infoText(variant)}\" when info type is \"${variant}\"`, () => { + const alert = shallow() + .find(Alert) + .dive() + expect(alert.text()).toBe(infoText(variant)) + }) + }) }) diff --git a/src/components/Info/index.tsx b/src/components/Info/index.tsx index 1b5a5a0155..6d65bbfb24 100644 --- a/src/components/Info/index.tsx +++ b/src/components/Info/index.tsx @@ -13,16 +13,16 @@ export interface InfoProps { infoType: InfoType } -const infoText = (infoType: InfoType) => { +export const infoText = (infoType: InfoType) => { switch (infoType) { case '404': return 'Page not found' case 'CLIENT_APPS_EMPTY': return 'We are sorry, there are no apps listed compatible with your account' case 'INSTALLED_APPS_EMPTY': - return 'You have no apps installed - try browsing the apps list for apps you might find useful' + return 'It looks like you haven’t installed any Apps yet. Have a look at what’s available by clicking ‘Browse’ from the menu.' case 'DEVELOPER_APPS_EMPTY': - return 'You currently have no apps listed. Go to the submit app page to submit an app. After submission, you will need to edit the app and set status to isListed to appear in the marketplace' + return 'It looks like you haven’t submitted an App yet . When you’re ready, click on ‘Submit’ from the menu to get started.' case 'ADMIN_APPROVALS_EMPTY': return 'There are no updates that require approval' default: diff --git a/src/components/Info/info.stories.tsx b/src/components/Info/info.stories.tsx index e3161fe0b0..5aafffea4e 100644 --- a/src/components/Info/info.stories.tsx +++ b/src/components/Info/info.stories.tsx @@ -5,3 +5,4 @@ import { Info } from './index' storiesOf('Info', module) .add('404', () => ) .add('NoAppsInstalled', () => ) + .add('DeveloperAppsEmpty', () => ) diff --git a/src/components/ToastMessage/__tests__/__snapshots__/index.tsx.snap b/src/components/ToastMessage/__tests__/__snapshots__/index.tsx.snap index aa1ccdfcce..fed05b9e5a 100644 --- a/src/components/ToastMessage/__tests__/__snapshots__/index.tsx.snap +++ b/src/components/ToastMessage/__tests__/__snapshots__/index.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`ToastMessage should match a snapshot 1`] = ` +exports[`ToastMessage should match a snapshot when pass different props 1`] = `
`; + +exports[`ToastMessage should match a snapshot with default baseProps 1`] = ` +
+ + Toast message + +
+`; diff --git a/src/components/ToastMessage/__tests__/index.tsx b/src/components/ToastMessage/__tests__/index.tsx index 21b5437773..22891be12a 100644 --- a/src/components/ToastMessage/__tests__/index.tsx +++ b/src/components/ToastMessage/__tests__/index.tsx @@ -3,20 +3,28 @@ import { shallow } from 'enzyme' import toJson from 'enzyme-to-json' import { ToastMessage, ToastMessageProps, ToastVariant } from '..' -const defaultProps: ToastMessageProps = { - visible: true, +const baseProps: ToastMessageProps = { message: 'Toast message', variant: 'primary', onCloseToast: jest.fn() } +const defaultProps: ToastMessageProps = { + ...baseProps, + visible: true, + displayDuration: 5000 +} describe('ToastMessage', () => { - it('should match a snapshot', () => { + it('should match a snapshot with default baseProps', () => { + expect(toJson(shallow())).toMatchSnapshot() + }) + + it('should match a snapshot when pass different props', () => { expect(toJson(shallow())).toMatchSnapshot() }) it('should dismiss toast when click', () => { - shallow() + shallow() .find('[data-test="toast-wrapper"]') .first() .simulate('click') diff --git a/src/components/ToastMessage/index.tsx b/src/components/ToastMessage/index.tsx index b9780a0dc0..5fff450a33 100644 --- a/src/components/ToastMessage/index.tsx +++ b/src/components/ToastMessage/index.tsx @@ -4,15 +4,22 @@ import { Button } from '../Button' export type ToastVariant = 'primary' | 'secondary' | 'danger' | 'info' export interface ToastMessageProps { - visible: boolean + visible?: boolean + displayDuration?: number message: string variant: ToastVariant onCloseToast: () => void } -export const ToastMessage: React.FC = ({ visible = false, message, onCloseToast, variant }) => { +export const ToastMessage: React.FC = ({ + visible = false, + displayDuration = 3000, + message, + onCloseToast, + variant +}) => { if (visible) { - setTimeout(onCloseToast, 3000) + setTimeout(onCloseToast, displayDuration) } return ( diff --git a/yarn.lock b/yarn.lock index eed13274ba..95141c8303 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6375,9 +6375,9 @@ gzip-size@5.1.1, gzip-size@^5.0.0: pify "^4.0.1" handlebars@^4.1.2: - version "4.4.3" - resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.4.3.tgz#180bae52c1d0e9ec0c15d7e82a4362d662762f6e" - integrity sha512-B0W4A2U1ww3q7VVthTKfh+epHx+q4mCt6iK+zEAzbMBpWQAwxCeKxEGpj/1oQTpzPXDNSOG7hmG14TsISH50yw== + version "4.5.3" + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.5.3.tgz#5cf75bd8714f7605713511a56be7c349becb0482" + integrity sha512-3yPecJoJHK/4c6aZhSvxOyG4vJKDshV36VHp0iVCDVh7o9w2vwi3NSnL2MMPj3YdduqaBcu7cGbggJQM0br9xA== dependencies: neo-async "^2.6.0" optimist "^0.6.1"