@automattic/jetpack-components 0.41.1 → 0.42.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.
Files changed (107) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/components/boost-score-graph/background.tsx +183 -0
  3. package/components/boost-score-graph/day-highlight-plugin.ts +82 -0
  4. package/components/boost-score-graph/get-date-format.ts +59 -0
  5. package/components/boost-score-graph/index.native.js +1 -0
  6. package/components/boost-score-graph/index.tsx +76 -0
  7. package/components/boost-score-graph/style-tooltip.scss +52 -0
  8. package/components/boost-score-graph/style-uplot.scss +5 -0
  9. package/components/boost-score-graph/style.scss +17 -0
  10. package/components/boost-score-graph/tooltip.tsx +87 -0
  11. package/components/boost-score-graph/tooltips-plugin.ts +98 -0
  12. package/components/boost-score-graph/types/declarations.d.ts +4 -0
  13. package/components/boost-score-graph/uplot-line-chart.tsx +193 -0
  14. package/components/boost-score-graph/use-boost-score-transform.ts +36 -0
  15. package/components/boost-score-graph/use-resize.ts +40 -0
  16. package/components/gridicon/index.tsx +13 -0
  17. package/components/{pricing-slider → number-slider}/index.tsx +12 -12
  18. package/components/{pricing-slider → number-slider}/style.scss +8 -8
  19. package/components/{pricing-slider → number-slider}/types.ts +2 -2
  20. package/components/popover/index.tsx +19 -0
  21. package/components/popover/style.scss +25 -0
  22. package/components/product-price/index.tsx +5 -5
  23. package/components/product-price/style.module.scss +8 -1
  24. package/index.ts +3 -1
  25. package/package.json +6 -3
  26. package/.gitattributes +0 -8
  27. package/components/action-button/stories/index.stories.jsx +0 -38
  28. package/components/action-button/test/component.jsx +0 -16
  29. package/components/action-popover/stories/index.stories.jsx +0 -115
  30. package/components/action-popover/stories/styles.module.scss +0 -7
  31. package/components/admin-page/stories/index.stories.tsx +0 -35
  32. package/components/admin-page/stories/style.module.scss +0 -13
  33. package/components/admin-section/stories/index.stories.tsx +0 -60
  34. package/components/alert/stories/index.stories.jsx +0 -24
  35. package/components/automattic-byline-logo/stories/index.stories.tsx +0 -20
  36. package/components/automattic-byline-logo/test/component.tsx +0 -28
  37. package/components/boost-score-bar/stories/index.stories.tsx +0 -39
  38. package/components/boost-score-bar/test/component.tsx +0 -102
  39. package/components/button/stories/index.mdx +0 -90
  40. package/components/button/stories/index.stories.tsx +0 -400
  41. package/components/button/stories/style.module.scss +0 -20
  42. package/components/contextual-upgrade-trigger/stories/index.stories.tsx +0 -25
  43. package/components/decorative-card/stories/index.stories.tsx +0 -18
  44. package/components/dialog/stories/boost.png +0 -0
  45. package/components/dialog/stories/declaration.d.ts +0 -1
  46. package/components/dialog/stories/index.stories.tsx +0 -118
  47. package/components/dialog/stories/js-components.components.dialog.mdx +0 -62
  48. package/components/dialog/stories/js-components.components.dialog.stories.js +0 -37
  49. package/components/dialog/stories/style.module.scss +0 -21
  50. package/components/donut-meter/stories/index.stories.tsx +0 -51
  51. package/components/donut-meter/test/component.tsx +0 -24
  52. package/components/gridicon/stories/index.stories.tsx +0 -18
  53. package/components/icon-tooltip/stories/index.stories.tsx +0 -108
  54. package/components/icon-tooltip/stories/style.scss +0 -36
  55. package/components/icon-tooltip/test/component.tsx +0 -15
  56. package/components/icons/stories/index.stories.tsx +0 -65
  57. package/components/icons/stories/style.module.scss +0 -33
  58. package/components/indeterminate-progress-bar/stories/index.stories.tsx +0 -14
  59. package/components/jetpack-footer/stories/index.stories.tsx +0 -39
  60. package/components/jetpack-footer/test/__snapshots__/component.tsx.snap +0 -186
  61. package/components/jetpack-footer/test/component.tsx +0 -159
  62. package/components/jetpack-logo/stories/index.stories.tsx +0 -20
  63. package/components/jetpack-logo/test/component.tsx +0 -16
  64. package/components/jetpack-search-logo/stories/index.stories.tsx +0 -21
  65. package/components/jetpack-search-logo/test/component.tsx +0 -16
  66. package/components/jetpack-vaultpress-backup-logo/stories/index.stories.tsx +0 -20
  67. package/components/jetpack-vaultpress-backup-logo/test/component.tsx +0 -18
  68. package/components/jetpack-videopress-logo/stories/index.stories.tsx +0 -20
  69. package/components/jetpack-videopress-logo/test/component.tsx +0 -16
  70. package/components/layout/stories/index.stories.tsx +0 -145
  71. package/components/layout/stories/styles.module.scss +0 -22
  72. package/components/loading-placeholder/stories/index.stories.tsx +0 -78
  73. package/components/notice/stories/index.stories.jsx +0 -90
  74. package/components/pricing-card/stories/index.stories.tsx +0 -55
  75. package/components/pricing-card/test/component.tsx +0 -89
  76. package/components/pricing-slider/stories/index.stories.tsx +0 -44
  77. package/components/pricing-slider/test/component.tsx +0 -14
  78. package/components/pricing-table/stories/index.stories.tsx +0 -74
  79. package/components/pricing-table/test/component.tsx +0 -41
  80. package/components/product-offer/stories/index.stories.tsx +0 -104
  81. package/components/product-price/stories/index.stories.tsx +0 -33
  82. package/components/product-price/test/component.tsx +0 -26
  83. package/components/qr-code/stories/index.stories.tsx +0 -32
  84. package/components/record-meter-bar/stories/index.stories.tsx +0 -39
  85. package/components/record-meter-bar/test/component.tsx +0 -52
  86. package/components/spinner/stories/index.stories.jsx +0 -20
  87. package/components/spinner/test/component.jsx +0 -17
  88. package/components/split-button/stories/index.stories.tsx +0 -35
  89. package/components/stat-card/stories/index.mdx +0 -35
  90. package/components/stat-card/stories/index.stories.tsx +0 -41
  91. package/components/stat-card/test/component.tsx +0 -24
  92. package/components/status/stories/index.stories.tsx +0 -44
  93. package/components/terms-of-service/test/index.test.jsx +0 -52
  94. package/components/testimonials/test/component.tsx +0 -103
  95. package/components/text/stories/headings.index.stories.tsx +0 -80
  96. package/components/text/stories/index.mdx +0 -195
  97. package/components/text/stories/index.stories.tsx +0 -69
  98. package/components/text/stories/style.module.scss +0 -64
  99. package/components/text/stories/title.index.stories.tsx +0 -34
  100. package/components/theme-provider/stories/index.stories.tsx +0 -164
  101. package/components/theme-provider/stories/style.module.scss +0 -79
  102. package/components/toggle-control/stories/index.stories.tsx +0 -83
  103. package/components/zendesk-chat/stories/index.stories.tsx +0 -15
  104. package/components/zendesk-chat/test/component.tsx +0 -16
  105. package/lib/locale/test/index.ts +0 -21
  106. package/tools/jp-redirect/test/index.tsx +0 -89
  107. package/tools/pricing-utils/test/index.ts +0 -39
