Skip to content

Instantly share code, notes, and snippets.

@rcdexta
rcdexta / TodoListItem.test.js
Last active October 9, 2018 00:34
TodoListItem.test
import React from 'react'
import {render, fireEvent} from 'react-testing-library'
import TodoListItem from '../TodoListItem'
test('TodoListItem should render passed props as content body and respond to callback props', () => {
const markTodoDone = jest.fn()
const removeItem = jest.fn()
const item = {index: 3, value: "Fill Gas", done: false}
let itemIndex = 5
@rcdexta
rcdexta / TodoForm.js
Created October 9, 2018 02:46
TodoForm.js
class TodoForm extends React.Component {
static propTypes = {
onAddItem: PropTypes.func
}
state = {value: ''}
handleChange = (event) => {
this.setState({value: event.target.value});
@rcdexta
rcdexta / TodoForm.test.js
Created October 9, 2018 02:47
TodoForm.test.js
test('TodoForm should add new item and call onAddItem callback prop', () => {
const addItem = jest.fn()
const {getByTestId} = render(<TodoForm onAddItem={addItem}/>)
let newItem = 'Get Milk'
fireEvent.change(getByTestId('newItemField'), {target: {value: newItem}})
getByTestId('addBtn').click()
expect(addItem).toBeCalledWith({newItemValue: newItem})
expect(addItem).toHaveBeenCalledTimes(1);
import React from "react";
import {SortableContainer, SortableElement, SortableHandle, arrayMove} from "react-sortable-hoc";
const DragHandle = SortableHandle(() => (
<span className="handle">&#x2261;</span>
));
const SortableItem = SortableElement(({ value }) => (
<li>
<DragHandle />
import React from "react";
export default class NewItem extends React.Component {
state = { value: "" };
updateValue = evt => {
this.setState({ value: evt.target.value });
};
addNewItem = () => {
@rcdexta
rcdexta / App.jsx
Last active November 26, 2018 08:43
import React from 'react'
class App extends React.Component {
state = {
items: ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"]
};
addItem = newItem => {
this.setState({ items: [...this.state.items, newItem] });
};
class ItemList extends React.Component {
state = {
items: this.props.items
};
onSortEnd = ({ oldIndex, newIndex }) => {
this.setState({
items: arrayMove(this.state.items, oldIndex, newIndex)
});
};
const { Client } = require('pg')
const pg = {
init: async function() {
const client = new Client({
user: process.env['DB_USER'] || 'postgres',
host: process.env['DB_HOST'] || 'localhost',
database: process.env['DB_NAME'] || 'customers',
password: process.env['DB_PASSWORD'] || '',
port: 5432
{
"name": "Customers",
"description": "All customer related details sync",
"spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1d4QXXx8qFRhcajpVcEbwVM8TlEXAvrclWpLGmqvw-Pc/edit#gid=0",
"spreadsheetId": "1d4QXXx8qFRhcajpVcEbwVM8TlEXAvrclWpLGmqvw-Pc",
"tables": [
{
"tableName": "customer_details",
"sheetName": "Sheet1"
}
functions:
lambda_sheets:
handler: handler.runs
description: Lambda function to pull data from Postgres and dump to Google Spreadsheet
timeout: 900
events:
- schedule:
rate: rate(1 hour)
enabled: true