{"size": 1455, "ext": "js", "max_stars_repo_path": "templates/content-site/template/cms/client/__tests__/unit/components/routes/settings/form/password.js", "max_stars_repo_name": "sham-ui/shamui-cli", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "templates/content-site/template/cms/client/__tests__/unit/components/routes/settings/form/password.js", "max_issues_repo_name": "sham-ui/shamui-cli", "max_issues_repo_issues_event_min_datetime": "2018-04-07T06:11:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-01T05:23:00.000Z", "max_forks_repo_path": "templates/admin-panel/template/client/__tests__/unit/components/routes/settings/form/password.js", "max_forks_repo_name": "sham-ui/sham-ui-cli", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 90, "max_forks_count": null, "avg_line_length": 32.3333333333, "max_line_length": 109, "alphanum_fraction": 0.6378006873}
import * as directives from 'sham-ui-directives';
// eslint-disable-next-line max-len
import RoutesSettingsFormPassword  from '../../../../../../src/components/routes/settings/form/password.sfc';
import renderer from 'sham-ui-test-helpers';
import { createDI } from 'sham-ui';

it( 'renders correctly', () => {
    const DI = createDI();
    const meta = renderer( RoutesSettingsFormPassword, {
        DI,
        directives
    } );
    expect( meta.toJSON() ).toMatchSnapshot();
} );

it( 'display errors', async() => {
    expect.assertions( 2 );

    const DI = createDI();
    const updateMock = jest.fn();
    DI.bind( 'store', {
        updateMemberPassword: updateMock.mockReturnValueOnce( Promise.reject( {} ) )
    } );

    const meta = renderer( RoutesSettingsFormPassword, {
        DI,
        directives
    } );

    const formData = {
        pass1: 'admin1@gmail.com',
        pass2: 'admin1@gmail.com'
    };
    const { component } = meta;
    component.container.querySelector( '[name="pass1"]' ).value = formData.pass1;
    component.container.querySelector( '[name="pass2"]' ).value = formData.pass2;
    component.container.querySelector( '[type="submit"]' ).click();
    component.container.querySelector( '[data-test-modal] [data-test-ok-button]' ).click();

    await new Promise( resolve => setImmediate( resolve ) );

    expect( updateMock.mock.calls ).toHaveLength( 1 );
    expect( meta.toJSON() ).toMatchSnapshot();
} );
