|
| 1 | +import 'contentElements/logoList/editor'; |
| 2 | + |
| 3 | +import {SliderInput} from 'pageflow/testHelpers'; |
| 4 | +import {renderContentElementConfigurationEditor, useEditorGlobals} from 'support'; |
| 5 | + |
| 6 | +describe('logoList configuration editor', () => { |
| 7 | + const {createEntry} = useEditorGlobals(); |
| 8 | + |
| 9 | + const marqueeSpeedScale = { |
| 10 | + 'logoListMarqueeSpeed-sm': '0.75', |
| 11 | + 'logoListMarqueeSpeed-md': '1' |
| 12 | + }; |
| 13 | + |
| 14 | + function render({configuration = {}, themeProperties = {}, themeTranslations} = {}) { |
| 15 | + const entry = createEntry({ |
| 16 | + themeOptions: {properties: {root: themeProperties}}, |
| 17 | + themeTranslations, |
| 18 | + contentElements: [{id: 1, typeName: 'logoList', configuration}] |
| 19 | + }); |
| 20 | + const contentElement = entry.contentElements.get(1); |
| 21 | + const postCommand = jest.fn(); |
| 22 | + contentElement.on('postCommand', postCommand); |
| 23 | + |
| 24 | + const configurationEditor = renderContentElementConfigurationEditor({ |
| 25 | + entry, |
| 26 | + contentElement |
| 27 | + }); |
| 28 | + |
| 29 | + return {configurationEditor, postCommand}; |
| 30 | + } |
| 31 | + |
| 32 | + it('displays logo height input if theme defines scale', () => { |
| 33 | + const {configurationEditor} = render({ |
| 34 | + themeProperties: {'logoListLogoHeight-sm': '2rem', 'logoListLogoHeight-md': '3rem'} |
| 35 | + }); |
| 36 | + |
| 37 | + expect(configurationEditor.inputPropertyNames()).toContain('logoHeight'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('hides logo height input if theme does not define scale', () => { |
| 41 | + const {configurationEditor} = render(); |
| 42 | + |
| 43 | + expect(configurationEditor.inputPropertyNames()).not.toContain('logoHeight'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('displays marquee speed input if marquee is enabled', () => { |
| 47 | + const {configurationEditor} = render({ |
| 48 | + configuration: {marquee: true}, |
| 49 | + themeProperties: marqueeSpeedScale |
| 50 | + }); |
| 51 | + |
| 52 | + expect(configurationEditor.visibleInputPropertyNames()).toContain('marqueeSpeed'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('hides marquee speed input if marquee is disabled', () => { |
| 56 | + const {configurationEditor} = render({themeProperties: marqueeSpeedScale}); |
| 57 | + |
| 58 | + expect(configurationEditor.visibleInputPropertyNames()).not.toContain('marqueeSpeed'); |
| 59 | + }); |
| 60 | + |
| 61 | + it('labels marquee speed steps with multipliers', () => { |
| 62 | + const {configurationEditor} = render({ |
| 63 | + configuration: {marquee: true, marqueeSpeed: 'lg'}, |
| 64 | + themeProperties: {...marqueeSpeedScale, 'logoListMarqueeSpeed-lg': '1.5'} |
| 65 | + }); |
| 66 | + |
| 67 | + expect(SliderInput.findByPropertyName('marqueeSpeed', {inView: configurationEditor}) |
| 68 | + .displayedValue()).toEqual('1.5×'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('prefers translated marquee speed labels', () => { |
| 72 | + const {configurationEditor} = render({ |
| 73 | + configuration: {marquee: true, marqueeSpeed: 'md'}, |
| 74 | + themeProperties: marqueeSpeedScale, |
| 75 | + themeTranslations: {scales: {logoListMarqueeSpeed: {md: 'Normal'}}} |
| 76 | + }); |
| 77 | + |
| 78 | + expect(SliderInput.findByPropertyName('marqueeSpeed', {inView: configurationEditor}) |
| 79 | + .displayedValue()).toEqual('Normal'); |
| 80 | + }); |
| 81 | + |
| 82 | + it('hides marquee speed input if theme does not define scale', () => { |
| 83 | + const {configurationEditor} = render({configuration: {marquee: true}}); |
| 84 | + |
| 85 | + expect(configurationEditor.inputPropertyNames()).not.toContain('marqueeSpeed'); |
| 86 | + }); |
| 87 | + |
| 88 | + it('starts marquee preview when sliding speed slider', () => { |
| 89 | + const {configurationEditor, postCommand} = render({ |
| 90 | + configuration: {marquee: true}, |
| 91 | + themeProperties: marqueeSpeedScale |
| 92 | + }); |
| 93 | + |
| 94 | + SliderInput.findByPropertyName('marqueeSpeed', {inView: configurationEditor}) |
| 95 | + .startSliding(); |
| 96 | + |
| 97 | + expect(postCommand).toHaveBeenCalledWith(1, {type: 'START_MARQUEE_PREVIEW'}); |
| 98 | + }); |
| 99 | + |
| 100 | + it('stops marquee preview when releasing speed slider', () => { |
| 101 | + const {configurationEditor, postCommand} = render({ |
| 102 | + configuration: {marquee: true}, |
| 103 | + themeProperties: marqueeSpeedScale |
| 104 | + }); |
| 105 | + |
| 106 | + SliderInput.findByPropertyName('marqueeSpeed', {inView: configurationEditor}) |
| 107 | + .stopSliding(); |
| 108 | + |
| 109 | + expect(postCommand).toHaveBeenCalledWith(1, {type: 'STOP_MARQUEE_PREVIEW'}); |
| 110 | + }); |
| 111 | +}); |
0 commit comments