|
1 | 1 | import {Style} from 'editor/models/Style'; |
2 | 2 |
|
| 3 | +import {editor} from 'pageflow-scrolled/editor'; |
3 | 4 | import {ScrolledEntry} from 'editor/models/ScrolledEntry'; |
4 | 5 | import {factories, useFakeTranslations} from 'pageflow/testHelpers'; |
5 | 6 | import {normalizeSeed} from 'support'; |
@@ -77,6 +78,161 @@ describe('Style', () => { |
77 | 78 | expect(style.inputType()).toEqual('color'); |
78 | 79 | }); |
79 | 80 |
|
| 81 | + describe('.getTypesForContentElement', () => { |
| 82 | + it('returns empty object when no margin scale is defined', () => { |
| 83 | + editor.contentElementTypes.register('textBlock', {}); |
| 84 | + |
| 85 | + const entry = factories.entry( |
| 86 | + ScrolledEntry, |
| 87 | + {}, |
| 88 | + { |
| 89 | + entryTypeSeed: normalizeSeed({ |
| 90 | + contentElements: [ |
| 91 | + {id: 1, typeName: 'textBlock'} |
| 92 | + ] |
| 93 | + }) |
| 94 | + } |
| 95 | + ); |
| 96 | + |
| 97 | + const contentElement = entry.contentElements.get(1); |
| 98 | + const result = Style.getTypesForContentElement({entry, contentElement}); |
| 99 | + |
| 100 | + expect(result).toEqual({}); |
| 101 | + }); |
| 102 | + |
| 103 | + it('returns margin types based on content element margin scale', () => { |
| 104 | + editor.contentElementTypes.register('textBlock', {}); |
| 105 | + |
| 106 | + const entry = factories.entry( |
| 107 | + ScrolledEntry, |
| 108 | + {}, |
| 109 | + { |
| 110 | + entryTypeSeed: normalizeSeed({ |
| 111 | + contentElements: [ |
| 112 | + {id: 1, typeName: 'textBlock'} |
| 113 | + ], |
| 114 | + themeOptions: { |
| 115 | + properties: { |
| 116 | + root: { |
| 117 | + 'contentElementMargin-sm': '0.5rem', |
| 118 | + 'contentElementMargin-md': '1rem', |
| 119 | + 'contentElementMargin-lg': '1.5rem' |
| 120 | + } |
| 121 | + } |
| 122 | + }, |
| 123 | + themeTranslations: { |
| 124 | + scales: { |
| 125 | + contentElementMargin: { |
| 126 | + sm: 'Small', |
| 127 | + md: 'Medium', |
| 128 | + lg: 'Large' |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + }) |
| 133 | + } |
| 134 | + ); |
| 135 | + |
| 136 | + const contentElement = entry.contentElements.get(1); |
| 137 | + const result = Style.getTypesForContentElement({entry, contentElement}); |
| 138 | + |
| 139 | + expect(result).toMatchObject({ |
| 140 | + marginTop: { |
| 141 | + inputType: 'slider', |
| 142 | + values: ['sm', 'md', 'lg'], |
| 143 | + texts: ['Small', 'Medium', 'Large'] |
| 144 | + }, |
| 145 | + marginBottom: { |
| 146 | + inputType: 'slider', |
| 147 | + values: ['sm', 'md', 'lg'], |
| 148 | + texts: ['Small', 'Medium', 'Large'] |
| 149 | + } |
| 150 | + }); |
| 151 | + }); |
| 152 | + it('sets resetValue from content element defaultConfig', () => { |
| 153 | + editor.contentElementTypes.register('heading', { |
| 154 | + defaultConfig: {marginTop: 'none'} |
| 155 | + }); |
| 156 | + |
| 157 | + const entry = factories.entry( |
| 158 | + ScrolledEntry, |
| 159 | + {}, |
| 160 | + { |
| 161 | + entryTypeSeed: normalizeSeed({ |
| 162 | + contentElements: [ |
| 163 | + {id: 1, typeName: 'heading'} |
| 164 | + ], |
| 165 | + themeOptions: { |
| 166 | + properties: { |
| 167 | + root: { |
| 168 | + 'contentElementMargin-sm': '0.5rem', |
| 169 | + 'contentElementMargin-md': '1rem', |
| 170 | + 'contentElementMargin-lg': '1.5rem' |
| 171 | + } |
| 172 | + } |
| 173 | + }, |
| 174 | + themeTranslations: { |
| 175 | + scales: { |
| 176 | + contentElementMargin: { |
| 177 | + sm: 'Small', |
| 178 | + md: 'Medium', |
| 179 | + lg: 'Large' |
| 180 | + } |
| 181 | + } |
| 182 | + } |
| 183 | + }) |
| 184 | + } |
| 185 | + ); |
| 186 | + |
| 187 | + const contentElement = entry.contentElements.get(1); |
| 188 | + const result = Style.getTypesForContentElement({entry, contentElement}); |
| 189 | + |
| 190 | + expect(result.marginTop.resetValue).toEqual('none'); |
| 191 | + expect(result.marginBottom).not.toHaveProperty('resetValue'); |
| 192 | + }); |
| 193 | + |
| 194 | + it('includes default value from margin scale', () => { |
| 195 | + editor.contentElementTypes.register('textBlock', {}); |
| 196 | + |
| 197 | + const entry = factories.entry( |
| 198 | + ScrolledEntry, |
| 199 | + {}, |
| 200 | + { |
| 201 | + entryTypeSeed: normalizeSeed({ |
| 202 | + contentElements: [ |
| 203 | + {id: 1, typeName: 'textBlock'} |
| 204 | + ], |
| 205 | + themeOptions: { |
| 206 | + properties: { |
| 207 | + root: { |
| 208 | + 'contentElementMargin-sm': '0.5rem', |
| 209 | + 'contentElementMargin-md': '1rem', |
| 210 | + 'contentElementMargin-lg': '1.5rem', |
| 211 | + 'contentElementMarginStyleDefault': '0.5rem' |
| 212 | + } |
| 213 | + } |
| 214 | + }, |
| 215 | + themeTranslations: { |
| 216 | + scales: { |
| 217 | + contentElementMargin: { |
| 218 | + sm: 'Small', |
| 219 | + md: 'Medium', |
| 220 | + lg: 'Large' |
| 221 | + } |
| 222 | + } |
| 223 | + } |
| 224 | + }) |
| 225 | + } |
| 226 | + ); |
| 227 | + |
| 228 | + const contentElement = entry.contentElements.get(1); |
| 229 | + const result = Style.getTypesForContentElement({entry, contentElement}); |
| 230 | + |
| 231 | + expect(result.marginTop.defaultValue).toEqual('sm'); |
| 232 | + expect(result.marginBottom.defaultValue).toEqual('sm'); |
| 233 | + }); |
| 234 | + }); |
| 235 | + |
80 | 236 | describe('.getImageModifierTypes', () => { |
81 | 237 | const commonPrefix = 'pageflow_scrolled.editor.aspect_ratios'; |
82 | 238 | const themePrefix = `pageflow_scrolled.editor.themes.custom.aspect_ratios`; |
|
0 commit comments