Skip to content

Commit

Permalink
#9 added first real test spec!
Browse files Browse the repository at this point in the history
  • Loading branch information
abbr committed Oct 9, 2017
1 parent d8a2e4c commit c0c2336
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
4 changes: 2 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(config) {
config.set({
basePath: '',
browsers: ['ChromeHeadless'],
files: ['test/loadtests.js'],
files: ['test/loadTests.js'],
port: 8080,
captureTimeout: 60000,
frameworks: ['mocha', 'chai'],
Expand All @@ -31,7 +31,7 @@ module.exports = function(config) {
logLevel: config.LOG_INFO,
reporters: reporters,
preprocessors: {
'test/loadtests.js': ['webpack', 'sourcemap']
'test/loadTests.js': ['webpack', 'sourcemap']
},
webpack: webpackCfg,
coverageReporter: {
Expand Down
32 changes: 13 additions & 19 deletions test/components/AppTest.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
/*eslint-env node, mocha */
/*global expect */
/*eslint no-console: 0*/
'use strict'

// Uncomment the following lines to use the react test utilities
// import React from 'react/addons';
// const TestUtils = React.addons.TestUtils;
import createComponent from 'helpers/shallowRenderHelper'
import { shallow, mount } from 'enzyme'
// import createComponent from 'helpers/shallowRenderHelper'
import { mount } from 'enzyme'
import Main from 'components/app'
import React from 'react'

describe('MainComponent', () => {
let MainComponent
// describe('MainComponent', () => {
// let MainComponent

beforeEach(() => {
MainComponent = createComponent(Main)
})
// beforeEach(() => {
// MainComponent = createComponent(Main)
// })

it('should have its component name as default className', () => {
debugger
expect(MainComponent.props.className).to.equal('sp-main-container')
})
})
// it('should have its component name as default className', () => {
// expect(MainComponent.props.className).to.equal('sp-main-container')
// })
// })

describe('<Main />', () => {
it.only('should have its component name as default className', () => {
debugger
let app = document.createElement('div')
app.setAttribute('id', 'app')
document.body.appendChild(app)
describe('App', () => {
it('should have its component className as sp-main-container', () => {
const wrapper = mount(<Main />, { attachTo: app })
expect(wrapper.children().is('.sp-main-container')).to.equal(true)
})
Expand Down
17 changes: 17 additions & 0 deletions test/components/header/indexTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { mount } from 'enzyme'
import Main from 'components/app'
import React from 'react'

describe('Header', () => {
it('should add a text widget when clicking insert object button', () => {
const wrapper = mount(<Main />, { attachTo: app })
expect(wrapper.state().deck.getActiveSlide().components.length).to.equal(1)
wrapper
.find(
'.sp-main-container .navbar .container-fluid #sp-navbar-collapse-1 .navbar-left button'
)
.first()
.simulate('click')
expect(wrapper.state().deck.getActiveSlide().components.length).to.equal(2)
})
})
12 changes: 11 additions & 1 deletion test/loadtests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
configure({ adapter: new Adapter() })

beforeEach(() => {
while (localStorage.length > 0) {
localStorage.removeItem(localStorage.key(0))
}
})

let app = document.createElement('div')
app.setAttribute('id', 'app')
document.body.appendChild(app)

// Add support for all files in the test directory
const testsContext = require.context('.', true, /(Test\.js$)|(Helper\.js$)/)
const testsContext = require.context('.', true, /(test|helper)\.jsx?$/i)
testsContext.keys().forEach(testsContext)

0 comments on commit c0c2336

Please sign in to comment.