|
1 | 1 | import helpers from '@percy/sdk-utils/test/helpers'; |
| 2 | +import { createRegion } from '../../createRegion'; |
2 | 3 |
|
3 | 4 | const { match } = Cypress.sinon; |
4 | 5 |
|
@@ -198,4 +199,79 @@ describe('percySnapshot', () => { |
198 | 199 | }); |
199 | 200 | }); |
200 | 201 | }); |
| 202 | + |
| 203 | + describe('createRegion function', () => { |
| 204 | + it('creates a region object with default values', () => { |
| 205 | + const region = createRegion(); |
| 206 | + expect(region).to.deep.equal({ algorithm: 'ignore', elementSelector: {} }); |
| 207 | + }); |
| 208 | + |
| 209 | + it('creates a region object with provided values', () => { |
| 210 | + const region = createRegion({ boundingBox: { x: 10, y: 20, width: 100, height: 200 }, algorithm: 'standard' }); |
| 211 | + expect(region).to.deep.equal({ |
| 212 | + algorithm: 'standard', |
| 213 | + elementSelector: { boundingBox: { x: 10, y: 20, width: 100, height: 200 } } |
| 214 | + }); |
| 215 | + }); |
| 216 | + |
| 217 | + it('adds configuration properties when using standard or intelliignore', () => { |
| 218 | + const region = createRegion({ algorithm: 'standard', diffSensitivity: 0.5 }); |
| 219 | + expect(region).to.have.property('configuration'); |
| 220 | + expect(region.configuration).to.deep.equal({ diffSensitivity: 0.5 }); |
| 221 | + }); |
| 222 | + |
| 223 | + it('adds assertion properties if diffIgnoreThreshold is provided', () => { |
| 224 | + const region = createRegion({ diffIgnoreThreshold: 0.1 }); |
| 225 | + expect(region).to.have.property('assertion'); |
| 226 | + expect(region.assertion).to.deep.equal({ diffIgnoreThreshold: 0.1 }); |
| 227 | + }); |
| 228 | + |
| 229 | + it('includes padding when provided', () => { |
| 230 | + const region = createRegion({ padding: { top: 10 } }); |
| 231 | + expect(region).to.have.property('padding').that.deep.equals({ top: 10 }); |
| 232 | + }); |
| 233 | + |
| 234 | + it('includes configuration when algorithm is standard', () => { |
| 235 | + const region = createRegion({ algorithm: 'standard', diffSensitivity: 5 }); |
| 236 | + expect(region.configuration.diffSensitivity).to.equal(5); |
| 237 | + }); |
| 238 | + |
| 239 | + it('includes configuration when algorithm is intelliignore', () => { |
| 240 | + const region = createRegion({ algorithm: 'intelliignore', imageIgnoreThreshold: 0.2 }); |
| 241 | + expect(region.configuration.imageIgnoreThreshold).to.equal(0.2); |
| 242 | + }); |
| 243 | + |
| 244 | + it('does not include configuration for ignore algorithm', () => { |
| 245 | + const region = createRegion({ algorithm: 'ignore', diffSensitivity: 5 }); |
| 246 | + expect(region.configuration).to.be.undefined; |
| 247 | + }); |
| 248 | + |
| 249 | + it('sets elementXpath in elementSelector', () => { |
| 250 | + const region = createRegion({ elementXpath: "//div[@id='test']" }); |
| 251 | + expect(region.elementSelector.elementXpath).to.equal("//div[@id='test']"); |
| 252 | + }); |
| 253 | + |
| 254 | + it('sets elementCSS in elementSelector', () => { |
| 255 | + const region = createRegion({ elementCSS: '.test-class' }); |
| 256 | + expect(region.elementSelector.elementCSS).to.equal('.test-class'); |
| 257 | + }); |
| 258 | + }); |
| 259 | + |
| 260 | + it('includes carouselsEnabled in configuration if provided', () => { |
| 261 | + const region = createRegion({ algorithm: 'standard', carouselsEnabled: true }); |
| 262 | + expect(region).to.have.property('configuration'); |
| 263 | + expect(region.configuration).to.have.property('carouselsEnabled', true); |
| 264 | + }); |
| 265 | + |
| 266 | + it('includes bannersEnabled in configuration if provided', () => { |
| 267 | + const region = createRegion({ algorithm: 'standard', bannersEnabled: true }); |
| 268 | + expect(region).to.have.property('configuration'); |
| 269 | + expect(region.configuration).to.have.property('bannersEnabled', true); |
| 270 | + }); |
| 271 | + |
| 272 | + it('includes adsEnabled in configuration if provided', () => { |
| 273 | + const region = createRegion({ algorithm: 'standard', adsEnabled: true }); |
| 274 | + expect(region).to.have.property('configuration'); |
| 275 | + expect(region.configuration).to.have.property('adsEnabled', true); |
| 276 | + }); |
201 | 277 | }); |
0 commit comments