2017-08-23 00:27:35 +05:30
|
|
|
import React from 'react';
|
2020-05-21 23:38:47 +05:30
|
|
|
import uxpect from 'app/test/unexpected';
|
|
|
|
import { render, fireEvent, screen } from '@testing-library/react';
|
2016-12-10 21:28:47 +05:30
|
|
|
import sinon from 'sinon';
|
2020-05-21 23:38:47 +05:30
|
|
|
import { TestContextProvider } from 'app/shell';
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2020-05-21 23:38:47 +05:30
|
|
|
import ChangePassword from './ChangePassword';
|
2016-05-01 23:20:55 +05:30
|
|
|
|
|
|
|
describe('<ChangePassword />', () => {
|
2019-11-27 14:33:32 +05:30
|
|
|
it('renders two <Input /> components', () => {
|
2020-05-21 23:38:47 +05:30
|
|
|
render(
|
|
|
|
<TestContextProvider>
|
|
|
|
<ChangePassword onSubmit={async () => {}} />
|
|
|
|
</TestContextProvider>,
|
|
|
|
);
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2020-05-21 23:38:47 +05:30
|
|
|
expect(
|
|
|
|
screen.getByLabelText('New password', { exact: false }),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
|
|
|
screen.getByLabelText('Repeat the password', { exact: false }),
|
|
|
|
).toBeInTheDocument();
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2020-05-21 23:38:47 +05:30
|
|
|
it('should call onSubmit if passwords entered', async () => {
|
|
|
|
const onSubmit = sinon.spy(() => Promise.resolve()).named('onSubmit');
|
|
|
|
|
|
|
|
render(
|
|
|
|
<TestContextProvider>
|
|
|
|
<ChangePassword onSubmit={onSubmit} />
|
|
|
|
</TestContextProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
fireEvent.change(screen.getByLabelText('New password', { exact: false }), {
|
|
|
|
target: {
|
|
|
|
value: '123',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
fireEvent.change(
|
|
|
|
screen.getByLabelText('Repeat the password', { exact: false }),
|
|
|
|
{
|
|
|
|
target: {
|
|
|
|
value: '123',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2020-05-21 23:38:47 +05:30
|
|
|
fireEvent.click(
|
|
|
|
screen
|
|
|
|
.getByRole('button', { name: 'Change password' })
|
|
|
|
.closest('button') as HTMLButtonElement,
|
|
|
|
);
|
2016-05-01 23:20:55 +05:30
|
|
|
|
2020-05-21 23:38:47 +05:30
|
|
|
uxpect(onSubmit, 'was called');
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-05-01 23:20:55 +05:30
|
|
|
});
|