@@ -6,14 +6,21 @@
6
6
  }
7
7
 
8
8
  .price-container {
9
+ display: flex;
10
+ align-items: flex-start;
9
11
  flex-grow: 2;
10
12
  flex-basis: 0;
13
+
14
+ .promo-label {
15
+ margin-left: auto;
16
+ }
11
17
  }
12
18
 
13
19
  .price {
14
20
  display: inline-flex;
15
21
  align-items: flex-start;
16
22
  position: relative;
23
+ flex: 0 0 auto;
17
24
 
18
25
  &:first-child {
19
26
  margin-right: calc( var( --spacing-base ) * 2 );
@@ -66,4 +73,4 @@
66
73
 
67
74
  .symbol {
68
75
  font-weight: 400;
69
- }
76
+ }
package/index.ts CHANGED
@@ -28,7 +28,7 @@ export { default as Gridicon } from './components/gridicon';
28
28
  export { default as IconTooltip } from './components/icon-tooltip';
29
29
  export { default as ActionButton } from './components/action-button';
30
30
  export { default as PricingCard } from './components/pricing-card';
31
- export { default as PricingSlider } from './components/pricing-slider';
31
+ export { default as NumberSlider } from './components/number-slider';
32
32
  export { default as AdminSection } from './components/admin-section/basic';
33
33
  export { default as AdminSectionHero } from './components/admin-section/hero';
34
34
  export { default as AdminPage } from './components/admin-page';
@@ -54,6 +54,7 @@ export {
54
54
  PricingTableItem,
55
55
  } from './components/pricing-table';
56
56
  export { default as BoostScoreBar } from './components/boost-score-bar';
57
+ export { default as BoostScoreGraph } from './components/boost-score-graph';
57
58
  export { default as ProductPrice } from './components/product-price';
58
59
  export { default as ProductOffer, IconsCard } from './components/product-offer';
59
60
  export { default as Dialog } from './components/dialog';
@@ -62,6 +63,7 @@ export { default as RecordMeterBar } from './components/record-meter-bar';
62
63
  export { default as ContextualUpgradeTrigger } from './components/contextual-upgrade-trigger';
63
64
  export { default as Alert } from './components/alert';
64
65
  export { default as Notice } from './components/notice';
66
+ export { default as Popover } from './components/popover';
65
67
  export { default as Status } from './components/status';
66
68
  export { default as IndeterminateProgressBar } from './components/indeterminate-progress-bar';
67
69
  export { default as ActionPopover } from './components/action-popover';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/jetpack-components",
3
- "version": "0.41.1",
3
+ "version": "0.42.0",
4
4
  "description": "Jetpack Components Package",
5
5
  "author": "Automattic",
6
6
  "license": "GPL-2.0-or-later",
@@ -15,6 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@automattic/format-currency": "1.0.1",
18
+ "@automattic/jetpack-boost-score-api": "^0.1.8",
18
19
  "@babel/runtime": "^7",
19
20
  "@wordpress/browserslist-config": "5.21.0",
20
21
  "@wordpress/components": "25.4.0",
@@ -27,10 +28,12 @@
27
28
  "classnames": "2.3.2",
28
29
  "prop-types": "^15.7.2",
29
30
  "qrcode.react": "3.1.0",
30
- "react-slider": "2.0.5"
31
+ "react-slider": "2.0.5",
32
+ "uplot": "1.6.24",
33
+ "uplot-react": "1.1.4"
31
34
  },
