cozy-bar 1.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +7 -0
- package/.github/auto-merge.yml +7 -0
- package/.nvmrc +1 -0
- package/.transifexrc.tpl +4 -0
- package/.travis.yml +28 -0
- package/.tx/config +8 -0
- package/CHANGELOG.md +493 -0
- package/CODEOWNERS +2 -0
- package/CONTRIBUTING.md +135 -0
- package/LICENSE +21 -0
- package/README.md +172 -0
- package/babel.config.js +3 -0
- package/config/aliases/globalReact.js +1 -0
- package/config/aliases/globalReactDOM.js +1 -0
- package/config/webpack.config.analyzer.js +10 -0
- package/config/webpack.config.base.js +61 -0
- package/config/webpack.config.dev.js +16 -0
- package/config/webpack.config.extract.js +84 -0
- package/config/webpack.config.inline-styles.js +82 -0
- package/config/webpack.config.jsx.js +14 -0
- package/config/webpack.config.prod.js +18 -0
- package/config/webpack.js +31 -0
- package/config/webpack.vars.js +11 -0
- package/dist/cozy-bar.css +9445 -0
- package/dist/cozy-bar.css.map +1 -0
- package/dist/cozy-bar.js +122668 -0
- package/dist/cozy-bar.js.map +1 -0
- package/dist/cozy-bar.min.css +9 -0
- package/dist/cozy-bar.min.css.map +1 -0
- package/dist/cozy-bar.min.js +57 -0
- package/dist/cozy-bar.min.js.map +1 -0
- package/dist/cozy-bar.mobile.js +123719 -0
- package/dist/cozy-bar.mobile.js.map +1 -0
- package/dist/cozy-bar.mobile.min.js +57 -0
- package/dist/cozy-bar.mobile.min.js.map +1 -0
- package/docs/dev.md +20 -0
- package/examples/Procfile +3 -0
- package/examples/icon.png +0 -0
- package/examples/index.html +7 -0
- package/examples/index.jsx +122 -0
- package/examples/logs.js +3 -0
- package/package.json +163 -0
- package/postcss.config.js +23 -0
- package/public/fonts/Lato-Bold.woff2 +0 -0
- package/public/fonts/Lato-Regular.woff2 +0 -0
- package/public/fonts.css +13 -0
- package/public/icon-type-folder-32.png +0 -0
- package/public/index.html +63 -0
- package/renovate.json +5 -0
- package/src/assets/icons/16/icon-claudy.svg +5 -0
- package/src/assets/icons/16/icon-cozy-16.svg +1 -0
- package/src/assets/icons/16/icon-cube-16.svg +6 -0
- package/src/assets/icons/16/icon-logout-16.svg +3 -0
- package/src/assets/icons/16/icon-magnifier-16.svg +6 -0
- package/src/assets/icons/16/icon-people-16.svg +3 -0
- package/src/assets/icons/16/icon-phone-16.svg +3 -0
- package/src/assets/icons/16/icon-question-mark-16.svg +3 -0
- package/src/assets/icons/16/icon-storage-16.svg +3 -0
- package/src/assets/icons/24/icon-arrow-left.svg +3 -0
- package/src/assets/icons/32/icon-claudy.svg +1 -0
- package/src/assets/icons/apps/icon-collect.svg +25 -0
- package/src/assets/icons/apps/icon-drive.svg +17 -0
- package/src/assets/icons/apps/icon-market-soon.svg +25 -0
- package/src/assets/icons/apps/icon-photos.svg +19 -0
- package/src/assets/icons/apps/icon-soon.svg +21 -0
- package/src/assets/icons/apps/icon-store.svg +19 -0
- package/src/assets/icons/claudyActions/icon-bills.svg +6 -0
- package/src/assets/icons/claudyActions/icon-laptop.svg +7 -0
- package/src/assets/icons/claudyActions/icon-phone.svg +8 -0
- package/src/assets/icons/claudyActions/icon-question-mark.svg +6 -0
- package/src/assets/icons/comingsoon/icon-bank.svg +12 -0
- package/src/assets/icons/comingsoon/icon-sante.svg +12 -0
- package/src/assets/icons/comingsoon/icon-store.svg +6 -0
- package/src/assets/icons/icon-cozy.svg +3 -0
- package/src/assets/icons/icon-shield.svg +3 -0
- package/src/assets/icons/spinner.svg +4 -0
- package/src/assets/sprites/icon-apps.svg +1 -0
- package/src/assets/sprites/icon-cozy-home.svg +16 -0
- package/src/components/Apps/AppItem.jsx +117 -0
- package/src/components/Apps/AppItemPlaceholder.jsx +12 -0
- package/src/components/Apps/AppNavButtons.jsx +88 -0
- package/src/components/Apps/AppsContent.jsx +89 -0
- package/src/components/Apps/ButtonCozyHome.jsx +30 -0
- package/src/components/Apps/ButtonCozyHome.spec.jsx +53 -0
- package/src/components/Apps/IconCozyHome.jsx +24 -0
- package/src/components/Apps/index.jsx +81 -0
- package/src/components/Banner.jsx +41 -0
- package/src/components/Bar.jsx +293 -0
- package/src/components/Bar.spec.jsx +133 -0
- package/src/components/Claudy.jsx +81 -0
- package/src/components/Drawer.jsx +227 -0
- package/src/components/Drawer.spec.jsx +98 -0
- package/src/components/SearchBar.jsx +358 -0
- package/src/components/Settings/SettingsContent.jsx +145 -0
- package/src/components/Settings/StorageData.jsx +29 -0
- package/src/components/Settings/helper.js +8 -0
- package/src/components/Settings/index.jsx +218 -0
- package/src/components/SupportModal.jsx +59 -0
- package/src/components/__snapshots__/Bar.spec.jsx.snap +302 -0
- package/src/config/claudyActions.yaml +14 -0
- package/src/config/persistWhitelist.yaml +2 -0
- package/src/dom.js +80 -0
- package/src/index.jsx +235 -0
- package/src/index.spec.jsx +34 -0
- package/src/lib/api/helpers.js +13 -0
- package/src/lib/api/index.jsx +145 -0
- package/src/lib/exceptions.js +89 -0
- package/src/lib/expiringMemoize.js +13 -0
- package/src/lib/icon.js +77 -0
- package/src/lib/importIcons.js +14 -0
- package/src/lib/intents.js +16 -0
- package/src/lib/logger.js +6 -0
- package/src/lib/middlewares/appsI18n.js +57 -0
- package/src/lib/realtime.js +43 -0
- package/src/lib/reducers/apps.js +175 -0
- package/src/lib/reducers/apps.spec.js +59 -0
- package/src/lib/reducers/content.js +50 -0
- package/src/lib/reducers/context.js +83 -0
- package/src/lib/reducers/index.js +73 -0
- package/src/lib/reducers/locale.js +22 -0
- package/src/lib/reducers/settings.js +111 -0
- package/src/lib/reducers/theme.js +48 -0
- package/src/lib/reducers/unserializable.js +26 -0
- package/src/lib/stack-client.js +401 -0
- package/src/lib/stack.js +79 -0
- package/src/lib/store/index.js +54 -0
- package/src/locales/de.json +57 -0
- package/src/locales/en.json +57 -0
- package/src/locales/es.json +57 -0
- package/src/locales/fr.json +57 -0
- package/src/locales/it.json +57 -0
- package/src/locales/ja.json +57 -0
- package/src/locales/nl_NL.json +57 -0
- package/src/locales/pl.json +57 -0
- package/src/locales/ru.json +57 -0
- package/src/locales/sq.json +57 -0
- package/src/locales/zh_CN.json +57 -0
- package/src/proptypes/index.js +10 -0
- package/src/queries/index.js +16 -0
- package/src/styles/apps.css +248 -0
- package/src/styles/banner.css +64 -0
- package/src/styles/bar.css +106 -0
- package/src/styles/base.css +41 -0
- package/src/styles/claudy.css +99 -0
- package/src/styles/drawer.css +126 -0
- package/src/styles/index.styl +33 -0
- package/src/styles/indicators.css +58 -0
- package/src/styles/nav.css +81 -0
- package/src/styles/navigation_item.css +39 -0
- package/src/styles/searchbar.css +158 -0
- package/src/styles/settings.css +44 -0
- package/src/styles/storage.css +22 -0
- package/src/styles/supportModal.css +20 -0
- package/src/styles/theme.styl +25 -0
- package/test/__mocks__/fileMock.js +3 -0
- package/test/__snapshots__/index.spec.js.snap +41 -0
- package/test/components/AppItem.spec.jsx +113 -0
- package/test/components/AppsContent.spec.jsx +116 -0
- package/test/components/Settings/helper.spec.js +23 -0
- package/test/components/__snapshots__/AppsContent.spec.jsx.snap +90 -0
- package/test/index.spec.js +24 -0
- package/test/jestLib/I18n.js +15 -0
- package/test/jestLib/setup.js +14 -0
- package/test/lib/__snapshots__/api.spec.jsx.snap +67 -0
- package/test/lib/__snapshots__/stack.spec.js.snap +3 -0
- package/test/lib/api.spec.jsx +142 -0
- package/test/lib/mockStackClient.js +7 -0
- package/test/lib/stack-client/stack-client.appiconprops.spec.js +65 -0
- package/test/lib/stack-client/stack-client.compare.spec.js +20 -0
- package/test/lib/stack-client/stack-client.cozyfetchjson.spec.js +46 -0
- package/test/lib/stack-client/stack-client.cozyurl.spec.js +29 -0
- package/test/lib/stack-client/stack-client.getapp.spec.js +72 -0
- package/test/lib/stack-client/stack-client.getapps.spec.js +72 -0
- package/test/lib/stack-client/stack-client.getcontext.spec.js +96 -0
- package/test/lib/stack-client/stack-client.getstoragedata.spec.js +85 -0
- package/test/lib/stack-client/stack-client.init.spec.js +56 -0
- package/test/lib/stack-client/stack-client.intents.spec.js +27 -0
- package/test/lib/stack-client/stack-client.logout.spec.js +40 -0
- package/test/lib/stack.spec.js +60 -0
- package/test/store/__snapshots__/index.spec.js.snap +14 -0
- package/test/store/index.spec.js +41 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { AppsContent } from 'components/Apps/AppsContent'
|
|
3
|
+
import { shallow } from 'enzyme'
|
|
4
|
+
import { tMock } from '../jestLib/I18n'
|
|
5
|
+
|
|
6
|
+
describe('Apps Content', () => {
|
|
7
|
+
it('should render no App', () => {
|
|
8
|
+
const root = shallow(
|
|
9
|
+
<AppsContent
|
|
10
|
+
t={tMock}
|
|
11
|
+
breakpoints={{ isMobile: true }}
|
|
12
|
+
isFetchingApps={false}
|
|
13
|
+
/>
|
|
14
|
+
)
|
|
15
|
+
expect(root.getElement()).toMatchSnapshot()
|
|
16
|
+
})
|
|
17
|
+
it('should render display Drive', () => {
|
|
18
|
+
const apps = [
|
|
19
|
+
{
|
|
20
|
+
slug: 'cozy-drive',
|
|
21
|
+
name: 'Drive'
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
const root = shallow(
|
|
25
|
+
<AppsContent
|
|
26
|
+
t={tMock}
|
|
27
|
+
apps={apps}
|
|
28
|
+
breakpoints={{ isMobile: true }}
|
|
29
|
+
isFetchingApps={false}
|
|
30
|
+
/>
|
|
31
|
+
)
|
|
32
|
+
expect(root.getElement()).toMatchSnapshot()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('should render Loader when fetching', () => {
|
|
36
|
+
const apps = [
|
|
37
|
+
{
|
|
38
|
+
slug: 'cozy-drive',
|
|
39
|
+
name: 'Drive'
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
const root = shallow(
|
|
43
|
+
<AppsContent
|
|
44
|
+
t={tMock}
|
|
45
|
+
apps={apps}
|
|
46
|
+
breakpoints={{ isMobile: true }}
|
|
47
|
+
isFetchingApps={true}
|
|
48
|
+
/>
|
|
49
|
+
)
|
|
50
|
+
expect(root.getElement()).toMatchSnapshot()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('should display home in the app items lists, if we are on mobile', () => {
|
|
54
|
+
const apps = [
|
|
55
|
+
{
|
|
56
|
+
slug: 'cozy-home',
|
|
57
|
+
name: 'Home'
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
const root = shallow(
|
|
61
|
+
<AppsContent
|
|
62
|
+
t={tMock}
|
|
63
|
+
apps={apps}
|
|
64
|
+
homeApp={{
|
|
65
|
+
slug: 'cozy-home'
|
|
66
|
+
}}
|
|
67
|
+
breakpoints={{ isMobile: true }}
|
|
68
|
+
isFetchingApps={false}
|
|
69
|
+
/>
|
|
70
|
+
)
|
|
71
|
+
expect(root.getElement()).toMatchSnapshot()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('should not display home within the app items list, but just a link', () => {
|
|
75
|
+
const apps = [
|
|
76
|
+
{
|
|
77
|
+
slug: 'cozy-home',
|
|
78
|
+
name: 'Home'
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
const root = shallow(
|
|
82
|
+
<AppsContent
|
|
83
|
+
t={tMock}
|
|
84
|
+
apps={apps}
|
|
85
|
+
homeApp={{
|
|
86
|
+
slug: 'cozy-home'
|
|
87
|
+
}}
|
|
88
|
+
breakpoints={{ isMobile: false }}
|
|
89
|
+
isFetchingApps={false}
|
|
90
|
+
/>
|
|
91
|
+
)
|
|
92
|
+
expect(root.getElement()).toMatchSnapshot()
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('should not display home if not on mobile and home is the currentApp', () => {
|
|
96
|
+
const apps = [
|
|
97
|
+
{
|
|
98
|
+
slug: 'cozy-home',
|
|
99
|
+
name: 'Home'
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
const root = shallow(
|
|
103
|
+
<AppsContent
|
|
104
|
+
t={tMock}
|
|
105
|
+
apps={apps}
|
|
106
|
+
homeApp={{
|
|
107
|
+
slug: 'cozy-home',
|
|
108
|
+
isCurrentApp: true
|
|
109
|
+
}}
|
|
110
|
+
breakpoints={{ isMobile: false }}
|
|
111
|
+
isFetchingApps={false}
|
|
112
|
+
/>
|
|
113
|
+
)
|
|
114
|
+
expect(root.getElement()).toMatchSnapshot()
|
|
115
|
+
})
|
|
116
|
+
})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isFetchingQueries } from 'components/Settings/helper'
|
|
2
|
+
|
|
3
|
+
describe('Settings Helper', () => {
|
|
4
|
+
it('should return true if isFetchingQueries', () => {
|
|
5
|
+
const fakeRequest1 = {
|
|
6
|
+
fetchStatus: 'loading'
|
|
7
|
+
}
|
|
8
|
+
const fakeRequest2 = {
|
|
9
|
+
fetchStatus: 'loaded'
|
|
10
|
+
}
|
|
11
|
+
expect(isFetchingQueries([fakeRequest1, fakeRequest2])).toBe(true)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('should not return true if not fetching', () => {
|
|
15
|
+
const fakeRequest1 = {
|
|
16
|
+
fetchStatus: 'loaded'
|
|
17
|
+
}
|
|
18
|
+
const fakeRequest2 = {
|
|
19
|
+
fetchStatus: 'loaded'
|
|
20
|
+
}
|
|
21
|
+
expect(isFetchingQueries([fakeRequest1, fakeRequest2])).toBe(false)
|
|
22
|
+
})
|
|
23
|
+
})
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Apps Content should display home in the app items lists, if we are on mobile 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
className="coz-nav-pop-content"
|
|
6
|
+
>
|
|
7
|
+
<ul
|
|
8
|
+
className="coz-nav-group"
|
|
9
|
+
>
|
|
10
|
+
<AppItem
|
|
11
|
+
app={
|
|
12
|
+
Object {
|
|
13
|
+
"slug": "cozy-home",
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
useHomeIcon={true}
|
|
17
|
+
/>
|
|
18
|
+
</ul>
|
|
19
|
+
</div>
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
exports[`Apps Content should not display home if not on mobile and home is the currentApp 1`] = `
|
|
23
|
+
<div
|
|
24
|
+
className="coz-nav-pop-content"
|
|
25
|
+
>
|
|
26
|
+
<ul
|
|
27
|
+
className="coz-nav-group"
|
|
28
|
+
/>
|
|
29
|
+
</div>
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
exports[`Apps Content should not display home within the app items list, but just a link 1`] = `
|
|
33
|
+
<div
|
|
34
|
+
className="coz-nav-pop-content"
|
|
35
|
+
>
|
|
36
|
+
<ul
|
|
37
|
+
className="coz-nav-group"
|
|
38
|
+
/>
|
|
39
|
+
<a
|
|
40
|
+
className="coz-apps-home-btn"
|
|
41
|
+
role="menuitem"
|
|
42
|
+
>
|
|
43
|
+
<img
|
|
44
|
+
src="test-file-stub"
|
|
45
|
+
/>
|
|
46
|
+
Back to home
|
|
47
|
+
</a>
|
|
48
|
+
</div>
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
exports[`Apps Content should render Loader when fetching 1`] = `
|
|
52
|
+
<div
|
|
53
|
+
className="coz-nav-pop-content"
|
|
54
|
+
>
|
|
55
|
+
<ul
|
|
56
|
+
className="coz-nav-group"
|
|
57
|
+
>
|
|
58
|
+
<AppItemPlaceholder />
|
|
59
|
+
<AppItemPlaceholder />
|
|
60
|
+
<AppItemPlaceholder />
|
|
61
|
+
</ul>
|
|
62
|
+
</div>
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
exports[`Apps Content should render display Drive 1`] = `
|
|
66
|
+
<div
|
|
67
|
+
className="coz-nav-pop-content"
|
|
68
|
+
>
|
|
69
|
+
<ul
|
|
70
|
+
className="coz-nav-group"
|
|
71
|
+
>
|
|
72
|
+
<AppItem
|
|
73
|
+
app={
|
|
74
|
+
Object {
|
|
75
|
+
"name": "Drive",
|
|
76
|
+
"slug": "cozy-drive",
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/>
|
|
80
|
+
</ul>
|
|
81
|
+
</div>
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
exports[`Apps Content should render no App 1`] = `
|
|
85
|
+
<p
|
|
86
|
+
className="coz-nav--error coz-nav-group"
|
|
87
|
+
>
|
|
88
|
+
No applications found on the Cozy.
|
|
89
|
+
</p>
|
|
90
|
+
`;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { init } from '../src'
|
|
2
|
+
import Enzyme, { mount } from 'enzyme'
|
|
3
|
+
import Adapter from 'enzyme-adapter-react-16'
|
|
4
|
+
|
|
5
|
+
Enzyme.configure({ adapter: new Adapter() })
|
|
6
|
+
|
|
7
|
+
describe('The bar library', function() {
|
|
8
|
+
xit('should render correctly the cozy-bar', () => {
|
|
9
|
+
// Set up our document body
|
|
10
|
+
document.body.innerHTML =
|
|
11
|
+
'<div role="application">' + ' The application will be here' + '</div>'
|
|
12
|
+
const options = {
|
|
13
|
+
appName: 'test-app',
|
|
14
|
+
appNamePrefix: 'cozy',
|
|
15
|
+
lang: 'en',
|
|
16
|
+
iconPath: '',
|
|
17
|
+
cozyURL: 'https://mock.cozy',
|
|
18
|
+
token: 'mock'
|
|
19
|
+
}
|
|
20
|
+
const Bar = init(options)
|
|
21
|
+
const mounted = mount(Bar)
|
|
22
|
+
expect(mounted.getElement()).toMatchSnapshot()
|
|
23
|
+
})
|
|
24
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { I18n } from 'cozy-ui/react/I18n'
|
|
4
|
+
|
|
5
|
+
const I18nComponent = new I18n({
|
|
6
|
+
lang: 'en',
|
|
7
|
+
defaultLang: 'en',
|
|
8
|
+
dictRequire: lang => require(`../../src/locales/${lang}`)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const context = I18nComponent.getChildContext()
|
|
12
|
+
|
|
13
|
+
export const tMock = context.t
|
|
14
|
+
|
|
15
|
+
export const fMock = context.f
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Enzyme from 'enzyme'
|
|
2
|
+
import Adapter from 'enzyme-adapter-react-16'
|
|
3
|
+
|
|
4
|
+
import '@babel/polyfill'
|
|
5
|
+
|
|
6
|
+
// polyfill for requestAnimationFrame
|
|
7
|
+
/* istanbul ignore next */
|
|
8
|
+
global.requestAnimationFrame = cb => {
|
|
9
|
+
setTimeout(cb, 0)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Enzyme.configure({ adapter: new Adapter() })
|
|
13
|
+
|
|
14
|
+
process.env.USE_REACT = true
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`api spec should set content of the store via declarative api 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
Left
|
|
6
|
+
</div>
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
exports[`api spec should set content of the store via declarative api 2`] = `
|
|
10
|
+
<div>
|
|
11
|
+
<p>
|
|
12
|
+
Center
|
|
13
|
+
</p>
|
|
14
|
+
</div>
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
exports[`api spec should set content of the store via declarative api 3`] = `
|
|
18
|
+
<div>
|
|
19
|
+
<div>
|
|
20
|
+
test3
|
|
21
|
+
<span>
|
|
22
|
+
Right
|
|
23
|
+
</span>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
exports[`api spec should set content of the store via declarative api 4`] = `
|
|
29
|
+
<div>
|
|
30
|
+
Search
|
|
31
|
+
</div>
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
exports[`api spec should set content of the store via imperative api 1`] = `
|
|
35
|
+
<span
|
|
36
|
+
dangerouslySetInnerHTML={
|
|
37
|
+
Object {
|
|
38
|
+
"__html": "Left",
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/>
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
exports[`api spec should set content of the store via imperative api 2`] = `
|
|
45
|
+
<p>
|
|
46
|
+
Center
|
|
47
|
+
</p>
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
exports[`api spec should set content of the store via imperative api 3`] = `
|
|
51
|
+
<div>
|
|
52
|
+
test3
|
|
53
|
+
<span>
|
|
54
|
+
Right
|
|
55
|
+
</span>
|
|
56
|
+
</div>
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
exports[`api spec should set content of the store via imperative api 4`] = `
|
|
60
|
+
<span
|
|
61
|
+
dangerouslySetInnerHTML={
|
|
62
|
+
Object {
|
|
63
|
+
"__html": "Search",
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/>
|
|
67
|
+
`;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { shallow } from 'enzyme'
|
|
3
|
+
|
|
4
|
+
import createStore from 'lib/store'
|
|
5
|
+
import { createBarAPI } from 'lib/api'
|
|
6
|
+
import appReducers, { getContent as _getContent } from 'lib/reducers'
|
|
7
|
+
import { getDefaultState } from 'lib/reducers/content'
|
|
8
|
+
import { locations, getJsApiName, getReactApiName } from 'lib/api/helpers'
|
|
9
|
+
|
|
10
|
+
const store = createStore()
|
|
11
|
+
const api = createBarAPI(store)
|
|
12
|
+
|
|
13
|
+
// add test reducer to reset state
|
|
14
|
+
const RESET_API = 'RESET_API'
|
|
15
|
+
const testReducer = (state, action) => {
|
|
16
|
+
if (action.type === RESET_API) {
|
|
17
|
+
const newState = Object.assign({}, state, {
|
|
18
|
+
content: getDefaultState()
|
|
19
|
+
})
|
|
20
|
+
return newState
|
|
21
|
+
}
|
|
22
|
+
return appReducers(state, action)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
store.replaceReducer(testReducer)
|
|
26
|
+
|
|
27
|
+
const getContent = location => {
|
|
28
|
+
return _getContent(store.getState(), location)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const contentToTest = {
|
|
32
|
+
left: 'Left',
|
|
33
|
+
center: <p>Center</p>,
|
|
34
|
+
right: (
|
|
35
|
+
<div>
|
|
36
|
+
test3
|
|
37
|
+
<span>Right</span>
|
|
38
|
+
</div>
|
|
39
|
+
),
|
|
40
|
+
search: 'Search'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('api spec', function() {
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
store.dispatch({
|
|
46
|
+
type: RESET_API
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('should set content of the store via imperative api', function() {
|
|
51
|
+
locations.map(location => {
|
|
52
|
+
api[getJsApiName(location)](contentToTest[location])
|
|
53
|
+
expect(getContent(location)).toMatchSnapshot()
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('should set content of the store via declarative api', function() {
|
|
58
|
+
locations.map(location => {
|
|
59
|
+
const BarAPI = api[getReactApiName(location)]
|
|
60
|
+
shallow(
|
|
61
|
+
<BarAPI>
|
|
62
|
+
<div>{contentToTest[location]}</div>
|
|
63
|
+
</BarAPI>
|
|
64
|
+
)
|
|
65
|
+
expect(getContent(location)).toMatchSnapshot()
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('should replace content of the store instead of adding new entry', function() {
|
|
70
|
+
locations.map(location => {
|
|
71
|
+
const BarAPI = api[getReactApiName(location)]
|
|
72
|
+
const barComponent = shallow(
|
|
73
|
+
<BarAPI>
|
|
74
|
+
<div>{contentToTest[location]}</div>
|
|
75
|
+
</BarAPI>
|
|
76
|
+
)
|
|
77
|
+
const initialContent = getContent(location)
|
|
78
|
+
// update content
|
|
79
|
+
expect(initialContent).toEqual(getContent(location))
|
|
80
|
+
expect(store.getState().content[location].size).toBe(1)
|
|
81
|
+
barComponent.setProps({
|
|
82
|
+
children: <div>Left Updated</div>
|
|
83
|
+
})
|
|
84
|
+
// content has correctly be updated
|
|
85
|
+
expect(initialContent).not.toEqual(getContent(location))
|
|
86
|
+
// but no new content added, it was replaced in the state
|
|
87
|
+
expect(store.getState().content[location].size).toBe(1)
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('should unset content of the store on unmount', function() {
|
|
92
|
+
locations.map(location => {
|
|
93
|
+
const BarAPI = api[getReactApiName(location)]
|
|
94
|
+
const barComponent = shallow(
|
|
95
|
+
<BarAPI>
|
|
96
|
+
<div>{contentToTest[location]}</div>
|
|
97
|
+
</BarAPI>
|
|
98
|
+
)
|
|
99
|
+
expect(store.getState().content[location].size).toBe(1)
|
|
100
|
+
// unmount
|
|
101
|
+
barComponent.unmount()
|
|
102
|
+
expect(store.getState().content[location].size).toBe(0)
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('should set locale', function() {
|
|
107
|
+
const { setLocale } = api
|
|
108
|
+
// default lang is `en`
|
|
109
|
+
expect(store.getState().locale).toBe('en')
|
|
110
|
+
setLocale('fr')
|
|
111
|
+
expect(store.getState().locale).toBe('fr')
|
|
112
|
+
setLocale('de')
|
|
113
|
+
expect(store.getState().locale).toBe('de')
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('should set theme', function() {
|
|
117
|
+
const { setTheme } = api
|
|
118
|
+
// default theme is `default`
|
|
119
|
+
expect(store.getState().theme.name).toBe('default')
|
|
120
|
+
expect(store.getState().theme.overrides).toEqual({})
|
|
121
|
+
setTheme('primary')
|
|
122
|
+
expect(store.getState().theme.name).toBe('primary')
|
|
123
|
+
expect(store.getState().theme.overrides).toEqual({})
|
|
124
|
+
setTheme('primary', { primaryColor: 'red' })
|
|
125
|
+
expect(store.getState().theme.name).toBe('primary')
|
|
126
|
+
expect(store.getState().theme.overrides).toEqual({ primaryColor: 'red' })
|
|
127
|
+
setTheme('wrongTheme')
|
|
128
|
+
expect(store.getState().theme.name).toBe('default')
|
|
129
|
+
expect(store.getState().theme.overrides).toEqual({})
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('should set webviewContext', function() {
|
|
133
|
+
const { setWebviewContext } = api
|
|
134
|
+
// default webviewContext is `undefined`
|
|
135
|
+
expect(store.getState().unserializable.webviewContext).toBe(undefined)
|
|
136
|
+
setWebviewContext('foo')
|
|
137
|
+
expect(store.getState().unserializable.webviewContext).toBe('foo')
|
|
138
|
+
setWebviewContext('bar')
|
|
139
|
+
expect(store.getState().unserializable.webviewContext).toBe('bar')
|
|
140
|
+
setWebviewContext(undefined)
|
|
141
|
+
})
|
|
142
|
+
})
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import CozyClient from 'cozy-client'
|
|
2
|
+
import stack from 'lib/stack-client'
|
|
3
|
+
import { isMobileApp } from 'cozy-device-helper'
|
|
4
|
+
|
|
5
|
+
import mockStackClient from '../mockStackClient'
|
|
6
|
+
|
|
7
|
+
jest.mock('cozy-device-helper', () => ({
|
|
8
|
+
...require.requireActual('cozy-device-helper'),
|
|
9
|
+
isMobileApp: jest.fn()
|
|
10
|
+
}))
|
|
11
|
+
|
|
12
|
+
describe('stack client', () => {
|
|
13
|
+
describe('getAppIconProps', () => {
|
|
14
|
+
const cozyClient = new CozyClient({
|
|
15
|
+
stackClient: mockStackClient
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const params = {
|
|
19
|
+
cozyClient,
|
|
20
|
+
onCreateApp: function() {},
|
|
21
|
+
onDeleteApp: function() {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
beforeAll(async () => {
|
|
25
|
+
await stack.init(params)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
afterAll(() => {
|
|
29
|
+
jest.restoreAllMocks()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
describe('for target=browser', () => {
|
|
33
|
+
beforeAll(() => {
|
|
34
|
+
isMobileApp.mockReturnValue(false)
|
|
35
|
+
})
|
|
36
|
+
it('should have `domain` and `secure` set', () => {
|
|
37
|
+
const data = stack.get.iconProps()
|
|
38
|
+
expect(data.domain).toBe('test.mycozy.cloud')
|
|
39
|
+
expect(data.secure).toBe(true)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should not have a `fetchIcon` function', () => {
|
|
43
|
+
const data = stack.get.iconProps()
|
|
44
|
+
expect(data.fetchIcon).toBe(undefined)
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
describe('for target=mobile', () => {
|
|
49
|
+
beforeAll(() => {
|
|
50
|
+
isMobileApp.mockReturnValue(true)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('should not have `domain` and `secure` set', () => {
|
|
54
|
+
const data = stack.get.iconProps()
|
|
55
|
+
expect(data.domain).toBeUndefined()
|
|
56
|
+
expect(data.secure).toBeUndefined()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('should have a `fetchIcon` function set', () => {
|
|
60
|
+
const data = stack.get.iconProps()
|
|
61
|
+
expect(data.fetchIcon).toBeInstanceOf(Function)
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { compareClientVersion } from 'lib/stack-client'
|
|
2
|
+
|
|
3
|
+
describe('stack client', () => {
|
|
4
|
+
describe('compareClientVersion', () => {
|
|
5
|
+
it('should compare to target versions', () => {
|
|
6
|
+
const targetVersion = '6.7.8'
|
|
7
|
+
const CozyClient = {
|
|
8
|
+
version: '5.1.0'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
expect(compareClientVersion(targetVersion, CozyClient)).toBe(false)
|
|
12
|
+
|
|
13
|
+
CozyClient.version = targetVersion
|
|
14
|
+
expect(compareClientVersion(targetVersion, CozyClient)).toBe(true)
|
|
15
|
+
|
|
16
|
+
CozyClient.version = '10.7.8'
|
|
17
|
+
expect(compareClientVersion(targetVersion, CozyClient)).toBe(true)
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import stack from 'lib/stack-client'
|
|
2
|
+
import CozyClient from 'cozy-client'
|
|
3
|
+
import mockStackClient from '../mockStackClient'
|
|
4
|
+
|
|
5
|
+
describe('stack client', () => {
|
|
6
|
+
describe('cozyFetchJSON', () => {
|
|
7
|
+
let json = jest.fn().mockReturnValue({
|
|
8
|
+
data: { id: 'myid' }
|
|
9
|
+
})
|
|
10
|
+
let fetch = jest.fn().mockResolvedValue({
|
|
11
|
+
status: 200,
|
|
12
|
+
headers: {
|
|
13
|
+
get: () => 'application/json'
|
|
14
|
+
},
|
|
15
|
+
json
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
let cozyClient = new CozyClient({
|
|
19
|
+
stackClient: {
|
|
20
|
+
...mockStackClient,
|
|
21
|
+
fetch
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
let params = {
|
|
26
|
+
cozyClient,
|
|
27
|
+
onCreateApp: function() {},
|
|
28
|
+
onDeleteApp: function() {}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
beforeAll(async () => {
|
|
32
|
+
await stack.init(params)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('should transform `id` in `_id`', async () => {
|
|
36
|
+
const data = await stack.cozyFetchJSON('_', 'GET', '/path')
|
|
37
|
+
expect(data._id).toBe('myid')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('should call fetch from cozy-client', async () => {
|
|
41
|
+
fetch.mockClear()
|
|
42
|
+
await stack.cozyFetchJSON('_', 'GET', '/path')
|
|
43
|
+
expect(fetch).toHaveBeenCalled()
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import stack from 'lib/stack-client'
|
|
2
|
+
import CozyClient from 'cozy-client'
|
|
3
|
+
import mockStackClient from '../mockStackClient'
|
|
4
|
+
|
|
5
|
+
describe('stack client', () => {
|
|
6
|
+
describe('cozyURL', () => {
|
|
7
|
+
const cozyClient = new CozyClient({
|
|
8
|
+
stackClient: mockStackClient
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const params = {
|
|
12
|
+
cozyClient,
|
|
13
|
+
onCreateApp: function() {},
|
|
14
|
+
onDeleteApp: function() {}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
beforeAll(async () => {
|
|
18
|
+
await stack.init(params)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
afterAll(() => {
|
|
22
|
+
jest.restoreAllMocks()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('should give back the origin of cozy-client', () => {
|
|
26
|
+
expect(stack.get.cozyURL()).toBe('https://test.mycozy.cloud')
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
})
|