Skip to content

Commit

Permalink
fix: Always display home icon in Webview
Browse files Browse the repository at this point in the history
In case of race condition, error handling is done by native javascript
(can't call() from undefined)
  • Loading branch information
acezard committed Mar 18, 2022
1 parent d0327e6 commit de2a530
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/components/Apps/ButtonCozyHome.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react'
import { isFlagshipApp } from 'cozy-device-helper'

import flag from 'cozy-flags'

import IconCozyHome from './IconCozyHome'

export const ButtonCozyHome = ({ webviewContext, homeHref }) => {
if (webviewContext || flag('flagship.debug'))
if (isFlagshipApp() || flag('flagship.debug'))
return (
<a
onClick={() => {
Expand Down
13 changes: 10 additions & 3 deletions src/components/Apps/ButtonCozyHome.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react'
import { shallow } from 'enzyme'
import { ButtonCozyHome } from './ButtonCozyHome'
import { isFlagshipApp } from 'cozy-device-helper'

import { ButtonCozyHome } from 'components/Apps/ButtonCozyHome'
jest.mock('cozy-device-helper')

const homeHref = 'foo'
const expectedCall = 'backToHome'
Expand All @@ -11,28 +13,32 @@ const webviewContext = {

describe('ButtonCozyHome', () => {
it('should render a span with no props', () => {
isFlagshipApp.mockImplementation(() => false)
const render = shallow(<ButtonCozyHome />)
const element = render.getElement()

expect(element.type).toBe('span')
})

it('should render an anchor with correct href when homeHref', () => {
isFlagshipApp.mockImplementation(() => false)
const render = shallow(<ButtonCozyHome homeHref={homeHref} />)
const element = render.getElement()

expect(element.type).toBe('a')
expect(element.props.href).toBe(homeHref)
})

it('should render an anchor when webviewContext', () => {
it('should render an anchor when isFlagshipApp', () => {
isFlagshipApp.mockImplementation(() => true)
const render = shallow(<ButtonCozyHome webviewContext={webviewContext} />)
const element = render.getElement()

expect(element.type).toBe('a')
})

it('should give priority to anchor if both webviewContext and homeHref are present', () => {
it('should give priority to anchor if both isFlagshipApp and homeHref are present', () => {
isFlagshipApp.mockImplementation(() => true)
const render = shallow(
<ButtonCozyHome homeHref={homeHref} webviewContext={webviewContext} />
)
Expand All @@ -42,6 +48,7 @@ describe('ButtonCozyHome', () => {
})

it('should call the correct context method on click', () => {
isFlagshipApp.mockImplementation(() => true)
const render = shallow(
<ButtonCozyHome homeHref={homeHref} webviewContext={webviewContext} />
)
Expand Down
4 changes: 2 additions & 2 deletions src/components/Bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getTracker,
configureTracker
} from 'cozy-ui/react/helpers/tracker'
import { isMobileApp } from 'cozy-device-helper'
import { isFlagshipApp, isMobileApp } from 'cozy-device-helper'
import flag from 'cozy-flags'

import { ButtonCozyHome } from 'components/Apps/ButtonCozyHome'
Expand Down Expand Up @@ -168,7 +168,7 @@ export class Bar extends Component {
renderLeft = () => {
const { t, isPublic, webviewContext } = this.props

if (webviewContext || flag('flagship.debug')) {
if (isFlagshipApp() || flag('flagship.debug')) {
return <ButtonCozyHome webviewContext={webviewContext} />
}

Expand Down

0 comments on commit de2a530

Please sign in to comment.