|
1 | | -/** |
2 | | - * Copyright © Magento, Inc. All rights reserved. |
3 | | - * See COPYING.txt for license details. |
4 | | - */ |
5 | | - |
6 | | -define([ |
7 | | - 'jquery', |
8 | | - 'Magento_Swatches/js/swatch-renderer' |
9 | | -], function ($, SwatchRenderer) { |
10 | | - 'use strict'; |
11 | | - |
12 | | - describe('Testing "_RenderSwatchOptions" method of SwatchRenderer Widget', function () { |
13 | | - var widget, |
14 | | - html, |
15 | | - optionConfig, |
16 | | - attribute, |
17 | | - optionId = 2, |
18 | | - swathImageHeight = '60', |
19 | | - swathImageWidth = '70', |
20 | | - swathThumbImageHeight = '40', |
21 | | - swathThumbImageWidth = '50'; |
22 | | - |
23 | | - beforeEach(function () { |
24 | | - widget = new SwatchRenderer(); |
25 | | - attribute = { |
26 | | - id: 1, |
27 | | - options: [{ |
28 | | - id: optionId |
29 | | - }] |
30 | | - }; |
31 | | - |
32 | | - widget.options = { |
33 | | - classes: { |
34 | | - optionClass: 'swatch-option' |
35 | | - }, |
36 | | - jsonSwatchConfig: { |
37 | | - 1: { |
38 | | - 2: { |
39 | | - type: 2 |
40 | | - } |
41 | | - } |
42 | | - }, |
43 | | - jsonSwatchImageSizeConfig: { |
44 | | - swatchImage: { |
45 | | - width: swathImageWidth, |
46 | | - height: swathImageHeight |
47 | | - }, |
48 | | - swatchThumb: { |
49 | | - width: swathThumbImageWidth, |
50 | | - height: swathThumbImageHeight |
51 | | - } |
52 | | - } |
53 | | - }; |
54 | | - |
55 | | - optionConfig = widget.options.jsonSwatchConfig[attribute.id]; |
56 | | - html = $(widget._RenderSwatchOptions(attribute, 'option-label-control-id-1'))[0]; |
57 | | - }); |
58 | | - |
59 | | - it('check if swatch config has attribute id', function () { |
60 | | - expect(widget.options.jsonSwatchConfig.hasOwnProperty(attribute.id)).toEqual(true); |
61 | | - }); |
62 | | - |
63 | | - it('check if option config has option id', function () { |
64 | | - expect(optionConfig.hasOwnProperty(optionId)).toEqual(true); |
65 | | - }); |
66 | | - |
67 | | - it('check swatch thumbnail image height attribute', function () { |
68 | | - expect(html.hasAttribute('thumb-height')).toBe(true); |
69 | | - expect(html.getAttribute('thumb-height')).toEqual(swathThumbImageHeight); |
70 | | - }); |
71 | | - |
72 | | - it('check swatch thumbnail image width attribute', function () { |
73 | | - expect(html.hasAttribute('thumb-width')).toBe(true); |
74 | | - expect(html.getAttribute('thumb-width')).toEqual(swathThumbImageWidth); |
75 | | - }); |
76 | | - |
77 | | - it('check swatch image styles', function () { |
78 | | - expect(html.style.height).toEqual(swathImageHeight + 'px'); |
79 | | - expect(html.style.width).toEqual(swathImageWidth + 'px'); |
80 | | - }); |
81 | | - |
82 | | - it('check udate price method', function () { |
83 | | - var productPriceMock = { |
84 | | - find: jasmine.createSpy().and.returnValue({ |
85 | | - hide: jasmine.createSpy(), |
86 | | - priceBox: jasmine.createSpy().and.returnValue(''), |
87 | | - trigger: jasmine.createSpy(), |
88 | | - find: jasmine.createSpy().and.returnValue({ |
89 | | - toggleClass: jasmine.createSpy() |
90 | | - }) |
91 | | - }) |
92 | | - }; |
93 | | - |
94 | | - widget.element = { |
95 | | - parents: jasmine.createSpy().and.returnValue(productPriceMock) |
96 | | - }; |
97 | | - widget._getNewPrices = jasmine.createSpy().and.returnValue(undefined); |
98 | | - widget._UpdatePrice(); |
99 | | - expect(productPriceMock.find().find.calls.count()).toBe(1); |
100 | | - }); |
101 | | - |
102 | | - it('check getSelectedOptionPriceIndex', function () { |
103 | | - var optionMock = '<div class="swatch-attribute" attribute-id="2" option-selected="4"></div>', |
104 | | - element = $('<div class="' + widget.options.tooltipClass + |
105 | | - '"><div class="image"></div><div class="title"></div><div class="corner"></div>' + |
106 | | - optionMock + '</div>' |
107 | | - ), |
108 | | - optionPricesMock = { |
109 | | - optionPrices: { |
110 | | - p: { |
111 | | - finalPrice: { |
112 | | - amount: 12 |
113 | | - } |
114 | | - } |
115 | | - } |
116 | | - }; |
117 | | - |
118 | | - widget.element = element; |
119 | | - widget.options.classes.attributeClass = 'swatch-attribute'; |
120 | | - widget.options.jsonConfig = optionPricesMock; |
121 | | - widget.optionsMap = { |
122 | | - 2: { |
123 | | - 4: { |
124 | | - products: 'p' |
125 | | - }, |
126 | | - hasOwnProperty: jasmine.createSpy().and.returnValue(true) |
127 | | - }, |
128 | | - hasOwnProperty: jasmine.createSpy().and.returnValue(true) |
129 | | - }; |
130 | | - |
131 | | - expect(widget._getSelectedOptionPriceIndex()).toBe('p'); |
132 | | - }); |
133 | | - }); |
134 | | -}); |
| 1 | +/** |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | + |
| 6 | +define([ |
| 7 | + 'jquery', |
| 8 | + 'Magento_Swatches/js/swatch-renderer' |
| 9 | +], function ($, SwatchRenderer) { |
| 10 | + 'use strict'; |
| 11 | + |
| 12 | + describe('Testing "_RenderSwatchOptions" method of SwatchRenderer Widget', function () { |
| 13 | + var widget, |
| 14 | + html, |
| 15 | + optionConfig, |
| 16 | + attribute, |
| 17 | + optionId = 2, |
| 18 | + swathImageHeight = '60', |
| 19 | + swathImageWidth = '70', |
| 20 | + swathThumbImageHeight = '40', |
| 21 | + swathThumbImageWidth = '50'; |
| 22 | + |
| 23 | + beforeEach(function () { |
| 24 | + widget = new SwatchRenderer(); |
| 25 | + attribute = { |
| 26 | + id: 1, |
| 27 | + options: [{ |
| 28 | + id: optionId |
| 29 | + }] |
| 30 | + }; |
| 31 | + |
| 32 | + widget.options = { |
| 33 | + classes: { |
| 34 | + optionClass: 'swatch-option' |
| 35 | + }, |
| 36 | + jsonSwatchConfig: { |
| 37 | + 1: { |
| 38 | + 2: { |
| 39 | + type: 2 |
| 40 | + } |
| 41 | + } |
| 42 | + }, |
| 43 | + jsonSwatchImageSizeConfig: { |
| 44 | + swatchImage: { |
| 45 | + width: swathImageWidth, |
| 46 | + height: swathImageHeight |
| 47 | + }, |
| 48 | + swatchThumb: { |
| 49 | + width: swathThumbImageWidth, |
| 50 | + height: swathThumbImageHeight |
| 51 | + } |
| 52 | + } |
| 53 | + }; |
| 54 | + |
| 55 | + optionConfig = widget.options.jsonSwatchConfig[attribute.id]; |
| 56 | + html = $(widget._RenderSwatchOptions(attribute, 'option-label-control-id-1'))[0]; |
| 57 | + }); |
| 58 | + |
| 59 | + it('check if swatch config has attribute id', function () { |
| 60 | + expect(widget.options.jsonSwatchConfig.hasOwnProperty(attribute.id)).toEqual(true); |
| 61 | + }); |
| 62 | + |
| 63 | + it('check if option config has option id', function () { |
| 64 | + expect(optionConfig.hasOwnProperty(optionId)).toEqual(true); |
| 65 | + }); |
| 66 | + |
| 67 | + it('check swatch thumbnail image height attribute', function () { |
| 68 | + expect(html.hasAttribute('data-thumb-height')).toBe(true); |
| 69 | + expect(html.getAttribute('data-thumb-height')).toEqual(swathThumbImageHeight); |
| 70 | + }); |
| 71 | + |
| 72 | + it('check swatch thumbnail image width attribute', function () { |
| 73 | + expect(html.hasAttribute('data-thumb-width')).toBe(true); |
| 74 | + expect(html.getAttribute('data-thumb-width')).toEqual(swathThumbImageWidth); |
| 75 | + }); |
| 76 | + |
| 77 | + it('check swatch image styles', function () { |
| 78 | + expect(html.style.height).toEqual(swathImageHeight + 'px'); |
| 79 | + expect(html.style.width).toEqual(swathImageWidth + 'px'); |
| 80 | + }); |
| 81 | + |
| 82 | + it('check udate price method', function () { |
| 83 | + var productPriceMock = { |
| 84 | + find: jasmine.createSpy().and.returnValue({ |
| 85 | + hide: jasmine.createSpy(), |
| 86 | + priceBox: jasmine.createSpy().and.returnValue(''), |
| 87 | + trigger: jasmine.createSpy(), |
| 88 | + find: jasmine.createSpy().and.returnValue({ |
| 89 | + toggleClass: jasmine.createSpy() |
| 90 | + }) |
| 91 | + }) |
| 92 | + }; |
| 93 | + |
| 94 | + widget.element = { |
| 95 | + parents: jasmine.createSpy().and.returnValue(productPriceMock) |
| 96 | + }; |
| 97 | + widget._getNewPrices = jasmine.createSpy().and.returnValue(undefined); |
| 98 | + widget._UpdatePrice(); |
| 99 | + expect(productPriceMock.find().find.calls.count()).toBe(1); |
| 100 | + }); |
| 101 | + |
| 102 | + it('check getSelectedOptionPriceIndex', function () { |
| 103 | + var optionMock = '<div class="swatch-attribute" data-attribute-id="2" data-option-selected="4"></div>', |
| 104 | + element = $('<div class="' + widget.options.tooltipClass + |
| 105 | + '"><div class="image"></div><div class="title"></div><div class="corner"></div>' + |
| 106 | + optionMock + '</div>' |
| 107 | + ), |
| 108 | + optionPricesMock = { |
| 109 | + optionPrices: { |
| 110 | + p: { |
| 111 | + finalPrice: { |
| 112 | + amount: 12 |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + }; |
| 117 | + |
| 118 | + widget.element = element; |
| 119 | + widget.options.classes.attributeClass = 'swatch-attribute'; |
| 120 | + widget.options.jsonConfig = optionPricesMock; |
| 121 | + widget.optionsMap = { |
| 122 | + 2: { |
| 123 | + 4: { |
| 124 | + products: 'p' |
| 125 | + }, |
| 126 | + hasOwnProperty: jasmine.createSpy().and.returnValue(true) |
| 127 | + }, |
| 128 | + hasOwnProperty: jasmine.createSpy().and.returnValue(true) |
| 129 | + }; |
| 130 | + |
| 131 | + expect(widget._getSelectedOptionPriceIndex()).toBe('p'); |
| 132 | + }); |
| 133 | + }); |
| 134 | +}); |
0 commit comments