Skip to content

Commit

Permalink
fix(getIconUrl): Add appData to getIconUrl
Browse files Browse the repository at this point in the history
CozyClient v27.19.1 is bound in order to get icon url mechanism working
  • Loading branch information
trollepierre committed Mar 2, 2022
1 parent b14fb86 commit ffb568c
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 13 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@
"commitlint": "7.6.1",
"commitlint-config-cozy": "0.6.0",
"copyfiles": "2.1.1",
"cozy-client": "^27.5.1",
"cozy-client": "27.19.1",
"cozy-device-helper": "^1.16.1",
"cozy-doctypes": "^1.69.0",
"cozy-harvest-lib": "^6.7.3",
"cozy-intent": "^1.6.0",
"cozy-sharing": "^3.10.0",
"cozy-stack-client": "27.19.1",
"css-loader": "0.28.11",
"cssnano": "4.1.11",
"cssnano-preset-advanced": "4.0.8",
Expand Down Expand Up @@ -168,7 +169,7 @@
},
"peerDependencies": {
"@material-ui/core": ">=4.12",
"cozy-client": ">=27.5.1",
"cozy-client": ">=27.19.1",
"cozy-device-helper": "^1.16.0",
"cozy-doctypes": "^1.69.0",
"cozy-harvest-lib": "^6.7.3",
Expand Down
2 changes: 2 additions & 0 deletions react/AppIcon/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class AppIcon extends Component {
return client.getStackClient().getIconURL({
type,
slug: app.slug || app,
appData: app,
priority
})
}
Expand All @@ -59,6 +60,7 @@ export class AppIcon extends Component {

async load() {
const { app, fetchIcon, onReady, client } = this.props

const loadFn = fetchIcon || this.fetchIcon
let loadedUrl
let loadError
Expand Down
38 changes: 38 additions & 0 deletions react/AppIcon/test/AppIcon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,44 @@ describe('AppIcon component', () => {
expect(console.error).not.toHaveBeenCalled()
})

it(`should provide appData to getIconUrl in order to get icon simply, when oauth not needed`, async done => {
const app = {
name: 'app name',
slug: 'slug',
links: {
icon: 'icon url'
},
latest_version: {
version: 'version'
}
}
const getIconURLMock = jest
.fn()
.mockImplementation(() => `https://${domain}`)
const mockClient = {
getStackClient: () => ({
uri: `https://${domain}`,
getIconURL: getIconURLMock
})
}
const wrapper = shallow(
<AppIcon
app={app}
client={mockClient}
onReady={() => {
wrapper.update()
expect(getIconURLMock).toHaveBeenNthCalledWith(1, {
appData: app,
priority: 'stack',
slug: 'slug',
type: 'app'
})
done()
}}
/>
)
})

it(`renders correctly`, async done => {
const wrapper = shallow(
<AppIcon
Expand Down
5 changes: 3 additions & 2 deletions react/CipherIcon/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Icon from '../Icon'
import { withClient } from 'cozy-client'
import { AppDoctype } from '../proptypes'

import KeychainIcon from 'cozy-ui/transpiled/react/Icons/Keychain'
import KeychainIcon from '../Icons/Keychain'

class CipherIcon extends React.PureComponent {
constructor(props) {
Expand All @@ -19,7 +19,8 @@ class CipherIcon extends React.PureComponent {

return client.stackClient.getIconURL({
type: 'konnector',
slug: konnector.slug || konnector
slug: konnector.slug || konnector,
appData: konnector
})
}

Expand Down
50 changes: 50 additions & 0 deletions react/CipherIcon/index.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react'
import { fireEvent, render } from '@testing-library/react'
import CipherIcon from './index'

jest.mock('cozy-client', () => ({
withClient: Component => {
const client = {
stackClient: {
getIconURL: ({ type, appData }) => {
console.log('getIconUrl called with:')
console.log(type)
console.log(appData)
}
}
}
return konnector => (
<Component client={client} konnector={{ ...konnector }} />
)
}
}))

jest.mock('../AppIcon', () => ({ fetchIcon }) => (
<button data-testid="app-icon" onClick={fetchIcon}></button>
))

describe('CipherIcon', () => {
it('should provide appData to getIconUrl in order to get icon simply, when oauth not needed', () => {
// Given
jest.spyOn(console, 'log').mockImplementation()
const konnector = {
name: 'PropTypes.string',
slug: 'slug',
links: {
icon: 'icon url'
},
latest_version: {
version: 'version'
}
}
const { getByTestId } = render(<CipherIcon konnector={konnector} />)

// When
fireEvent.click(getByTestId('app-icon'))

// Then
expect(console.log).toHaveBeenNthCalledWith(1, 'getIconUrl called with:')
expect(console.log).toHaveBeenNthCalledWith(2, 'konnector')
expect(console.log).toHaveBeenNthCalledWith(3, { konnector })
})
})
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5111,10 +5111,10 @@ cozy-bi-auth@0.0.23:
lodash "^4.17.20"
node-jose "^1.1.4"

cozy-client@^27.5.1:
version "27.5.1"
resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-27.5.1.tgz#5b4b81df34276115337404d4db903e92a5cfe635"
integrity sha512-HuRdqAKWb/5tjyZ5Vry4lVcTJtx71YOx0/K/KvX/4gvAxTwd2gPLb7nZfmB3kEtSzHDLq6F/mhgLLl0TDZfE3A==
cozy-client@27.19.1:
version "27.19.1"
resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-27.19.1.tgz#f7cab0257e290118e295d29436dd4731c014c7fc"
integrity sha512-kqDzQ/qgqwGBW6KTBppCxc1d00DEV1i0c7YpQXSAylTTXMk/FW6GF2Y51RJaESLYrTBJcLKmfkP79G/x0kQtrA==
dependencies:
"@cozy/minilog" "1.0.0"
"@types/jest" "^26.0.20"
Expand All @@ -5123,7 +5123,7 @@ cozy-client@^27.5.1:
cozy-device-helper "^1.12.0"
cozy-flags "2.7.1"
cozy-logger "^1.6.0"
cozy-stack-client "^27.1.0"
cozy-stack-client "^27.19.1"
json-stable-stringify "^1.0.1"
lodash "^4.17.13"
microee "^0.0.6"
Expand Down Expand Up @@ -5245,10 +5245,10 @@ cozy-sharing@^3.10.0:
react-tooltip "^3.11.1"
snarkdown "^2.0.0"

cozy-stack-client@^27.1.0:
version "27.1.0"
resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-27.1.0.tgz#facc296e99b666c5fd56e449c65f95decac6ec8b"
integrity sha512-fcZJpoUd5E+rDRwiuQ5Whjg+jJlxlC/xpmDjdph0mlyDshAP5B8pdNpPIm7MYhnUbcS97JEZHLcQntdKZnHz5Q==
cozy-stack-client@27.19.1, cozy-stack-client@^27.19.1:
version "27.19.1"
resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-27.19.1.tgz#679253c6e028273b480b350583627389d98c6a69"
integrity sha512-DdJCi0lHofWsnT4ZvX02uaELsvgNquuPFPaXulo8gw1x/mVoHsPn+Lpt9xCw35CvhJm3ajJQ709f7JT4lPbCSQ==
dependencies:
cozy-flags "2.7.1"
detect-node "^2.0.4"
Expand Down

0 comments on commit ffb568c

Please sign in to comment.