|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0 and the Server Side Public License, v 1; you may not use this file except |
| 5 | + * in compliance with, at your election, the Elastic License 2.0 or the Server |
| 6 | + * Side Public License, v 1. |
| 7 | + */ |
| 8 | + |
| 9 | +import { |
| 10 | + functionWrapper, |
| 11 | + elasticOutline, |
| 12 | + elasticLogo, |
| 13 | +} from '../../../presentation_util/common/lib'; |
| 14 | +import { getFunctionErrors } from '../i18n'; |
| 15 | +import { revealImageFunction } from './reveal_image_function'; |
| 16 | +import { Origin } from '../types'; |
| 17 | +import { ExecutionContext } from 'src/plugins/expressions'; |
| 18 | + |
| 19 | +const errors = getFunctionErrors().revealImage; |
| 20 | + |
| 21 | +describe('revealImageFunction', () => { |
| 22 | + const fn = functionWrapper(revealImageFunction); |
| 23 | + |
| 24 | + it('returns a render as revealImage', () => { |
| 25 | + const result = fn( |
| 26 | + 0.5, |
| 27 | + { |
| 28 | + image: null, |
| 29 | + emptyImage: null, |
| 30 | + origin: Origin.BOTTOM, |
| 31 | + }, |
| 32 | + {} as ExecutionContext |
| 33 | + ); |
| 34 | + expect(result).toHaveProperty('type', 'render'); |
| 35 | + expect(result).toHaveProperty('as', 'revealImage'); |
| 36 | + }); |
| 37 | + |
| 38 | + describe('context', () => { |
| 39 | + it('throws when context is not a number between 0 and 1', () => { |
| 40 | + expect(() => { |
| 41 | + fn( |
| 42 | + 10, |
| 43 | + { |
| 44 | + image: elasticLogo, |
| 45 | + emptyImage: elasticOutline, |
| 46 | + origin: Origin.TOP, |
| 47 | + }, |
| 48 | + {} as ExecutionContext |
| 49 | + ); |
| 50 | + }).toThrow(new RegExp(errors.invalidPercent(10).message)); |
| 51 | + |
| 52 | + expect(() => { |
| 53 | + fn( |
| 54 | + -0.1, |
| 55 | + { |
| 56 | + image: elasticLogo, |
| 57 | + emptyImage: elasticOutline, |
| 58 | + origin: Origin.TOP, |
| 59 | + }, |
| 60 | + {} as ExecutionContext |
| 61 | + ); |
| 62 | + }).toThrow(new RegExp(errors.invalidPercent(-0.1).message)); |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + describe('args', () => { |
| 67 | + describe('image', () => { |
| 68 | + it('sets the image', () => { |
| 69 | + const result = fn( |
| 70 | + 0.89, |
| 71 | + { |
| 72 | + emptyImage: null, |
| 73 | + origin: Origin.TOP, |
| 74 | + image: elasticLogo, |
| 75 | + }, |
| 76 | + {} as ExecutionContext |
| 77 | + ).value; |
| 78 | + expect(result).toHaveProperty('image', elasticLogo); |
| 79 | + }); |
| 80 | + |
| 81 | + it('defaults to the Elastic outline logo', () => { |
| 82 | + const result = fn( |
| 83 | + 0.89, |
| 84 | + { |
| 85 | + emptyImage: null, |
| 86 | + origin: Origin.TOP, |
| 87 | + image: null, |
| 88 | + }, |
| 89 | + {} as ExecutionContext |
| 90 | + ).value; |
| 91 | + expect(result).toHaveProperty('image', elasticOutline); |
| 92 | + }); |
| 93 | + }); |
| 94 | + |
| 95 | + describe('emptyImage', () => { |
| 96 | + it('sets the background image', () => { |
| 97 | + const result = fn( |
| 98 | + 0, |
| 99 | + { |
| 100 | + emptyImage: elasticLogo, |
| 101 | + origin: Origin.TOP, |
| 102 | + image: null, |
| 103 | + }, |
| 104 | + {} as ExecutionContext |
| 105 | + ).value; |
| 106 | + expect(result).toHaveProperty('emptyImage', elasticLogo); |
| 107 | + }); |
| 108 | + |
| 109 | + it('sets emptyImage to null', () => { |
| 110 | + const result = fn( |
| 111 | + 0, |
| 112 | + { |
| 113 | + emptyImage: null, |
| 114 | + origin: Origin.TOP, |
| 115 | + image: null, |
| 116 | + }, |
| 117 | + {} as ExecutionContext |
| 118 | + ).value; |
| 119 | + expect(result).toHaveProperty('emptyImage', null); |
| 120 | + }); |
| 121 | + }); |
| 122 | + |
| 123 | + describe('origin', () => { |
| 124 | + it('sets which side to start the reveal from', () => { |
| 125 | + let result = fn( |
| 126 | + 1, |
| 127 | + { |
| 128 | + emptyImage: null, |
| 129 | + origin: Origin.TOP, |
| 130 | + image: null, |
| 131 | + }, |
| 132 | + {} as ExecutionContext |
| 133 | + ).value; |
| 134 | + expect(result).toHaveProperty('origin', 'top'); |
| 135 | + result = fn( |
| 136 | + 1, |
| 137 | + { |
| 138 | + emptyImage: null, |
| 139 | + origin: Origin.LEFT, |
| 140 | + image: null, |
| 141 | + }, |
| 142 | + {} as ExecutionContext |
| 143 | + ).value; |
| 144 | + expect(result).toHaveProperty('origin', 'left'); |
| 145 | + result = fn( |
| 146 | + 1, |
| 147 | + { |
| 148 | + emptyImage: null, |
| 149 | + origin: Origin.BOTTOM, |
| 150 | + image: null, |
| 151 | + }, |
| 152 | + {} as ExecutionContext |
| 153 | + ).value; |
| 154 | + expect(result).toHaveProperty('origin', 'bottom'); |
| 155 | + result = fn( |
| 156 | + 1, |
| 157 | + { |
| 158 | + emptyImage: null, |
| 159 | + origin: Origin.RIGHT, |
| 160 | + image: null, |
| 161 | + }, |
| 162 | + {} as ExecutionContext |
| 163 | + ).value; |
| 164 | + expect(result).toHaveProperty('origin', 'right'); |
| 165 | + }); |
| 166 | + }); |
| 167 | + }); |
| 168 | +}); |
0 commit comments