This repository has been archived by the owner on Apr 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also add self compiled babel 7.0.0 beta.
- Loading branch information
Showing
9 changed files
with
251 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
# production | ||
/build | ||
/packages | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {mockAxiosAction} from 'axios'; | ||
import React from 'react'; | ||
import {shallow} from 'enzyme'; | ||
import Settings from './Settings'; | ||
|
||
jest.mock('react-dom'); | ||
|
||
|
||
/** | ||
* Test Settings Container. | ||
*/ | ||
describe('Settings Page', function testSettings() { | ||
|
||
/** | ||
* Test change language. | ||
*/ | ||
it('Change language', function () { | ||
let bound = null; | ||
const promise = { | ||
then: function onThen(callback) { | ||
bound = callback; | ||
return promise; | ||
}, | ||
catch: function onCatch() { | ||
return promise; | ||
} | ||
}; | ||
|
||
let templateLoaded = false; | ||
|
||
mockAxiosAction( | ||
'get', | ||
function onRequest(url) { | ||
expect(url).toBe('/Template/Settings.html.tpl'); | ||
templateLoaded = true; | ||
|
||
return promise; | ||
} | ||
); | ||
|
||
const wrapper = shallow(<Settings/>); | ||
let instance = wrapper.instance(); | ||
bound({data: 'TEMPLATE'}); | ||
wrapper.setProps({}); | ||
|
||
instance.onSelectionChange( | ||
{ | ||
name: 'language', | ||
selectedOptions: ['german'], | ||
selectedIndex: 1, | ||
value: 'german' | ||
} | ||
); | ||
|
||
wrapper.unmount(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import PropTypes from 'prop-types'; | ||
import {MDCSelect} from '@material/select'; | ||
|
||
/** | ||
* MDC Select implementation. | ||
*/ | ||
class Select extends React.Component { | ||
|
||
/** | ||
* Supported property types. | ||
*/ | ||
static get propTypes() { | ||
return { | ||
onChange: PropTypes.func.isRequired, | ||
name: PropTypes.string.isRequired | ||
}; | ||
} | ||
|
||
/** | ||
* Apply change information. | ||
*/ | ||
onChange() { | ||
let selectedOptions = [], index; | ||
|
||
// Convert options to array | ||
const options = this.select.selectedOptions; | ||
for (index = 0; index < options.length; index++) { | ||
selectedOptions[index] = options[index].id; | ||
} | ||
|
||
const event = { | ||
name: this.props.name, | ||
selectedOptions: selectedOptions, | ||
selectedIndex: this.select.selectedIndex, | ||
value: this.select.value | ||
}; | ||
this.props.onChange(event); | ||
} | ||
|
||
/** | ||
* Connect MDC after mount. | ||
*/ | ||
componentDidMount() { | ||
this.domNode = ReactDOM.findDOMNode(this); | ||
this.boundChnage = this.onChange.bind(this); | ||
this.select = new MDCSelect(this.domNode); | ||
this.select.listen('MDCSelect:change', this.boundChnage); | ||
} | ||
|
||
/** | ||
* Disconnect from MDC. | ||
*/ | ||
componentWillUnmount() { | ||
this.select.unlisten('MDCSelect:change', this.boundChnage); | ||
this.select.destroy(); | ||
this.select = undefined; | ||
} | ||
|
||
/** | ||
* Generate the output. | ||
*/ | ||
render() { | ||
// No special adding into dom tree, passing children as own level. | ||
return this.props.children; | ||
} | ||
} | ||
|
||
export default Select; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react'; | ||
import {shallow} from 'enzyme'; | ||
import Select from './Select'; | ||
import ReactDOM from 'react-dom'; | ||
import * as MDC from '@material/select'; | ||
|
||
|
||
jest.mock('@material/select', () => { | ||
const mockInstance = { | ||
destroy: jest.fn(), | ||
listen: jest.fn(), | ||
unlisten: jest.fn(), | ||
selectedOptions: ["option1"], | ||
selectedIndex: 1, | ||
value: "option" | ||
}; | ||
const mock = jest.fn().mockImplementation( | ||
function onCreate() { | ||
return mockInstance; | ||
} | ||
); | ||
return { | ||
mock: mockInstance, | ||
MDCSelect: mock, | ||
}; | ||
}); | ||
|
||
jest.mock('react-dom', () => { | ||
const mock = { | ||
findDOMNode: jest.fn() | ||
}; | ||
return { | ||
findDOMNode: mock.findDOMNode, | ||
getMock: function () { | ||
return mock; | ||
} | ||
}; | ||
}); | ||
|
||
|
||
/** | ||
* Test select interaction. | ||
*/ | ||
describe('MDC: Select', function testMDCDrawer() { | ||
it("Emit event on change", function() { | ||
let wasChanged = false; | ||
|
||
const domNode = { | ||
addEventListener: jest.fn() | ||
}; | ||
|
||
const domMock = ReactDOM.getMock().findDOMNode; | ||
domMock.mockClear(); | ||
domMock.mockReturnValue(domNode); | ||
|
||
MDC.mock.destroy.mockClear(); | ||
|
||
/** | ||
* Callback helper. | ||
* @param {Object} event | ||
*/ | ||
function checkEvent(event) | ||
{ | ||
wasChanged = true; | ||
} | ||
|
||
let wrapper = shallow( | ||
<Select name="selectMenu" onChange={checkEvent}/> | ||
); | ||
expect(MDC.mock.listen).toHaveBeenCalled(); | ||
MDC.mock.listen.mock.calls[0][1](); // emulate emit | ||
|
||
|
||
wrapper.unmount(); | ||
expect(MDC.mock.destroy).toHaveBeenCalled(); | ||
expect(MDC.mock.unlisten).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import Drawer from './Drawer'; | ||
import Select from './Select'; | ||
|
||
export default { | ||
Drawer: Drawer | ||
Drawer: Drawer, | ||
Select: Select | ||
}; |