cozy-ui 82.7.0 → 82.8.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [82.8.0](https://github.com/cozy/cozy-ui/compare/v82.7.0...v82.8.0) (2023-03-31)
2
+
3
+
4
+ ### Features
5
+
6
+ * Use helper for get random UUID ([e659a9b](https://github.com/cozy/cozy-ui/commit/e659a9b))
7
+
1
8
  # [82.7.0](https://github.com/cozy/cozy-ui/compare/v82.6.1...v82.7.0) (2023-03-31)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "82.7.0",
3
+ "version": "82.8.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -6,6 +6,7 @@ import Box from '../Box'
6
6
  import IconButton from '../IconButton'
7
7
  import Typography from '../Typography'
8
8
  import { makeTypoColor, makeButtonShadow } from './helpers'
9
+ import { getRandomUUID } from '../helpers/getRandomUUID'
9
10
 
10
11
  const useStyles = makeStyles(theme => ({
11
12
  iconButton: {
@@ -42,7 +43,7 @@ const CircleButton = ({
42
43
  ...props
43
44
  }) => {
44
45
  const styles = useStyles({ active: variant === 'active', disabled })
45
- const uuid = crypto.randomUUID()
46
+ const uuid = getRandomUUID()
46
47
 
47
48
  if (!ariaLabel && !label) {
48
49
  console.warn(`The "aria-label" or "label" property must be filled in.`)
@@ -53,7 +53,12 @@ describe('formatLocallyDistanceToNow', () => {
53
53
  })
54
54
 
55
55
  describe('formatLocallyDistanceToNowStrict', () => {
56
+ afterEach(() => {
57
+ MockDate.reset()
58
+ })
59
+
56
60
  it('should formatDistanceToNowStrict with small value', () => {
61
+ MockDate.set('2023-01-01T00:00:00')
57
62
  const date = Date.now() + 29 * 1000 // 29s
58
63
 
59
64
  const result = formatLocallyDistanceToNowStrict(date)
@@ -62,6 +67,7 @@ describe('formatLocallyDistanceToNowStrict', () => {
62
67
  })
63
68
 
64
69
  it('should formatDistanceToNowStrict with medium value', () => {
70
+ MockDate.set('2023-01-01T00:00:00')
65
71
  const date = Date.now() + (44 * 60 + 31) * 1000 // 44min 31s
66
72
 
67
73
  const result = formatLocallyDistanceToNowStrict(date)
@@ -70,6 +76,7 @@ describe('formatLocallyDistanceToNowStrict', () => {
70
76
  })
71
77
 
72
78
  it('should formatDistanceToNowStrict with high value', () => {
79
+ MockDate.set('2023-01-01T00:00:00')
73
80
  const date = Date.now() + (89 * 60 + 31) * 1000 // 89min 31s
74
81
 
75
82
  const result = formatLocallyDistanceToNowStrict(date)
@@ -78,6 +85,7 @@ describe('formatLocallyDistanceToNowStrict', () => {
78
85
  })
79
86
 
80
87
  it('should formatDistanceToNowStrict with one day', () => {
88
+ MockDate.set('2023-01-01T00:00:00')
81
89
  const date = Date.now() + 24 * 60 * 60 * 1000 // 1d
82
90
 
83
91
  const result = formatLocallyDistanceToNowStrict(date)
@@ -86,6 +94,7 @@ describe('formatLocallyDistanceToNowStrict', () => {
86
94
  })
87
95
 
88
96
  it('should formatDistanceToNowStrict with two days', () => {
97
+ MockDate.set('2023-01-01T00:00:00')
89
98
  const date = Date.now() + 2 * 24 * 60 * 60 * 1000 // 2d
90
99
 
91
100
  const result = formatLocallyDistanceToNowStrict(date)
@@ -94,6 +103,7 @@ describe('formatLocallyDistanceToNowStrict', () => {
94
103
  })
95
104
 
96
105
  it('should formatDistanceToNowStrict with very high value', () => {
106
+ MockDate.set('2023-01-01T00:00:00')
97
107
  const date = Date.now() + 42 * 24 * 60 * 60 * 1000 // 42d
98
108
 
99
109
  const result = formatLocallyDistanceToNowStrict(date)
@@ -1,9 +1,10 @@
1
1
  import React, { forwardRef } from 'react'
2
2
  import MuiTextField from '@material-ui/core/TextField'
3
+ import { getRandomUUID } from '../../helpers/getRandomUUID'
3
4
 
4
5
  const TextField = forwardRef(({ children, ...props }, ref) => {
5
6
  // A11Y, https://v4.mui.com/api/text-field/#props
6
- const uuid = crypto.randomUUID()
7
+ const uuid = getRandomUUID()
7
8
 
8
9
  return (
9
10
  <MuiTextField ref={ref} id={uuid} {...props}>
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Returns a random UUID
3
+ * @returns {string} a random UUID
4
+ */
5
+ export const getRandomUUID = () => {
6
+ if (process.env.NODE_ENV === 'test') {
7
+ return 'random-uuid-for-jest'
8
+ }
9
+
10
+ return window.crypto.randomUUID()
11
+ }
@@ -0,0 +1,9 @@
1
+ import { getRandomUUID } from './getRandomUUID'
2
+
3
+ describe('getRandomUUID', () => {
4
+ it('returns a random uuid', () => {
5
+ const uuid = getRandomUUID()
6
+
7
+ expect(uuid).toBe('random-uuid-for-jest')
8
+ })
9
+ })
@@ -8,6 +8,7 @@ import Box from "cozy-ui/transpiled/react/Box";
8
8
  import IconButton from "cozy-ui/transpiled/react/IconButton";
9
9
  import Typography from "cozy-ui/transpiled/react/Typography";
10
10
  import { makeTypoColor, makeButtonShadow } from "cozy-ui/transpiled/react/CircleButton/helpers";
11
+ import { getRandomUUID } from "cozy-ui/transpiled/react/helpers/getRandomUUID";
11
12
  var useStyles = makeStyles(function (theme) {
12
13
  return {
13
14
  iconButton: {
@@ -73,7 +74,7 @@ var CircleButton = function CircleButton(_ref7) {
73
74
  active: variant === 'active',
74
75
  disabled: disabled
75
76
  });
76
- var uuid = crypto.randomUUID();
77
+ var uuid = getRandomUUID();
77
78
 
78
79
  if (!ariaLabel && !label) {
79
80
  console.warn("The \"aria-label\" or \"label\" property must be filled in.");
@@ -3,12 +3,13 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
3
3
  var _excluded = ["children"];
4
4
  import React, { forwardRef } from 'react';
5
5
  import MuiTextField from '@material-ui/core/TextField';
6
+ import { getRandomUUID } from "cozy-ui/transpiled/react/helpers/getRandomUUID";
6
7
  var TextField = /*#__PURE__*/forwardRef(function (_ref, ref) {
7
8
  var children = _ref.children,
8
9
  props = _objectWithoutProperties(_ref, _excluded);
9
10
 
10
11
  // A11Y, https://v4.mui.com/api/text-field/#props
11
- var uuid = crypto.randomUUID();
12
+ var uuid = getRandomUUID();
12
13
  return /*#__PURE__*/React.createElement(MuiTextField, _extends({
13
14
  ref: ref,
14
15
  id: uuid
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Returns a random UUID
3
+ * @returns {string} a random UUID
4
+ */
5
+ export var getRandomUUID = function getRandomUUID() {
6
+ if (process.env.NODE_ENV === 'test') {
7
+ return 'random-uuid-for-jest';
8
+ }
9
+
10
+ return window.crypto.randomUUID();
11
+ };