Skip to content

Instantly share code, notes, and snippets.

View michelts's full-sized avatar

Michel Sabchuk michelts

View GitHub Profile
from django.views.generic.base import View, TemplateResponseMixin
from django.views.generic.edit import FormMixin, ProcessFormView
class MultipleFormsMixin(FormMixin):
"""
A mixin that provides a way to show and handle several forms in a
request.
"""
form_classes = {} # set the form classes as a mapping
@michelts
michelts / bootstrap.datepicker.js
Last active December 23, 2015 11:19 — forked from pamelafox/bootstrap.datepicker.js
jQuery/Zepto Bootstrap Datepicker now with tables and able to start with blank values.
/* ===========================================================
* bootstrap-datepicker.js v1.3.0
* http://twitter.github.com/bootstrap/javascript.html#datepicker
* ===========================================================
* Copyright 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
import React from 'react';
import { useGlobal } from 'reactn';
import Card from './Card'
const Cards = () => {
const [cards, setCards] = useGlobal('cards');
return (
<div>
{cards.map(card => (
<Card key={card} card={card} />))}
import React from 'react';
import { shallow } from 'enzyme';
import { useGlobal } from 'reactn';
import Cards from './cards';
jest.mock('reactn');
it('should render a Card component for each global state card', () => {
const cards = ['Q', 'J', 'K', 'A', '2'];
useGlobal.mockReturnValueOnce([cards]);
it('Cards component, supposing that uses redux', () => {
const props = StoreFactory({ ...customConditions });
const wrapper = shallow(<Cards {...props} />);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find(something)).toEqual(whatImExpecting);
});
exports[`should render a Card component for each global state card 1`] = `
<div>
<Card card="Q" key="Q" />
<Card card="J" key="J" />
<Card card="K" key="K" />
<Card card="A" key="A" />
<Card card="2" key="2" />
</div>
`;
import React from 'react';
import { useGlobal } from 'reactn';
import { getRandomCard } from './utils';
import Card from './card';
const Cards = () => {
const [cards, setCards] = useGlobal('cards');
return (
<div>
{cards.map(card => (
it('should ask a new Card when click the button', () => {
const cards = [];
const setCards = jest.fn();
useGlobal.mockReturnValueOnce([cards, setCards]);
const wrapper = shallow(<Cards />);
wrapper.find('button').simulate('click');
expect(getRandomCard).toHaveBeenCalledWith(cards);
expect(setCards).toHaveBeenCalledWith(getRandomCard.mock.results[0].value);
});
export const useGlobal = jest.fn();
const [global, setGlobal] = useGlobal();
useGlobal.mockReturnValueOnce([mockedGlobal, jest.fn()]);
const reducerFunc = useGlobal('someReducerFunc');
useGlobal.mockReturnValueOnce(mockedReducerFunc);