Skip to content

Commit 5460a5e

Browse files
author
Spencer Canner
committed
add title to component iframes
1 parent a6ca6a7 commit 5460a5e

File tree

9 files changed

+52
-0
lines changed

9 files changed

+52
-0
lines changed

src/component.js

+8
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ export default class Component {
152152
};
153153
}
154154

155+
/**
156+
* get iframe title for component.
157+
* @return {String} iframe title.
158+
*/
159+
get iframeTitle() {
160+
return this.options.text && this.options.text.iframeTitle;
161+
}
162+
155163
/**
156164
* initializes component by creating model and rendering view.
157165
* @param {Object} [data] - data to initialize model with.

src/components/cart.js

+4
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ export default class Cart extends Component {
201201
return `${this.props.client.config.storefrontAccessToken}.${this.props.client.config.domain}.checkoutId`;
202202
}
203203

204+
get iframeTitle() {
205+
return this.options.text.title;
206+
}
207+
204208
imageForLineItem(lineItem) {
205209
const imageSize = 180;
206210
const imageOptions = {

src/defaults/components.js

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const defaults = {
8484
unitPriceAccessibilitySeparator: 'per',
8585
regularPriceAccessibilityLabel: 'Regular price',
8686
salePriceAccessibilityLabel: 'Sale price',
87+
iframeTitle: 'Product buy button',
8788
},
8889
},
8990
modalProduct: {
@@ -122,6 +123,7 @@ const defaults = {
122123
buttonDestination: 'cart',
123124
text: {
124125
button: 'ADD TO CART',
126+
iframeTitle: 'Product details modal buy button',
125127
},
126128
},
127129
modal: {
@@ -147,6 +149,9 @@ const defaults = {
147149
},
148150
order: ['contents'],
149151
templates: modalTemplates,
152+
text: {
153+
iframeTitle: 'Product details modal',
154+
},
150155
},
151156
productSet: {
152157
iframe: true,
@@ -173,6 +178,7 @@ const defaults = {
173178
},
174179
text: {
175180
nextPageButton: 'Next page',
181+
iframeTitle: 'Product collection buy buttons',
176182
},
177183
},
178184
option: {
@@ -305,6 +311,7 @@ const defaults = {
305311
},
306312
text: {
307313
title: 'cart',
314+
iframeTitle: 'Cart toggle',
308315
},
309316
},
310317
window: {

src/iframe.js

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ export default class iframe {
9393
});
9494
Object.keys(iframeAttrs).forEach((key) => this.el.setAttribute(key, iframeAttrs[key]));
9595
this.el.setAttribute('name', config.name);
96+
if (config.title) {
97+
this.el.setAttribute('title', config.title);
98+
}
9699
this.styleTag = null;
97100
}
98101

src/view.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default class View {
3030
googleFonts: this.component.googleFonts,
3131
name: this.component.name,
3232
width: this.component.options.layout === 'vertical' ? this.component.options.width : null,
33+
title: this.component.iframeTitle,
3334
});
3435
this.iframe.addClass(this.className);
3536
return this.iframe.load();

test/unit/cart/cart.js

+6
Original file line numberDiff line numberDiff line change
@@ -1590,4 +1590,10 @@ describe('Cart class', () => {
15901590
viewSetFocusStub.restore();
15911591
});
15921592
});
1593+
1594+
describe('get iframeTitle', () => {
1595+
it('returns the title from the text options', () => {
1596+
assert.equal(cart.iframeTitle, cart.options.text.title);
1597+
});
1598+
});
15931599
});

test/unit/component.js

+6
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,12 @@ describe('Component class', () => {
417417
});
418418
});
419419
});
420+
421+
describe('iframeTitle', () => {
422+
it('returns the iframeTitle from the option text', () => {
423+
assert.equal(component.iframeTitle, component.options.text.iframeTitle);
424+
});
425+
});
420426
});
421427

422428
describe('"private" methods', () => {

test/unit/iframe.js

+14
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('Iframe class', () => {
6262
constructorConfig = Object.assign({}, configObject, {
6363
googleFonts: ['Arial', 'Calibri'],
6464
width: '200px',
65+
title: 'Iframe title',
6566
});
6667
createElementSpy = sinon.spy(document, 'createElement');
6768
setWidthStub = sinon.stub(Iframe.prototype, 'setWidth');
@@ -137,6 +138,19 @@ describe('Iframe class', () => {
137138
assert.equal(iframe.el.getAttribute('name'), constructorConfig.name);
138139
});
139140

141+
it('sets element title to title in config if it exists', () => {
142+
assert.equal(iframe.el.getAttribute('title'), constructorConfig.title);
143+
});
144+
145+
it('does not set element title if it does not exist in the config', () => {
146+
constructorConfig.title = null;
147+
const setAttributeStub = sinon.stub(iframe.el, 'setAttribute');
148+
iframe = new Iframe(parent, constructorConfig);
149+
assert.neverCalledWith(setAttributeStub, 'title');
150+
assert.equal(iframe.el.getAttribute('title'), null);
151+
setAttributeStub.restore();
152+
});
153+
140154
it('sets styleTag to null', () => {
141155
iframe = new Iframe(parent, constructorConfig);
142156
assert.equal(iframe.styleTag = null);

test/unit/view.js

+3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ describe('View class', () => {
6565
value: {
6666
iframe: true,
6767
manifest: ['product', 'option'],
68+
text: {
69+
iframeTitle: 'Iframe title',
70+
},
6871
},
6972
});
7073
});

0 commit comments

Comments
 (0)