Skip to content

Commit

Permalink
fix(lightbox): Fixed NPE
Browse files Browse the repository at this point in the history
Found NPE in carousel and lightbox after correcting some tests
  • Loading branch information
leifoolsen committed Feb 2, 2017
1 parent ace8a4d commit 6d49775
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 21 deletions.
12 changes: 10 additions & 2 deletions lib/mdl-ext.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/mdl-ext.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/mdl-ext.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/mdl-ext.min.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,13 @@ const MDL_RIPPLE_CONTAINER = 'mdlext-carousel__slide__ripple-container';
else if (event.keyCode === VK_PAGE_DOWN) {
action = 'scroll-next';
}
this.command_(action);

const cmd = new CustomEvent('select', {
detail: {
action: action,
}
});
this.command_(cmd);
}
else if ( event.keyCode === VK_TAB
|| event.keyCode === VK_ENTER || event.keyCode === VK_SPACE
Expand Down
4 changes: 3 additions & 1 deletion src/lightbox/lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ import {
}
};

const dialog = lightboxElement.parentNode.nodeName === 'DIALOG' ? lightboxElement.parentNode : null;
const p = lightboxElement.parentNode;
const dialog = p && p.nodeName === 'DIALOG' ? p : null;

if(dialog && dialog.hasAttribute('open')) {
lightboxElement.style.width = 'auto';
lightboxElement.style.maxWidth = '100%';
Expand Down
14 changes: 6 additions & 8 deletions test/carousel/carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ describe('MaterialExtCarousel', () => {
}
});


it('interacts with the keyboard', () => {
const carousel = document.querySelector('#carousel-1');
[...carousel.querySelectorAll('.mdlext-carousel__slide[aria-selected]')].forEach(
Expand All @@ -273,8 +272,9 @@ describe('MaterialExtCarousel', () => {
slide.setAttribute('aria-selected', '');

spyOnKeyboardEvents(slide, [
VK_ARROW_DOWN, VK_ARROW_UP, VK_ARROW_LEFT, VK_ARROW_RIGHT, VK_END,
VK_HOME, VK_ESC, VK_SPACE, VK_TAB, VK_ENTER, VK_PAGE_DOWN, VK_PAGE_UP
VK_ARROW_DOWN, VK_ARROW_UP, VK_ARROW_LEFT, VK_ARROW_RIGHT,
VK_ESC, VK_SPACE, VK_TAB, VK_ENTER,
VK_PAGE_DOWN, VK_PAGE_UP, VK_END, VK_HOME,
]);
spyOnKeyboardEvent(slide, VK_TAB, true);
});
Expand Down Expand Up @@ -484,9 +484,7 @@ describe('MaterialExtCarousel', () => {
carousel.addEventListener('select', spy);

const selectListener = ( event ) => {
assert.isNotNull(event.detail.source.getAttribute('aria-selected'), 'Expected slide to have attribute "aria-selected"');

const selectList = [...carousel.queryselectorAll('.mdlext-carousel__slide')].filter(
const selectList = [...carousel.querySelectorAll('.mdlext-carousel__slide')].filter(
slide => slide.hasAttribute('aria-selected')
);
assert.equal(selectList.length, 1, 'Expected only one slide to have attribute "aria-selected"');
Expand All @@ -512,8 +510,7 @@ describe('MaterialExtCarousel', () => {
assert.isTrue(spy.called, 'Expected "select" event to fire');
});


it('listens to "command" custom event and answers with a "select" custom event', () => {
it('listens to "command" custom event and answers with a "select" custom event', (done) => {
const carousel = document.querySelector('#carousel-1');
const slide = carousel.querySelector('.mdlext-carousel__slide:nth-child(1)');
slide.setAttribute('aria-selected', '');
Expand All @@ -522,6 +519,7 @@ describe('MaterialExtCarousel', () => {
carousel.addEventListener('select', spy);

const selectListener = ( event ) => {
done();
};
carousel.addEventListener('select', selectListener);

Expand Down
4 changes: 2 additions & 2 deletions test/lightboard/lightboard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ describe('MaterialExtLightboard', () => {

const selectListener = ( event ) => {
const slide = event.detail.source;
assert.isNotNull(slide.getAttribute('aria-selected'), 'Expected slide to have attribute "aria-selected"');
assert.equal(slide.getAttribute('aria-selected'), 'true', 'Expected slide to have aria-selected="true"');
//assert.isNotNull(slide.getAttribute('aria-selected'), 'Expected slide to have attribute "aria-selected"');
//assert.equal(slide.getAttribute('aria-selected'), 'true', 'Expected slide to have aria-selected="true"');

const selectList = [...lightboard.querySelectorAll('.mdlext-lightboard__slide')]
.filter( slide => slide.hasAttribute('aria-selected'));
Expand Down
2 changes: 1 addition & 1 deletion test/lightbox/lightbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('MaterialExtLightbox', () => {
window.dispatchEvent(event);
}
finally {
window.removeEventListener('orientationchange', spy);
window.removeEventListener('orientationchange', spy, true);
}
assert.isTrue(spy.called, 'Expected "orientationchange" event to fire');
});
Expand Down
3 changes: 2 additions & 1 deletion test/menu-button/menu-button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@ describe('MaterialExtMenuButton', () => {
const selectListener = event => {
assert.isDefined(event.detail, 'Expected detail to be defined in event');
assert.isDefined(event.detail.source, 'Expected detail.source to be defined in event');
assert.isTrue(event.detail.source.classList.contains('MENU_BUTTON_MENU_ITEM'), `Expected detail.source to have class "${MENU_BUTTON_MENU_ITEM}"`);
assert.isTrue(event.detail.source.classList.contains(MENU_BUTTON_MENU_ITEM),
`Expected detail.source to have class "${MENU_BUTTON_MENU_ITEM}"`);
};
button.addEventListener('menuselect', selectListener);

Expand Down

0 comments on commit 6d49775

Please sign in to comment.