@elementor/editor-app-bar 0.15.1 → 0.16.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 (27) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/package.json +16 -9
  3. package/src/components/__tests__/app-bar.test.tsx +0 -27
  4. package/src/components/locations/__tests__/locations-components.test.tsx +0 -37
  5. package/src/components/locations/__tests__/menus.test.tsx +0 -153
  6. package/src/extensions/documents-indicator/components/__tests__/settings-button.test.tsx +0 -57
  7. package/src/extensions/documents-preview/hooks/__tests__/use-document-preview-props.test.ts +0 -43
  8. package/src/extensions/documents-save/components/__tests__/primary-action-menu.test.tsx +0 -39
  9. package/src/extensions/documents-save/components/__tests__/primary-action.test.tsx +0 -222
  10. package/src/extensions/documents-save/hooks/__tests__/use-document-save-draft-props.test.ts +0 -68
  11. package/src/extensions/documents-save/hooks/__tests__/use-document-save-template-props.test.ts +0 -28
  12. package/src/extensions/documents-save/hooks/__tests__/use-document-view-page-props.test.ts +0 -43
  13. package/src/extensions/elements/hooks/__tests__/use-action-props.test.ts +0 -36
  14. package/src/extensions/elements/sync/__tests__/sync-panel-title.test.ts +0 -96
  15. package/src/extensions/finder/hooks/__tests__/use-action-props.test.ts +0 -38
  16. package/src/extensions/history/hooks/__tests__/use-action-props.test.ts +0 -36
  17. package/src/extensions/keyboard-shortcuts/hooks/__tests__/use-action-props.test.ts +0 -20
  18. package/src/extensions/responsive/components/__tests__/breakpoints-switcher.test.tsx +0 -101
  19. package/src/extensions/site-settings/components/__tests__/portalled-primary-action.test.tsx +0 -104
  20. package/src/extensions/site-settings/components/__tests__/primary-action.test.tsx +0 -106
  21. package/src/extensions/site-settings/hooks/__tests__/use-action-props.test.ts +0 -52
  22. package/src/extensions/structure/hooks/__tests__/use-action-props.test.ts +0 -36
  23. package/src/extensions/theme-builder/hooks/__tests__/use-action-props.test.ts +0 -22
  24. package/src/extensions/user-preferences/hooks/__tests__/use-action-props.test.ts +0 -37
  25. package/src/locations/__tests__/menus.test.tsx +0 -211
  26. package/src/sync/__tests__/redirect-old-menus.test.ts +0 -38
  27. package/typedoc.config.js +0 -6
