|
1 | 1 | /* (c) Copyright Frontify Ltd., all rights reserved. */ |
2 | 2 |
|
3 | | -import { mount } from 'cypress/react18'; |
4 | 3 | import { AssetDummy, withAppBridgeBlockStubs } from '@frontify/app-bridge'; |
| 4 | +import { Security } from '@frontify/guideline-blocks-settings'; |
| 5 | +import { mount } from 'cypress/react18'; |
| 6 | + |
5 | 7 | import { AudioBlock } from './AudioBlock'; |
6 | 8 | import { TextPosition } from './types'; |
7 | | -import { AUDIO_ID } from './settings'; |
8 | | -import { Security } from '@frontify/guideline-blocks-settings'; |
| 9 | +import { ATTACHMENTS_ASSET_ID, AUDIO_ID } from './settings'; |
9 | 10 |
|
10 | 11 | const AudioBlockSelector = '[data-test-id="audio-block"]'; |
11 | 12 | const AudioTagSelector = '[data-test-id="audio-block-audio-tag"]'; |
12 | 13 | const UploadPlaceholderSelector = '[data-test-id="block-inject-button"]'; |
13 | 14 | const AudioBlockTitleHtmlSelector = '[data-test-id="block-title"] [data-test-id="rte-content-html"]'; |
14 | 15 | const AudioBlockDescriptionHtmlSelector = '[data-test-id="block-description"] [data-test-id="rte-content-html"]'; |
15 | 16 | const DownloadButtonSelector = '[data-test-id="download-button"]'; |
| 17 | +const AttachmentsTriggerSelector = '[data-test-id="attachments-flyout-button"]'; |
| 18 | +const ViewModeAddonsSelector = '[data-test-id="view-mode-addons"]'; |
| 19 | +const BlockWrapperSelector = '[data-test-id="block-item-wrapper"]'; |
16 | 20 |
|
17 | 21 | const Title = '[{"type":"heading3","children":[{"text":"Audio Title"}]}]'; |
18 | 22 | const Description = '[{"type":"p","children":[{"text":"Audio Description"}]}]'; |
@@ -165,4 +169,54 @@ describe('Audio Block', () => { |
165 | 169 | mount(<AudioBlockWithStubs />); |
166 | 170 | cy.get(DownloadButtonSelector).should('not.exist'); |
167 | 171 | }); |
| 172 | + |
| 173 | + it('should render attachment button in view mode', () => { |
| 174 | + const asset = AssetDummy.with(312); |
| 175 | + const [AudioBlockWithStubs] = withAppBridgeBlockStubs(AudioBlock, { |
| 176 | + blockAssets: { |
| 177 | + [ATTACHMENTS_ASSET_ID]: [asset, asset], |
| 178 | + [AUDIO_ID]: [asset], |
| 179 | + }, |
| 180 | + }); |
| 181 | + mount(<AudioBlockWithStubs />); |
| 182 | + cy.get(AttachmentsTriggerSelector).should('have.length', 1).and('be.visible').and('contain.text', 2); |
| 183 | + }); |
| 184 | + |
| 185 | + it('should hide block wrapper and toolbar in view mode', () => { |
| 186 | + const asset = AssetDummy.with(312); |
| 187 | + const [AudioBlockWithStubs] = withAppBridgeBlockStubs(AudioBlock, { |
| 188 | + blockAssets: { |
| 189 | + [ATTACHMENTS_ASSET_ID]: [asset, asset], |
| 190 | + [AUDIO_ID]: [asset], |
| 191 | + }, |
| 192 | + }); |
| 193 | + mount(<AudioBlockWithStubs />); |
| 194 | + cy.get(BlockWrapperSelector).should('not.exist'); |
| 195 | + }); |
| 196 | + |
| 197 | + it('should render attachment toolbar button in edit mode', () => { |
| 198 | + const asset = AssetDummy.with(312); |
| 199 | + const [AudioBlockWithStubs] = withAppBridgeBlockStubs(AudioBlock, { |
| 200 | + blockAssets: { |
| 201 | + [ATTACHMENTS_ASSET_ID]: [asset, asset], |
| 202 | + [AUDIO_ID]: [asset], |
| 203 | + }, |
| 204 | + editorState: true, |
| 205 | + }); |
| 206 | + mount(<AudioBlockWithStubs />); |
| 207 | + cy.get(AttachmentsTriggerSelector).should('have.length', 1).and('not.be.visible').and('contain.text', 2); |
| 208 | + }); |
| 209 | + |
| 210 | + it('should hide download and attachment buttons in edit mode', () => { |
| 211 | + const asset = AssetDummy.with(312); |
| 212 | + const [AudioBlockWithStubs] = withAppBridgeBlockStubs(AudioBlock, { |
| 213 | + blockAssets: { |
| 214 | + [ATTACHMENTS_ASSET_ID]: [asset, asset], |
| 215 | + [AUDIO_ID]: [asset], |
| 216 | + }, |
| 217 | + editorState: true, |
| 218 | + }); |
| 219 | + mount(<AudioBlockWithStubs />); |
| 220 | + cy.get(ViewModeAddonsSelector).should('not.exist'); |
| 221 | + }); |
168 | 222 | }); |
0 commit comments