Skip to content

Commit 3898643

Browse files
committed
#9 converted impress-vendor to module in order to pass multiple tests
1 parent 477c404 commit 3898643

File tree

3 files changed

+45
-28
lines changed

3 files changed

+45
-28
lines changed

src/components/show/impress-vendor.js

+20-25
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
// You are one of those who like to know how things work inside?
2323
// Let me show you the cogs that make impress.js run...
24-
;(function(document, window) {
24+
export function Impress(document, window) {
2525
'use strict'
2626

2727
// HELPER FUNCTIONS
@@ -687,7 +687,7 @@
687687

688688
// Flag that can be used in JS to check if browser have passed the support test
689689
impress.supported = impressSupported
690-
})(document, window)
690+
}
691691

692692
// NAVIGATION EVENTS
693693

@@ -697,7 +697,7 @@
697697
//
698698
// In future I think about moving it to make them optional, move to separate files
699699
// and treat more like a 'plugins'.
700-
;(function(document, window) {
700+
export function ImpressHandleEvents() {
701701
'use strict'
702702

703703
// Throttling function calls, by Remy Sharp
@@ -768,27 +768,22 @@
768768
return
769769
}
770770

771-
if (
772-
event.keyCode === 9 ||
773-
(event.keyCode >= 32 && event.keyCode <= 34) ||
774-
(event.keyCode >= 37 && event.keyCode <= 40)
775-
) {
776-
switch (event.keyCode) {
777-
case 33: // Page up
778-
case 37: // Left
779-
case 38: // Up
780-
api.prev()
781-
break
782-
case 9: // Tab
783-
case 32: // Space
784-
case 34: // Page down
785-
case 39: // Right
786-
case 40: // Down
787-
api.next()
788-
break
789-
}
790-
791-
event.preventDefault()
771+
switch (event.key) {
772+
case 'PageUp':
773+
case 'ArrowLeft':
774+
case 'ArrowUp':
775+
api.prev()
776+
event.preventDefault()
777+
break
778+
case 'Tab':
779+
case 'Space':
780+
case 'PageDown':
781+
case 'ArrowRight':
782+
case 'ArrowDown':
783+
api.next()
784+
event.preventDefault()
785+
break
786+
default:
792787
}
793788
},
794789
false
@@ -885,7 +880,7 @@
885880
},
886881
false
887882
)
888-
})(document, window)
883+
}
889884

890885
// THAT'S ALL FOLKS!
891886
//

src/components/show/impress.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict'
22
import React from 'react'
33
import ReactDOM from 'react-dom'
4-
import './impress-vendor.js'
4+
import { Impress, ImpressHandleEvents } from './impress-vendor.js'
55
import './impress.less'
66
import DeckStore from 'stores/deck'
77
import AutoScale from 'components/mixins/autoScale'
88
import _ from 'lodash'
99
import Global from './global'
1010
var DisplayableComponent = require('components/widgets/displayableComponent')
11-
11+
ImpressHandleEvents(document, window)
1212
let Presentation = class extends AutoScale.autoScaleMixin(React.Component) {
1313
constructor(props) {
1414
super(props)
@@ -23,6 +23,7 @@ let Presentation = class extends AutoScale.autoScaleMixin(React.Component) {
2323
}
2424

2525
componentDidMount() {
26+
Impress(document, window)
2627
super.componentDidMount && super.componentDidMount()
2728
if ('ontouchstart' in document.documentElement) {
2829
document.querySelector('.hint').innerHTML =

test/components/show/impressTest.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,31 @@ describe('show > impress', () => {
44
beforeEach(() => {
55
appWrapper = getAppWrapper('Impress')
66
})
7+
afterEach(() => {
8+
$('body').removeAttr('style')
9+
$('body').removeAttr('class')
10+
})
711

812
it('should have 5 initial views', () => {
913
expect(appWrapper.find('#impress').props().children.length).to.equal(5)
1014
expect($('body').attr('class')).to.contain('impress-on-step-1')
11-
expect($('#step-1').attr('class').split(' ')).to.include('active')
15+
expect(
16+
$('#step-1')
17+
.attr('class')
18+
.split(' ')
19+
).to.include('active')
20+
})
21+
22+
it('should move to 2nd step when press right key', () => {
23+
let event = new KeyboardEvent('keyup', {
24+
key: 'ArrowRight'
25+
})
26+
document.dispatchEvent(event)
27+
expect($('body').attr('class')).to.contain('impress-on-step-2')
28+
expect(
29+
$('#step-2')
30+
.attr('class')
31+
.split(' ')
32+
).to.include('active')
1233
})
1334
})

0 commit comments

Comments
 (0)