Skip to content

Instantly share code, notes, and snippets.

@visualskyrim
visualskyrim / ShowBox.jsx
Last active August 6, 2017 14:40
Use Enzyme to test React/Redux container - Code List 1
import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { submitValue } from '../store/modules/showBox'
export class ShowBox extends React.Component {
constructor(props) {
super(props)
this.state = {
searchString: this.props.search || ""
@visualskyrim
visualskyrim / shallowWithStore.jsx
Created May 22, 2017 05:34
Use Enzyme to test React/Redux container - Code List 2
import { shallow } from 'enzyme';
const shallowWithStore = (component, store) => {
const context = {
store,
};
return shallow(component, { context });
};
export default shallowWithStore;
@visualskyrim
visualskyrim / ShowBox.2.spec.js
Last active May 22, 2017 06:00
Use Enzyme to test React/Redux container - Code List 3 & 4
describe('ConnectedShowBox', () => {
it("should render a text box with empty string inside if string is not provided by store", () => {
const testState = {
searchBox: {}
};
const store = createMockStore(testState)
const component = shallowWithStore(<ConnectedShowBox />, store);
expect(component).to.be.a('object');
expect(component.dive().find("").prop("value")).to.equal("")
});
@visualskyrim
visualskyrim / ShowBox.jsx
Last active August 6, 2017 14:40
Use Enzyme to test React/Redux container - Code List 3
describe('ConnectedShowBox', () => {
it("should render successfully if string is not provided by store", () => {
const testState = {
showBox: {}
};
const store = createMockStore(testState)
const component = shallowWithStore(<ConnectedShowBox />, store);
expect(component).to.be.a('object');
});
});
@visualskyrim
visualskyrim / ShowBox.2.spec.js
Last active May 22, 2017 12:22
Use Enzyme to test React/Redux container - Code List 4
describe('ConnectedShowBox', () => {
it("should render a text box with empty string inside if string is not provided by store", () => {
const testState = {
searchBox: {
search: ""
}
};
const store = createMockStore(testState)
const component = shallowWithStore(<ConnectedSearchBox />, store);
@visualskyrim
visualskyrim / ShowBox.jsx
Created May 22, 2017 06:41
Use Enzyme to test React/Redux container - Code List 5
expect(component.find("").prop("value")).to.equal("")
@visualskyrim
visualskyrim / ShowBox.spec.js
Last active August 6, 2017 14:40
Use Enzyme to test React/Redux container - dispatch
it("should render a text box with no string inside if search string is not provided by store", () => {
const testState = {
showBox: {
search: ""
}
};
const store = createMockStore(testState)
const component = shallowWithStore(<ConnectedShowBox />, store);
component.dive().find("form > div > input").simulate("change", { target: { value: "Site" } });
@visualskyrim
visualskyrim / ShowBox.jsx
Created May 22, 2017 10:48
Use Enzyme to test React/Redux container - dive
describe('ConnectedShowBox', () => {
it("should render a text box with empty string inside if string is not provided by store", () => {
const testState = {
searchBox: {}
};
const store = createMockStore(testState)
const component = shallowWithStore(<ConnectedShowBox />, store);
expect(component).to.be.a('object');
expect(component.dive().find("").prop("value")).to.equal("")
});
@visualskyrim
visualskyrim / ShowBox.jsx
Last active May 22, 2017 12:34
Use Enzyme to test React/Redux container - simulate & find
it("should render a text box with no string inside if search string is not provided by store", () => {
const testState = {
showBox: {
search: ""
}
};
const store = createMockStore(testState)
const component = shallowWithStore(<ConnectedShowBox />, store);
expect(component).to.be.a('object');
@visualskyrim
visualskyrim / Producer.py
Created June 13, 2017 12:58
Simple python Kafka producer
from kafka import KafkaProducer
from kafka.errors import KafkaError
import json
import time
producer = KafkaProducer(bootstrap_servers=['localhost:9092'], value_serializer=lambda m: json.dumps(m).encode('ascii'))
# Asynchronous by default
future = producer.send('flink-test', b'raw_bytes')
# Block for 'synchronous' sends