32
35
  "devDependencies": {
33
- "@automattic/jetpack-base-styles": "^0.6.5",
36
+ "@automattic/jetpack-base-styles": "^0.6.7",
34
37
  "@babel/core": "7.22.9",
35
38
  "@babel/preset-react": "7.22.5",
36
39
  "@jest/globals": "29.4.3",
package/.gitattributes DELETED
@@ -1,8 +0,0 @@
1
- # Files not needed to be distributed in the package.
2
- .gitattributes export-ignore
3
- node_modules export-ignore
4
-
5
- # Files to exclude from the mirror repo
6
- /changelog/** production-exclude
7
- /.eslintrc.cjs production-exclude
8
- /jest.config.cjs production-exclude
@@ -1,38 +0,0 @@
1
- import { action } from '@storybook/addon-actions';
2
- import React from 'react';
3
- import ActionButton from '../index.jsx';
4
-
5
- export default {
6
- title: 'JS Packages/Components/Action Button',
7
- component: ActionButton,
8
- // TODO: Storybook Actions are not working. See https://github.com/storybookjs/storybook/issues/7215
9
- argTypes: {
10
- onButtonClick: { action: 'clicked' },
11
- },
12
- };
13
-
14
- // Export additional stories using pre-defined values
15
- const Template = args => <ActionButton { ...args } />;
16
-
17
- const DefaultArgs = {
18
- onButtonClick: action( 'onButtonClick' ),
19
- displayError: false,
20
- isLoading: false,
21
- label: 'Action!',
22
- };
23
-
24
- // Export Default story
25
- export const _default = Template.bind( {} );
26
- _default.args = DefaultArgs;
27
-
28
- export const Loading = Template.bind( {} );
29
- Loading.args = {
30
- ...DefaultArgs,
31
- isLoading: true,
32
- };
33
-
34
- export const Errored = Template.bind( {} );
35
- Errored.args = {
36
- ...DefaultArgs,
37
- displayError: true,
38
- };
@@ -1,16 +0,0 @@
1
- import { render, screen } from '@testing-library/react';
2
- import ActionButton from '../index';
3
-
4
- describe( 'ActionButton', () => {
5
- const testProps = {
6
- label: 'Action!',
7
- };
8
-
9
- describe( 'Render the ActionButton component', () => {
10
- render( <ActionButton { ...testProps } /> );
11
-
12
- it( 'renders the register button', () => {
13
- expect( screen.getByRole( 'button' ) ).toHaveTextContent( 'Action!' );
14
- } );
15
- } );
16
- } );
@@ -1,115 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { action } from '@storybook/addon-actions';
5
- import { useState } from 'react';
6
- /**
7
- * Internal dependencies
8
- */
9
- import ActionPopover from '../index';
10
- import styles from './styles.module.scss';
11
-
12
- export default {
13
- title: 'JS Packages/Components/Action Popover',
14
- component: ActionPopover,
15
- argTypes: {
16
- hideCloseButton: {
17
- control: { type: 'boolean' },
18
- },
19
- title: {
20
- control: { type: 'text' },
21
- },
22
- children: {
23
- control: { type: 'text' },
24
- },
25
- step: {
26
- control: { type: 'number' },
27
- },
28
- totalSteps: {
29
- control: { type: 'number' },
30
- },
31
- buttonContent: {
32
- control: { type: 'text' },
33
- },
34
- buttonDisabled: {
35
- control: { type: 'boolean' },
36
- },
37
- buttonHref: {
38
- control: { type: 'text' },
39
- },
40
- buttonExternalLink: {
41
- control: { type: 'boolean' },
42
- },
43
- offset: {
44
- control: { type: 'number' },
45
- },
46
- position: {
47
- control: {
48
- type: 'select',
49
- },
50
- options: [
51
- 'top left',
52
- 'top right',
53
- 'top center',
54
- 'middle left',
55
- 'middle right',
56
- 'middle center',
57
- 'bottom left',
58
- 'bottom right',
59
- 'bottom center',
60
- ],
61
- },
62
- noArrow: {
63
- control: { type: 'boolean' },
64
- },
65
- onClose: {
66
- table: {
67
- disable: true,
68
- },
69
- },
70
- onClick: {
71
- table: {
72
- disable: true,
73
- },
74
- },
75
- },
76
- };
77
-
78
- const Template = args => {
79
- const [ anchor, setAnchor ] = useState( null );
80
-
81
- return (
82
- <>
83
- <div className={ styles.wrapper }>
84
- <div ref={ setAnchor }>⚓</div>
85
- </div>
86
-
87
- <ActionPopover { ...args } anchor={ anchor } />
88
- </>
89
- );
90
- };
91
-
92
- const defaultArgs = {
93
- hideCloseButton: false,
94
- title: 'Check this out',
95
- children: 'Absque sudore et labore nullum opus perfectum est.',
96
- step: null,
97
- totalSteps: null,
98
- buttonContent: 'Next',
99
- buttonDisabled: false,
100
- offset: 32,
101
- position: 'top center',
102
- noArrow: true,
103
- onClose: () => action( 'close' )(),
104
- onClick: () => action( 'click' )(),
105
- };
106
-
107
- export const _default = Template.bind( {} );
108
- _default.args = defaultArgs;
109
-
110
- export const WithSteps = Template.bind( {} );
111
- WithSteps.args = {
112
- ...defaultArgs,
113
- step: 1,
114
- totalSteps: 3,
115
- };
@@ -1,7 +0,0 @@
1
- .wrapper {
2
- height: 100vh;
3
- display: flex;
4
- justify-content: center;
5
- align-items: center;
6
- background-color: var( --jp-gray-off );
7
- }
@@ -1,35 +0,0 @@
1
- import React from 'react';
2
- import JetpackLogo from '../../jetpack-logo/index';
3
- import Text from '../../text/index';
4
- import AdminPage from '../index';
5
- import styles from './style.module.scss';
6
- import type { ComponentStory, ComponentMeta } from '@storybook/react';
7
-
8
- export default {
9
- title: 'JS Packages/Components/Admin Page',
10
- component: AdminPage,
11
- argTypes: {
12
- moduleName: { control: 'text', defaultValue: 'Jetpack' },
13
- showHeader: { control: 'boolean', defaultValue: true },
14
- showFooter: { control: 'boolean', defaultValue: true },
15
- showBackground: { control: 'boolean', defaultValue: true },
16
- },
17
- } as ComponentMeta< typeof AdminPage >;
18
-
19
- // Export additional stories using pre-defined values
20
- const Template: ComponentStory< typeof AdminPage > = args => <AdminPage { ...args } />;
21
-
22
- // Export Default story
23
- export const _default = Template.bind( {} );
24
-
25
- export const CustomHeader = Template.bind( {} );
26
- CustomHeader.args = {
27
- header: (
28
- <div className={ styles[ 'custom-header' ] }>
29
- <JetpackLogo height={ 40 } />
30
- <Text className={ styles[ 'logo-title' ] } weight="regular">
31
- Next Product is coming up
32
- </Text>
33
- </div>
34
- ),
35
- };
@@ -1,13 +0,0 @@
1
- .custom-header {
2
- display: flex;
3
- }
4
-
5
- .logo-title {
6
- flex: 1;
7
- line-height: 30px;
8
- font-size: 30px;
9
- margin-top: 2px;
10
- margin-left: 4px;
11
- font-weight: 300;
12
- letter-spacing: 0.0625em;
13
- }
@@ -1,60 +0,0 @@
1
- import AdminPage from '../../admin-page';
2
- import Col from '../../layout/col';
3
- import Container from '../../layout/container';
4
- import AdminSection from '../basic';
5
- import AdminSectionHero from '../hero';
6
- import type { ComponentStory, ComponentMeta } from '@storybook/react';
7
-
8
- export default {
9
- title: 'JS Packages/Components/Admin Sections',
10
- } as ComponentMeta< typeof AdminSection >;
11
-
12
- // Export additional stories using pre-defined values
13
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
- const Template: ComponentStory< typeof AdminSection > = args => (
15
- <AdminPage>
16
- <AdminSectionHero>
17
- <Container>
18
- <Col lg={ 12 } md={ 8 } sm={ 4 }>
19
- <h1>Sample Hero section</h1>
20
- <p>This is a sample Hero section</p>
21
- </Col>
22
- </Container>
23
- </AdminSectionHero>
24
- <AdminSection>
25
- <Container>
26
- <Col lg={ 12 } md={ 8 } sm={ 4 }>
27
- <h2>Sample Section</h2>
28
- <p>This is a sample section</p>
29
- </Col>
30
- </Container>
31
- </AdminSection>
32
- </AdminPage>
33
- );
34
-
35
- // Export Default story
36
- export const _default = Template.bind( {} );
37
-
38
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
39
- export const onlyBasic = args => (
40
- <AdminSection>
41
- <Container>
42
- <Col lg={ 12 } md={ 8 } sm={ 4 }>
43
- <h2>Sample Section</h2>
44
- <p>This is a sample section</p>
45
- </Col>
46
- </Container>
47
- </AdminSection>
48
- );
49
-
50
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
51
- export const onlyHero = args => (
52
- <AdminSectionHero>
53
- <Container>
54
- <Col lg={ 12 } md={ 8 } sm={ 4 }>
55
- <h2>Sample Hero Section</h2>
56
- <p>This is a sample Hero section</p>
57
- </Col>
58
- </Container>
59
- </AdminSectionHero>
60
- );
@@ -1,24 +0,0 @@
1
- import React from 'react';
2
- import Alert from '../index';
3
-
4
- export default {
5
- title: 'JS Packages/Components/Alert',
6
- component: Alert,
7
- argTypes: {
8
- level: {
9
- control: {
10
- type: 'select',
11
- },
12
- options: [ 'info', 'success', 'warning', 'error' ],
13
- },
14
- },
15
- };
16
-
17
- const Template = args => <Alert { ...args } />;
18
-
19
- export const _default = Template.bind( {} );
20
- _default.args = {
21
- level: 'info',
22
- children: "Don't forget to check your email for the latest news.",
23
- showIcon: true,
24
- };
@@ -1,20 +0,0 @@
1
- import AutomatticBylineLogo from '../index';
2
- import type { ComponentStory, ComponentMeta } from '@storybook/react';
3
-
4
- export default {
5
- title: 'JS Packages/Components/Automattic Byline Logo',
6
- component: AutomatticBylineLogo,
7
- } as ComponentMeta< typeof AutomatticBylineLogo >;
8
-
9
- const Template: ComponentStory< typeof AutomatticBylineLogo > = args => (
10
- <AutomatticBylineLogo { ...args } />
11
- );
12
-
13
- const DefaultArgs = {
14
- title: 'Title',
15
- height: '50px',
16
- className: 'sample-classname',
17
- };
18
-
19
- export const _default = Template.bind( {} );
20
- _default.args = DefaultArgs;
@@ -1,28 +0,0 @@
1
- import { render, screen } from '@testing-library/react';
2
- import AutomatticBylineLogo from '../index';
3
-
4
- describe( 'AutomatticBylineLogo', () => {
5
- const testProps = {
6
- className: 'sample-classname',
7
- };
8
-
9
- describe( 'Render the AutomatticBylineLogo component', () => {
10
- it( 'validate the class name', () => {
11
- const { container } = render( <AutomatticBylineLogo { ...testProps } /> );
12
- // eslint-disable-next-line testing-library/no-node-access
13
- expect( container.firstChild ).toHaveClass( 'sample-classname' );
14
- } );
15
-
16
- it( 'renders the default title', () => {
17
- render( <AutomatticBylineLogo /> );
18
-
19
- expect( screen.getByText( 'An Automattic Airline' ) ).toBeInTheDocument();
20
- } );
21
-
22
- it( 'renders the given title', () => {
23
- render( <AutomatticBylineLogo title="An A8C Airline" /> );
24
-
25
- expect( screen.getByText( 'An A8C Airline' ) ).toBeInTheDocument();
26
- } );
27
- } );
28
- } );
@@ -1,39 +0,0 @@
1
- import BoostScoreBar from '../index';
2
- import type { Meta } from '@storybook/react';
3
-
4
- const meta: Meta< typeof BoostScoreBar > = {
5
- title: 'JS Packages/Components/Boost Score Bar',
6
- component: BoostScoreBar,
7
- argTypes: {
8
- score: { control: 'range', min: 0, max: 100, defaultValue: 80 },
9
- prevScore: { control: 'range', min: 0, max: 100 },
10
- isLoading: { control: 'boolean' },
11
- showPrevScores: { control: 'boolean' },
12
- active: { control: 'boolean' },
13
- scoreBarType: { control: 'radio', options: [ 'desktop', 'mobile' ] },
14
- noBoostScoreTooltip: { control: 'text' },
15
- },
16
- decorators: [
17
- Story => (
18
- <div style={ { width: '80%', maxWidth: '1320px', margin: '200px auto', fontSize: '16px' } }>
19
- <Story />
20
- </div>
21
- ),
22
- ],
23
- };
24
-
25
- const defaultValues = {
26
- score: 80,
27
- prevScore: 70,
28
- isLoading: false,
29
- showPrevScores: true,
30
- active: true,
31
- scoreBarType: 'desktop',
32
- noBoostScoreTooltip: 'No boost score',
33
- };
34
-
35
- export default meta;
36
-
37
- const Template = args => <BoostScoreBar { ...args } />;
38
- export const _default = Template.bind( {} );
39
- _default.args = defaultValues;
@@ -1,102 +0,0 @@
1
- /* eslint-disable testing-library/no-container */
2
- /* eslint-disable testing-library/no-node-access */
3
- import { render, screen } from '@testing-library/react';
4
- import BoostScoreBar from '..';
5
- import type { BoostScoreBarProps } from '../types';
6
-
7
- describe( 'BoostScrollBar', () => {
8
- const defaultProps: BoostScoreBarProps = {
9
- score: 80,
10
- prevScore: 60,
11
- scoreBarType: 'desktop',
12
- active: true,
13
- showPrevScores: true,
14
- isLoading: false,
15
- noBoostScoreTooltip: 'Test tooltip text',
16
- };
17
-
18
- it( 'renders the boost scroll bar when active is true', () => {
19
- const { container } = render( <BoostScoreBar { ...defaultProps } /> );
20
-
21
- // eslint-disable-next-line testing-library/no-node-access
22
- expect( container.firstChild ).toHaveAttribute( 'class', 'jb-score-bar jb-score-bar--desktop' );
23
- } );
24
-
25
- it( 'does not render the boost scroll bar when active is false', () => {
26
- const { container } = render( <BoostScoreBar { ...defaultProps } active={ false } /> );
27
-
28
- // eslint-disable-next-line testing-library/no-node-access
29
- expect( container ).toBeEmptyDOMElement();
30
- } );
31
-
32
- it( 'does not render the tooltip when noBoostScoreTooltip is not provided', () => {
33
- render( <BoostScoreBar { ...defaultProps } noBoostScoreTooltip={ undefined } /> );
34
-
35
- expect( screen.queryByRole( 'tooltip' ) ).not.toBeInTheDocument();
36
- } );
37
-
38
- it( 'renders the tooltip with the correct text when noBoostScoreTooltip is provided', () => {
39
- render( <BoostScoreBar { ...defaultProps } /> );
40
-
41
- expect( screen.getByRole( 'tooltip' ) ).toHaveTextContent( 'Test tooltip text' );
42
- } );
43
-
44
- it( 'displays loading spinner when isLoading is true', () => {
45
- const { container } = render( <BoostScoreBar { ...defaultProps } isLoading={ true } /> );
46
-
47
- expect( container.querySelector( '.jb-score-bar__loading' ) ).toBeInTheDocument();
48
- } );
49
-
50
- it( 'does not display loading spinner when isLoading is false', () => {
51
- const { container } = render( <BoostScoreBar { ...defaultProps } /> );
52
-
53
- expect( container.querySelector( '.jb-score-bar__loading' ) ).not.toBeInTheDocument();
54
- } );
55
-
56
- it( 'renders mobile icon and text when scoreBarType is mobile', () => {
57
- const { container } = render( <BoostScoreBar { ...defaultProps } scoreBarType="mobile" /> );
58
-
59
- expect( screen.getByText( 'Mobile score' ) ).toBeInTheDocument();
60
- expect( container.querySelector( '.gridicons-phone' ) ).toBeInTheDocument();
61
- } );
62
-
63
- it( 'renders desktop icon and text when scoreBarType is desktop', () => {
64
- const { container } = render( <BoostScoreBar { ...defaultProps } /> );
65
-
66
- expect( screen.getByText( 'Desktop score' ) ).toBeInTheDocument();
67
- expect( container.querySelector( '.gridicons-computer' ) ).toBeInTheDocument();
68
- } );
69
-
70
- it( 'renders previous scores when showPrevScores is true', () => {
71
- const { container } = render( <BoostScoreBar { ...defaultProps } /> );
72
-
73
- const previousScoreContainer = container.querySelector( '.jb-score-bar__no_boost_score' );
74
-
75
- expect( previousScoreContainer ).toBeInTheDocument();
76
- expect( previousScoreContainer ).toHaveTextContent( '60' );
77
- } );
78
-
79
- it( 'does not render previous scores when showPrevScores is false', () => {
80
- const { container } = render( <BoostScoreBar { ...defaultProps } showPrevScores={ false } /> );
81
-
82
- expect( container.querySelector( '.jb-score-bar__no_boost_score' ) ).not.toBeInTheDocument();
83
- } );
84
-
85
- it( 'renders the correct score bar class when score is < 50', () => {
86
- const { container } = render( <BoostScoreBar { ...defaultProps } score={ 40 } /> );
87
-
88
- expect( container.querySelector( '.fill-bad' ) ).toBeInTheDocument();
89
- } );
90
-
91
- it( 'renders the correct score bar class when score is >= 50 and < 71', () => {
92
- const { container } = render( <BoostScoreBar { ...defaultProps } score={ 60 } /> );
93
-
94
- expect( container.querySelector( '.fill-mediocre' ) ).toBeInTheDocument();
95
- } );
96
-
97
- it( 'renders the correct score bar class when score is > 70', () => {
98
- const { container } = render( <BoostScoreBar { ...defaultProps } /> );
99
-
100
- expect( container.querySelector( '.fill-good' ) ).toBeInTheDocument();
101
- } );
102
- } );