Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/forms / build / dist / __tests__ / plugins.test.js
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("./_setup");
const React = require("react");
const ReactTestRenderer = require("react-test-renderer");
const react_testing_library_1 = require("react-testing-library");
const OneForm_1 = require("../new-forms/OneForm/OneForm");
const InputState_1 = require("../new-forms/inputs/InputState");
const ObserverInput_1 = require("../new-forms/inputs/ObserverInput");
const PluginsContext_1 = require("../new-forms/plugins/PluginsContext");
// - provide default props
//
// - change validation strategy
// - validate using multiple inputs (like credit card, or confirm password)
//
// - absorb multiple inputs, even if they are flat (optional, can just pass specific props to it)
const actualValidator = (inputState) => true;
const mockValidator = jest.fn(actualValidator);
const actualSerializer = (inputState) => {
    return {
        eh: 'canada',
    };
};
const mockSerializer = jest.fn(actualSerializer);
class TestPlugin extends React.Component {
    static isSatisfiedByProps(props) {
        return true;
    }
    render() {
        return (React.createElement(ObserverInput_1.ObserverInput, { state: this.props.state, label: "Test", "data-qa": "qa-test", required: true, minLength: 4, maxLength: 254, pattern: "(.*)", placeholder: "test...", type: "test", autoComplete: "test" }));
    }
}
TestPlugin.defaultState = {
    label: 'Default State Label',
    // test just the input state
    validator: mockValidator,
    // this is important
    //    when we are using multiple inputs
    //    and we need to combine them...
    serializer: mockSerializer,
};
describe('@skava/forms - plugins', () => {
    afterEach(react_testing_library_1.cleanup);
    // it.skip('should - provide default props using a fn', () => {
    //   // basically do the same thing it already does in the next test
    //   // but take the current value and wrap it in a function
    //   // ...
    //   // or, test the render fn by importing it direct to test that 1 thing
    // })
    it(`should
    - provide default props
    - provide the plugins
    - render the plugin
    - pick the correct plugin
    - provide custom serialization
    - call validate
  `, () => {
        const formState = new OneForm_1.OneFormState().setInputsList([
            {
                type: 'test',
            },
        ]);
        const view = (React.createElement(PluginsContext_1.PluginsContext.Provider, { value: [TestPlugin] },
            React.createElement(OneForm_1.OneObserverForm, { state: formState })));
        expect(mockValidator.mock.calls.length).toEqual(0);
        const renderer = ReactTestRenderer.create(view);
        expect(renderer.toJSON()).toMatchSnapshot();
        // or `atLeast(1)`
        expect(mockValidator.mock.calls.length).toEqual(2);
        const { getByText } = react_testing_library_1.render(view);
        react_testing_library_1.fireEvent.click(getByText(/Continue/));
        expect(mockValidator.mock.calls.length).toEqual(2);
        // does not serialize by default now...
        // @see strategies.test
        // expect(mockSerializer.mock.calls.length).toEqual(1)
    });
    it('should be able to a render a plugin directly', () => {
        const state = new InputState_1.InputState();
        const view = React.createElement(TestPlugin, { state: state });
        const renderer = ReactTestRenderer.create(view);
        expect(renderer.toJSON()).toMatchSnapshot();
    });
});
//# sourceMappingURL=plugins.test.js.map