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.
Files changed (181) hide show
  1. package/.eslintrc.json +7 -0
  2. package/.github/auto-merge.yml +7 -0
  3. package/.nvmrc +1 -0
  4. package/.transifexrc.tpl +4 -0
  5. package/.travis.yml +28 -0
  6. package/.tx/config +8 -0
  7. package/CHANGELOG.md +493 -0
  8. package/CODEOWNERS +2 -0
  9. package/CONTRIBUTING.md +135 -0
  10. package/LICENSE +21 -0
  11. package/README.md +172 -0
  12. package/babel.config.js +3 -0
  13. package/config/aliases/globalReact.js +1 -0
  14. package/config/aliases/globalReactDOM.js +1 -0
  15. package/config/webpack.config.analyzer.js +10 -0
  16. package/config/webpack.config.base.js +61 -0
  17. package/config/webpack.config.dev.js +16 -0
  18. package/config/webpack.config.extract.js +84 -0
  19. package/config/webpack.config.inline-styles.js +82 -0
  20. package/config/webpack.config.jsx.js +14 -0
  21. package/config/webpack.config.prod.js +18 -0
  22. package/config/webpack.js +31 -0
  23. package/config/webpack.vars.js +11 -0
  24. package/dist/cozy-bar.css +9445 -0
  25. package/dist/cozy-bar.css.map +1 -0
  26. package/dist/cozy-bar.js +122668 -0
  27. package/dist/cozy-bar.js.map +1 -0
  28. package/dist/cozy-bar.min.css +9 -0
  29. package/dist/cozy-bar.min.css.map +1 -0
  30. package/dist/cozy-bar.min.js +57 -0
  31. package/dist/cozy-bar.min.js.map +1 -0
  32. package/dist/cozy-bar.mobile.js +123719 -0
  33. package/dist/cozy-bar.mobile.js.map +1 -0
  34. package/dist/cozy-bar.mobile.min.js +57 -0
  35. package/dist/cozy-bar.mobile.min.js.map +1 -0
  36. package/docs/dev.md +20 -0
  37. package/examples/Procfile +3 -0
  38. package/examples/icon.png +0 -0
  39. package/examples/index.html +7 -0
  40. package/examples/index.jsx +122 -0
  41. package/examples/logs.js +3 -0
  42. package/package.json +163 -0
  43. package/postcss.config.js +23 -0
  44. package/public/fonts/Lato-Bold.woff2 +0 -0
  45. package/public/fonts/Lato-Regular.woff2 +0 -0
  46. package/public/fonts.css +13 -0
  47. package/public/icon-type-folder-32.png +0 -0
  48. package/public/index.html +63 -0
  49. package/renovate.json +5 -0
  50. package/src/assets/icons/16/icon-claudy.svg +5 -0
  51. package/src/assets/icons/16/icon-cozy-16.svg +1 -0
  52. package/src/assets/icons/16/icon-cube-16.svg +6 -0
  53. package/src/assets/icons/16/icon-logout-16.svg +3 -0
  54. package/src/assets/icons/16/icon-magnifier-16.svg +6 -0
  55. package/src/assets/icons/16/icon-people-16.svg +3 -0
  56. package/src/assets/icons/16/icon-phone-16.svg +3 -0
  57. package/src/assets/icons/16/icon-question-mark-16.svg +3 -0
  58. package/src/assets/icons/16/icon-storage-16.svg +3 -0
  59. package/src/assets/icons/24/icon-arrow-left.svg +3 -0
  60. package/src/assets/icons/32/icon-claudy.svg +1 -0
  61. package/src/assets/icons/apps/icon-collect.svg +25 -0
  62. package/src/assets/icons/apps/icon-drive.svg +17 -0
  63. package/src/assets/icons/apps/icon-market-soon.svg +25 -0
  64. package/src/assets/icons/apps/icon-photos.svg +19 -0
  65. package/src/assets/icons/apps/icon-soon.svg +21 -0
  66. package/src/assets/icons/apps/icon-store.svg +19 -0
  67. package/src/assets/icons/claudyActions/icon-bills.svg +6 -0
  68. package/src/assets/icons/claudyActions/icon-laptop.svg +7 -0
  69. package/src/assets/icons/claudyActions/icon-phone.svg +8 -0
  70. package/src/assets/icons/claudyActions/icon-question-mark.svg +6 -0
  71. package/src/assets/icons/comingsoon/icon-bank.svg +12 -0
  72. package/src/assets/icons/comingsoon/icon-sante.svg +12 -0
  73. package/src/assets/icons/comingsoon/icon-store.svg +6 -0
  74. package/src/assets/icons/icon-cozy.svg +3 -0
  75. package/src/assets/icons/icon-shield.svg +3 -0
  76. package/src/assets/icons/spinner.svg +4 -0
  77. package/src/assets/sprites/icon-apps.svg +1 -0
  78. package/src/assets/sprites/icon-cozy-home.svg +16 -0
  79. package/src/components/Apps/AppItem.jsx +117 -0
  80. package/src/components/Apps/AppItemPlaceholder.jsx +12 -0
  81. package/src/components/Apps/AppNavButtons.jsx +88 -0
  82. package/src/components/Apps/AppsContent.jsx +89 -0
  83. package/src/components/Apps/ButtonCozyHome.jsx +30 -0
  84. package/src/components/Apps/ButtonCozyHome.spec.jsx +53 -0
  85. package/src/components/Apps/IconCozyHome.jsx +24 -0
  86. package/src/components/Apps/index.jsx +81 -0
  87. package/src/components/Banner.jsx +41 -0
  88. package/src/components/Bar.jsx +293 -0
  89. package/src/components/Bar.spec.jsx +133 -0
  90. package/src/components/Claudy.jsx +81 -0
  91. package/src/components/Drawer.jsx +227 -0
  92. package/src/components/Drawer.spec.jsx +98 -0
  93. package/src/components/SearchBar.jsx +358 -0
  94. package/src/components/Settings/SettingsContent.jsx +145 -0
  95. package/src/components/Settings/StorageData.jsx +29 -0
  96. package/src/components/Settings/helper.js +8 -0
  97. package/src/components/Settings/index.jsx +218 -0
  98. package/src/components/SupportModal.jsx +59 -0
  99. package/src/components/__snapshots__/Bar.spec.jsx.snap +302 -0
  100. package/src/config/claudyActions.yaml +14 -0
  101. package/src/config/persistWhitelist.yaml +2 -0
  102. package/src/dom.js +80 -0
  103. package/src/index.jsx +235 -0
  104. package/src/index.spec.jsx +34 -0
  105. package/src/lib/api/helpers.js +13 -0
  106. package/src/lib/api/index.jsx +145 -0
  107. package/src/lib/exceptions.js +89 -0
  108. package/src/lib/expiringMemoize.js +13 -0
  109. package/src/lib/icon.js +77 -0
  110. package/src/lib/importIcons.js +14 -0
  111. package/src/lib/intents.js +16 -0
  112. package/src/lib/logger.js +6 -0
  113. package/src/lib/middlewares/appsI18n.js +57 -0
  114. package/src/lib/realtime.js +43 -0
  115. package/src/lib/reducers/apps.js +175 -0
  116. package/src/lib/reducers/apps.spec.js +59 -0
  117. package/src/lib/reducers/content.js +50 -0
  118. package/src/lib/reducers/context.js +83 -0
  119. package/src/lib/reducers/index.js +73 -0
  120. package/src/lib/reducers/locale.js +22 -0
  121. package/src/lib/reducers/settings.js +111 -0
  122. package/src/lib/reducers/theme.js +48 -0
  123. package/src/lib/reducers/unserializable.js +26 -0
  124. package/src/lib/stack-client.js +401 -0
  125. package/src/lib/stack.js +79 -0
  126. package/src/lib/store/index.js +54 -0
  127. package/src/locales/de.json +57 -0
  128. package/src/locales/en.json +57 -0
  129. package/src/locales/es.json +57 -0
  130. package/src/locales/fr.json +57 -0
  131. package/src/locales/it.json +57 -0
  132. package/src/locales/ja.json +57 -0
  133. package/src/locales/nl_NL.json +57 -0
  134. package/src/locales/pl.json +57 -0
  135. package/src/locales/ru.json +57 -0
  136. package/src/locales/sq.json +57 -0
  137. package/src/locales/zh_CN.json +57 -0
  138. package/src/proptypes/index.js +10 -0
  139. package/src/queries/index.js +16 -0
  140. package/src/styles/apps.css +248 -0
  141. package/src/styles/banner.css +64 -0
  142. package/src/styles/bar.css +106 -0
  143. package/src/styles/base.css +41 -0
  144. package/src/styles/claudy.css +99 -0
  145. package/src/styles/drawer.css +126 -0
  146. package/src/styles/index.styl +33 -0
  147. package/src/styles/indicators.css +58 -0
  148. package/src/styles/nav.css +81 -0
  149. package/src/styles/navigation_item.css +39 -0
  150. package/src/styles/searchbar.css +158 -0
  151. package/src/styles/settings.css +44 -0
  152. package/src/styles/storage.css +22 -0
  153. package/src/styles/supportModal.css +20 -0
  154. package/src/styles/theme.styl +25 -0
  155. package/test/__mocks__/fileMock.js +3 -0
  156. package/test/__snapshots__/index.spec.js.snap +41 -0
  157. package/test/components/AppItem.spec.jsx +113 -0
  158. package/test/components/AppsContent.spec.jsx +116 -0
  159. package/test/components/Settings/helper.spec.js +23 -0
  160. package/test/components/__snapshots__/AppsContent.spec.jsx.snap +90 -0
  161. package/test/index.spec.js +24 -0
  162. package/test/jestLib/I18n.js +15 -0
  163. package/test/jestLib/setup.js +14 -0
  164. package/test/lib/__snapshots__/api.spec.jsx.snap +67 -0
  165. package/test/lib/__snapshots__/stack.spec.js.snap +3 -0
  166. package/test/lib/api.spec.jsx +142 -0
  167. package/test/lib/mockStackClient.js +7 -0
  168. package/test/lib/stack-client/stack-client.appiconprops.spec.js +65 -0
  169. package/test/lib/stack-client/stack-client.compare.spec.js +20 -0
  170. package/test/lib/stack-client/stack-client.cozyfetchjson.spec.js +46 -0
  171. package/test/lib/stack-client/stack-client.cozyurl.spec.js +29 -0
  172. package/test/lib/stack-client/stack-client.getapp.spec.js +72 -0
  173. package/test/lib/stack-client/stack-client.getapps.spec.js +72 -0
  174. package/test/lib/stack-client/stack-client.getcontext.spec.js +96 -0
  175. package/test/lib/stack-client/stack-client.getstoragedata.spec.js +85 -0
  176. package/test/lib/stack-client/stack-client.init.spec.js +56 -0
  177. package/test/lib/stack-client/stack-client.intents.spec.js +27 -0
  178. package/test/lib/stack-client/stack-client.logout.spec.js +40 -0
  179. package/test/lib/stack.spec.js +60 -0
  180. package/test/store/__snapshots__/index.spec.js.snap +14 -0
  181. 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,3 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`stack proxy should throw error if trying to use the stack before init 1`] = `"client not initialized in cozy-bar"`;
@@ -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,7 @@
1
+ const stackClient = {
2
+ token: { token: 'mytoken' },
3
+ uri: 'https://test.mycozy.cloud',
4
+ on: () => {}
5
+ }
6
+
7
+ export default stackClient
@@ -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
+ })