package/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.16.1](https://github.com/elementor/elementor-packages/compare/@elementor/editor-app-bar@0.16.0...@elementor/editor-app-bar@0.16.1) (2024-08-06)
7
+
8
+ **Note:** Version bump only for package @elementor/editor-app-bar
9
+
10
+ # [0.16.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-app-bar@0.15.1...@elementor/editor-app-bar@0.16.0) (2024-08-05)
11
+
12
+ ### Bug Fixes
13
+
14
+ - publish only necessary files to npm ([#226](https://github.com/elementor/elementor-packages/issues/226)) ([d808e2f](https://github.com/elementor/elementor-packages/commit/d808e2f60eb7ca2d7b8560d0b79c0e62c2f969a8))
15
+
16
+ ### Features
17
+
18
+ - **editor-editing-panel:** change textarea component [EDS-311] ([#221](https://github.com/elementor/elementor-packages/issues/221)) ([a9ab0d5](https://github.com/elementor/elementor-packages/commit/a9ab0d53e87086e323c4f024dca0eae93005e1a1))
19
+ - **editor-editing-panel:** settings and style tabs [EDS-277] ([#217](https://github.com/elementor/elementor-packages/issues/217)) ([c623797](https://github.com/elementor/elementor-packages/commit/c6237974d9940a2b58bdd1df3d835dc828e323f4))
20
+
6
21
  ## [0.15.1](https://github.com/elementor/elementor-packages/compare/@elementor/editor-app-bar@0.15.0...@elementor/editor-app-bar@0.15.1) (2024-07-23)
7
22
 
8
23
  **Note:** Version bump only for package @elementor/editor-app-bar
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-app-bar",
3
3
  "description": "App Bar extension for @elementor/editor",
4
- "version": "0.15.1",
4
+ "version": "0.16.1",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",
22
- "url": "https://github.com/elementor/elementor-packages.git",
22
+ "url": "git+https://github.com/elementor/elementor-packages.git",
23
23
  "directory": "packages/core/editor-app-bar"
24
24
  },
25
25
  "bugs": {
@@ -28,22 +28,29 @@
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
+ "files": [
32
+ "README.md",
33
+ "CHANGELOG.md",
34
+ "/dist",
35
+ "/src",
36
+ "!**/__tests__"
37
+ ],
31
38
  "scripts": {
32
39
  "build": "tsup --config=../../tsup.build.ts",
33
40
  "dev": "tsup --config=../../tsup.dev.ts"
34
41
  },
35
42
  "dependencies": {
36
- "@elementor/editor": "^0.11.2",
37
- "@elementor/editor-documents": "^0.11.5",
38
- "@elementor/editor-responsive": "^0.11.0",
39
- "@elementor/editor-v1-adapters": "^0.8.0",
43
+ "@elementor/editor": "^0.12.0",
44
+ "@elementor/editor-documents": "^0.11.6",
45
+ "@elementor/editor-responsive": "^0.12.0",
46
+ "@elementor/editor-v1-adapters": "^0.8.1",
40
47
  "@elementor/icons": "^1.1.4",
41
- "@elementor/locations": "^0.7.4",
42
- "@elementor/ui": "^1.4.61",
48
+ "@elementor/locations": "^0.7.5",
49
+ "@elementor/ui": "^1.14.2",
43
50
  "@wordpress/i18n": "^4.45.0"
44
51
  },
45
52
  "peerDependencies": {
46
53
  "react": "^18.3.1"
47
54
  },
48
- "gitHead": "0784373d42942edecbb0ab43e62e7caaefe92c3a"
55
+ "gitHead": "9bb2a2ab74c81e97ba6a060ab2867efb15b9e5c4"
49
56
  }
@@ -1,27 +0,0 @@
1
- import * as React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import AppBar from '../app-bar';
4
- import { __createStore, SliceState, Store, __StoreProvider as Provider } from '@elementor/store';
5
- import { slice } from '@elementor/editor-documents';
6
-
7
- describe( 'AppBar component', () => {
8
- let store: Store< SliceState< typeof slice > >;
9
-
10
- beforeEach( () => {
11
- store = __createStore();
12
- } );
13
-
14
- it( 'should render elementor logo', () => {
15
- // Act.
16
- render(
17
- <Provider store={ store }>
18
- <AppBar />
19
- </Provider>
20
- );
21
-
22
- // Assert.
23
- const logoTitle = screen.queryByText( 'Elementor Logo' );
24
-
25
- expect( logoTitle ).toBeInTheDocument();
26
- } );
27
- } );
@@ -1,37 +0,0 @@
1
- import * as React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import ResponsiveLocation from '../responsive-location';
4
- import PrimaryActionLocation from '../primary-action-location';
5
- import PageIndicationLocation from '../page-indication-location';
6
- import { injectIntoPageIndication, injectIntoPrimaryAction, injectIntoResponsive } from '../../../locations';
7
-
8
- describe( 'Locations components', () => {
9
- it.each( [
10
- {
11
- name: 'page indication',
12
- component: PageIndicationLocation,
13
- inject: injectIntoPageIndication,
14
- },
15
- {
16
- name: 'responsive',
17
- component: ResponsiveLocation,
18
- inject: injectIntoResponsive,
19
- },
20
- {
21
- name: 'primary action',
22
- component: PrimaryActionLocation,
23
- inject: injectIntoPrimaryAction,
24
- },
25
- ] )( 'should inject into $name', ( { inject, component: Component } ) => {
26
- // Act.
27
- inject( {
28
- id: 'test',
29
- component: () => <span>test</span>,
30
- } );
31
-
32
- // Assert.
33
- render( <Component /> );
34
-
35
- expect( screen.getByText( 'test' ) ).toBeInTheDocument();
36
- } );
37
- } );
@@ -1,153 +0,0 @@
1
- import * as React from 'react';
2
- import { fireEvent, render, screen } from '@testing-library/react';
3
- import MainMenuLocation from '../main-menu-location';
4
- import ToolsMenuLocation from '../tools-menu-location';
5
- import UtilitiesMenuLocation from '../utilities-menu-location';
6
- import { integrationsMenu, mainMenu, toolsMenu, utilitiesMenu } from '../../../locations';
7
- import { createMockMenuAction, createMockMenuLink, createMockMenuToggleAction, createMockSubMenu } from 'test-utils';
8
-
9
- describe( 'Menus components', () => {
10
- describe( 'Main menu', () => {
11
- it( 'should render ordered menu items in a popover', () => {
12
- // Arrange.
13
- mainMenu.registerAction( {
14
- ...createMockMenuAction(),
15
- id: 'test-action',
16
- } );
17
-
18
- mainMenu.registerToggleAction( {
19
- ...createMockMenuToggleAction(),
20
- id: 'test-toggle-action',
21
- } );
22
-
23
- mainMenu.registerLink( {
24
- ...createMockMenuLink(),
25
- group: 'exits',
26
- id: 'test-link',
27
- } );
28
-
29
- // Act.
30
- render( <MainMenuLocation /> );
31
-
32
- fireEvent.click( screen.getByRole( 'button' ) ); // Opens the popover menu
33
-
34
- // Assert.
35
- const menuItems = screen.getAllByRole( 'menuitem' );
36
-
37
- expect( menuItems ).toHaveLength( 3 );
38
-
39
- // Ensure the last one is the link, so the order is correct (`default`, then `exits`).
40
- expect( menuItems[ 2 ] ).toHaveAttribute( 'href', 'https://elementor.com' );
41
- } );
42
-
43
- it( 'should render the integrations menu inside the tools menu if there are registered integrations', () => {
44
- integrationsMenu.registerAction( {
45
- ...createMockMenuAction(),
46
- } );
47
-
48
- render( <ToolsMenuLocation /> );
49
-
50
- expect( screen.getByLabelText( 'Integrations' ) ).toBeInTheDocument();
51
-
52
- fireEvent.click( screen.getByLabelText( 'Integrations' ) ); // Opens the integrations menu.
53
-
54
- expect( screen.getByText( 'Test' ) ).toBeInTheDocument();
55
- } );
56
-
57
- it( 'should render groups and nested groups of actions', () => {
58
- const subMenu = integrationsMenu.registerSubMenu( {
59
- ...createMockSubMenu(),
60
- } );
61
- subMenu.registerAction( {
62
- ...createMockMenuAction(),
63
- id: 'sub-group-action',
64
- } );
65
- const subMenuSubGroup = subMenu.registerSubMenu( {
66
- ...createMockSubMenu( { title: 'Sub group' } ),
67
- } );
68
- subMenuSubGroup.registerAction( {
69
- ...createMockMenuAction( { title: 'Sub group action' } ),
70
- id: 'sub-sub-group-action',
71
- } );
72
-
73
- // Act.
74
- render( <ToolsMenuLocation /> );
75
-
76
- // Assert.
77
- expect( screen.getByLabelText( 'Integrations' ) ).toBeInTheDocument();
78
-
79
- // Act.
80
- fireEvent.click( screen.getByLabelText( 'Integrations' ) ); // Opens the integrations menu.
81
-
82
- // Assert.
83
- expect( screen.getByText( 'Test Group' ) ).toBeInTheDocument();
84
-
85
- // Act.
86
- fireEvent.mouseOver( screen.getByText( 'Test Group' ) ); // Opens the Test Group menu.
87
-
88
- // Assert.
89
- expect( screen.getByText( 'Sub group' ) ).toBeInTheDocument();
90
-
91
- // Act.
92
- fireEvent.mouseOver( screen.getByText( 'Sub group' ) ); // Opens the Sub group menu.
93
-
94
- expect( screen.getByText( 'Sub group action' ) ).toBeInTheDocument();
95
- } );
96
-
97
- it( 'should NOT render the integrations menu inside if there are no registered integrations', () => {
98
- // Act.
99
- render( <MainMenuLocation /> );
100
-
101
- fireEvent.click( screen.getByRole( 'button' ) ); // Opens the popover menu
102
-
103
- // Assert.
104
- expect( screen.queryByText( 'Integrations' ) ).not.toBeInTheDocument();
105
- } );
106
- } );
107
-
108
- describe.each( [
109
- {
110
- menuName: 'Tools',
111
- menu: toolsMenu,
112
- maxItems: 5,
113
- Component: ToolsMenuLocation,
114
- },
115
- {
116
- menuName: 'Utilities',
117
- menu: utilitiesMenu,
118
- maxItems: 4,
119
- Component: UtilitiesMenuLocation,
120
- },
121
- ] )( '$menuName menu', ( { maxItems, menu, Component } ) => {
122
- it( `should render ${ maxItems } menu items in a toolbar and the rest in a popover`, () => {
123
- // Arrange.
124
- const extraAfterMax = 2;
125
-
126
- for ( let i = 0; i < maxItems + extraAfterMax; i++ ) {
127
- menu.registerAction( {
128
- id: `test-${ i }`,
129
- props: {
130
- title: `Test ${ i }`,
131
- icon: () => <span>a</span>,
132
- },
133
- } );
134
- }
135
-
136
- // Act.
137
- render( <Component /> );
138
-
139
- // Assert.
140
- const toolbarButtons = screen.getAllByRole( 'button' );
141
- const popoverButton = toolbarButtons[ maxItems ];
142
-
143
- expect( toolbarButtons ).toHaveLength( maxItems + 1 ); // Including the popover button.
144
- expect( popoverButton ).toHaveAttribute( 'aria-label', 'More' );
145
-
146
- // Act.
147
- fireEvent.click( popoverButton );
148
-
149
- // Assert.
150
- expect( screen.getAllByRole( 'menuitem' ) ).toHaveLength( extraAfterMax );
151
- } );
152
- } );
153
- } );
@@ -1,57 +0,0 @@
1
- import * as React from 'react';
2
- import SettingsButton from '../settings-button';
3
- import {
4
- __privateOpenRoute as openRoute,
5
- __privateUseRouteStatus as useRouteStatus,
6
- } from '@elementor/editor-v1-adapters';
7
- import { fireEvent, render, screen } from '@testing-library/react';
8
- import { __useActiveDocument as useActiveDocument } from '@elementor/editor-documents';
9
- import { createMockDocument } from 'test-utils';
10
-
11
- jest.mock( '@elementor/editor-v1-adapters', () => ( {
12
- __privateOpenRoute: jest.fn(),
13
- __privateUseRouteStatus: jest.fn( () => ( { isActive: false, isBlocked: false } ) ),
14
- } ) );
15
-
16
- jest.mock( '@elementor/editor-documents', () => ( {
17
- __useActiveDocument: jest.fn(),
18
- __useHostDocument: jest.fn(),
19
- } ) );
20
-
21
- describe( '@elementor/editor-app-bar - App bar document settings button', () => {
22
- beforeEach( () => {
23
- jest.mocked( useActiveDocument ).mockReturnValue(
24
- createMockDocument( {
25
- type: { value: 'wp-page', label: 'Page' },
26
- } )
27
- );
28
- } );
29
-
30
- it( 'should open the document settings panel on click', () => {
31
- // Arrange.
32
- render( <SettingsButton /> );
33
-
34
- // Act.
35
- fireEvent.click( screen.getByRole( 'button' ) );
36
-
37
- // Assert.
38
- expect( openRoute ).toHaveBeenCalledTimes( 1 );
39
- expect( openRoute ).toHaveBeenCalledWith( 'panel/page-settings/settings' );
40
- } );
41
-
42
- it( 'should have the correct props for disabled and selected', () => {
43
- // Arrange.
44
- jest.mocked( useRouteStatus ).mockReturnValue( { isActive: true, isBlocked: true } );
45
-
46
- // Act.
47
- render( <SettingsButton /> );
48
-
49
- // Assert.
50
- const button = screen.getByRole( 'button' );
51
-
52
- expect( button ).toBeDisabled();
53
- expect( button ).toHaveAttribute( 'aria-pressed', 'true' );
54
- expect( useRouteStatus ).toHaveBeenCalledTimes( 1 );
55
- expect( useRouteStatus ).toHaveBeenCalledWith( 'panel/page-settings' );
56
- } );
57
- } );
@@ -1,43 +0,0 @@
1
- import { renderHook } from '@testing-library/react';
2
- import useActionProps from '../use-action-props';
3
- import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
4
- import { createMockDocument } from 'test-utils';
5
- import { __useActiveDocument as useActiveDocument } from '@elementor/editor-documents';
6
-
7
- jest.mock( '@elementor/editor-documents', () => ( {
8
- __useActiveDocument: jest.fn(),
9
- } ) );
10
-
11
- jest.mock( '@elementor/editor-v1-adapters', () => ( {
12
- __privateRunCommand: jest.fn(),
13
- } ) );
14
-
15
- describe( '@elementor/editor-app-bar - useDocumentPreviewProps', () => {
16
- it( 'should open the document preview', () => {
17
- // Arrange.
18
- jest.mocked( useActiveDocument ).mockReturnValue( createMockDocument() );
19
-
20
- const command = 'editor/documents/preview';
21
- const args = { id: 1, force: true };
22
-
23
- // Act.
24
- const { result } = renderHook( () => useActionProps() );
25
- result.current.onClick();
26
-
27
- // Assert.
28
- expect( runCommand ).toBeCalledTimes( 1 );
29
- expect( runCommand ).toHaveBeenCalledWith( command, args );
30
- } );
31
-
32
- it( 'should not run the command when there is no document', () => {
33
- // Arrange.
34
- jest.mocked( useActiveDocument ).mockReturnValue( null );
35
-
36
- // Act.
37
- const { result } = renderHook( () => useActionProps() );
38
- result.current.onClick();
39
-
40
- // Assert.
41
- expect( runCommand ).toBeCalledTimes( 0 );
42
- } );
43
- } );
@@ -1,39 +0,0 @@
1
- import * as React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import PrimaryActionMenu from '../primary-action-menu';
4
- import { documentOptionsMenu } from '../../locations';
5
-
6
- jest.mock( '@elementor/editor-documents' );
7
-
8
- describe( '@elementor/editor-app-bar - Primary action menu', () => {
9
- it( 'should render the actions ordered properly (save, default)', () => {
10
- // Arrange.
11
- documentOptionsMenu.registerAction( {
12
- id: 'test--first-action',
13
- group: 'save',
14
- props: {
15
- title: 'First action',
16
- icon: () => <span>a</span>,
17
- },
18
- } );
19
-
20
- documentOptionsMenu.registerAction( {
21
- id: 'test--second-action',
22
- group: 'default',
23
- props: {
24
- title: 'Second action',
25
- icon: () => <span>a</span>,
26
- },
27
- } );
28
-
29
- // Act.
30
- render( <PrimaryActionMenu open={ true } anchorEl={ document.body } /> );
31
-
32
- // Assert.
33
- const menuItems = screen.getAllByRole( 'menuitem' );
34
-
35
- expect( menuItems ).toHaveLength( 2 );
36
- expect( menuItems[ 0 ] ).toHaveTextContent( 'First action' );
37
- expect( menuItems[ 1 ] ).toHaveTextContent( 'Second action' );
38
- } );
39
- } );
@@ -1,222 +0,0 @@
1
- import * as React from 'react';
2
- import PrimaryAction from '../primary-action';
3
- import { fireEvent, render, screen } from '@testing-library/react';
4
- import { createMockDocument } from 'test-utils';
5
- import {
6
- __useActiveDocument as useActiveDocument,
7
- __useActiveDocumentActions as useActiveDocumentActions,
8
- } from '@elementor/editor-documents';
9
- import { __privateUseIsPreviewMode as useIsPreviewMode } from '@elementor/editor-v1-adapters';
10
-
11
- jest.mock( '@elementor/editor-documents', () => ( {
12
- __useActiveDocument: jest.fn(),
13
- __useActiveDocumentActions: jest.fn(),
14
- } ) );
15
-
16
- jest.mock( '@elementor/editor-v1-adapters', () => ( {
17
- __privateUseIsPreviewMode: jest.fn(),
18
- } ) );
19
-
20
- const actionsMock = {
21
- save: jest.fn(),
22
- saveDraft: jest.fn(),
23
- saveTemplate: jest.fn(),
24
- copyAndShare: jest.fn(),
25
- };
26
-
27
- describe( '@elementor/editor-app-bar - Top Bar Primary Action', () => {
28
- beforeEach( () => {
29
- jest.mocked( useActiveDocumentActions ).mockReturnValue( actionsMock );
30
- jest.mocked( useIsPreviewMode ).mockReturnValue( false );
31
- } );
32
-
33
- afterEach( () => {
34
- jest.clearAllMocks();
35
- } );
36
-
37
- it( 'should not render when there is no active document', () => {
38
- // Arrange.
39
- jest.mocked( useActiveDocument ).mockReturnValue( null );
40
-
41
- // Act.
42
- const { container } = render( <PrimaryAction /> );
43
-
44
- // Assert.
45
- expect( container ).toBeEmptyDOMElement();
46
- } );
47
-
48
- it( 'should have "Submit" text when the user cannot publish the document', () => {
49
- // Arrange.
50
- const mockDocument = createMockDocument( {
51
- userCan: {
52
- publish: false,
53
- },
54
- } );
55
-
56
- jest.mocked( useActiveDocument ).mockReturnValue( mockDocument );
57
-
58
- // Act.
59
- render( <PrimaryAction /> );
60
-
61
- // Assert.
62
- expect( screen.getAllByRole( 'button' )[ 0 ] ).toHaveTextContent( 'Submit' );
63
- } );
64
-
65
- it( 'should have "Publish" text when the user can publish the document', () => {
66
- // Arrange.
67
- const mockDocument = createMockDocument( {
68
- userCan: {
69
- publish: true,
70
- },
71
- } );
72
-
73
- jest.mocked( useActiveDocument ).mockReturnValue( mockDocument );
74
-
75
- // Act.
76
- render( <PrimaryAction /> );
77
-
78
- // Assert.
79
- expect( screen.getAllByRole( 'button' )[ 0 ] ).toHaveTextContent( 'Publish' );
80
- } );
81
-
82
- it( 'should disable main and the menu buttons when the document is a Kit', () => {
83
- // Arrange.
84
- const mockDocument = createMockDocument( {
85
- isDirty: true,
86
- type: {
87
- value: 'kit',
88
- label: 'Kit',
89
- },
90
- } );
91
-
92
- jest.mocked( useActiveDocument ).mockReturnValue( mockDocument );
93
-
94
- // Act.
95
- render( <PrimaryAction /> );
96
-
97
- // Assert.
98
- const mainButton = screen.getByText( 'Publish' );
99
- const menuButton = screen.getByLabelText( 'Save Options' );
100
-
101
- expect( mainButton ).toBeDisabled();
102
- expect( menuButton ).toBeDisabled();
103
- } );
104
-
105
- it( 'should disable main and the menu buttons when in preview mode', () => {
106
- // Arrange.
107
- const mockDocument = createMockDocument();
108
-
109
- jest.mocked( useActiveDocument ).mockReturnValue( mockDocument );
110
- jest.mocked( useIsPreviewMode ).mockReturnValue( true );
111
-
112
- // Act.
113
- render( <PrimaryAction /> );
114
-
115
- // Assert.
116
- const mainButton = screen.getByText( 'Publish' );
117
- const menuButton = screen.getByLabelText( 'Save Options' );
118
-
119
- expect( mainButton ).toBeDisabled();
120
- expect( menuButton ).toBeDisabled();
121
- } );
122
-
123
- it( 'should disable only the main button when the document is pristine', () => {
124
- // Arrange.
125
- const mockDocument = createMockDocument( { isDirty: false } );
126
-
127
- jest.mocked( useActiveDocument ).mockReturnValue( mockDocument );
128
-
129
- // Act.
130
- render( <PrimaryAction /> );
131
-
132
- // Assert.
133
- const mainButton = screen.getByText( 'Publish' );
134
- const menuButton = screen.getByLabelText( 'Save Options' );
135
-
136
- expect( mainButton ).toBeDisabled();
137
- expect( menuButton ).toBeEnabled();
138
- } );
139
-
140
- it( 'should always enable main and menu buttons when the document status is draft', () => {
141
- // Arrange.
142
- const mockDocument = createMockDocument( {
143
- isDirty: false,
144
- status: {
145
- value: 'draft',
146
- label: 'Draft',
147
- },
148
- } );
149
-
150
- jest.mocked( useActiveDocument ).mockReturnValue( mockDocument );
151
-
152
- // Act.
153
- render( <PrimaryAction /> );
154
-
155
- // Assert.
156
- const mainButton = screen.getByText( 'Publish' );
157
- const menuButton = screen.getByLabelText( 'Save Options' );
158
-
159
- expect( mainButton ).toBeEnabled();
160
- expect( menuButton ).toBeEnabled();
161
- } );
162
-
163
- it( 'should save the active document on click', () => {
164
- // Arrange.
165
- const mockDocument = createMockDocument( { isDirty: true } );
166
-
167
- jest.mocked( useActiveDocument ).mockReturnValue( mockDocument );
168
-
169
- // Act.
170
- render( <PrimaryAction /> );
171
-
172
- fireEvent.click( screen.getAllByRole( 'button' )[ 0 ] );
173
-
174
- // Assert.
175
- expect( actionsMock.save ).toHaveBeenCalledTimes( 1 );
176
- } );
177
-
178
- it( 'should show a loader & not save when there is save in progress', () => {
179
- // Arrange.
180
- const mockDocument = createMockDocument( {
181
- isDirty: true,
182
- isSaving: true,
183
- } );
184
-
185
- jest.mocked( useActiveDocument ).mockReturnValue( mockDocument );
186
-
187
- // Act.
188
- render( <PrimaryAction /> );
189
-
190
- const button = screen.getAllByRole( 'button' )[ 0 ];
191
- const loader = screen.getAllByRole( 'progressbar' )[ 0 ];
192
-
193
- fireEvent.click( button );
194
-
195
- // Assert.
196
- expect( actionsMock.save ).not.toHaveBeenCalled();
197
- expect( loader ).toBeInTheDocument();
198
- expect( button ).toHaveTextContent( '' );
199
- } );
200
-
201
- it( 'should not show a loader when the button is disabled', () => {
202
- // Arrange.
203
- const mockDocument = createMockDocument( {
204
- type: {
205
- value: 'kit',
206
- label: 'Kit',
207
- }, // Disables the button.
208
- isSaving: true,
209
- } );
210
-
211
- jest.mocked( useActiveDocument ).mockReturnValue( mockDocument );
212
-
213
- // Act.
214
- render( <PrimaryAction /> );
215
- const button = screen.getAllByRole( 'button' )[ 0 ];
216
- const loader = screen.queryByRole( 'progressbar' );
217
-
218
- // Assert.
219
- expect( loader ).not.toBeInTheDocument();
220
- expect( button ).not.toHaveTextContent( '' );
221
- } );
222
- } );