2023-03-20 12:55:53 +01:00
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import { fireEvent, screen } from '@testing-library/react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
|
|
|
import JwtUrlForm from './jwt-url-form';
|
|
|
|
|
|
|
|
describe('JwtUrlForm', function () {
|
|
|
|
const mockStore = {
|
|
|
|
metamask: {
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2023-03-20 12:55:53 +01:00
|
|
|
type: 'test',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const store = configureMockStore()(mockStore);
|
|
|
|
|
|
|
|
const props = {
|
|
|
|
jwtList: ['jwt1'],
|
|
|
|
currentJwt: 'jwt1',
|
|
|
|
onJwtChange: sinon.spy(),
|
|
|
|
jwtInputText: 'input text',
|
|
|
|
apiUrl: 'url',
|
|
|
|
urlInputText: '',
|
|
|
|
onUrlChange: sinon.spy(),
|
|
|
|
};
|
|
|
|
|
|
|
|
it('opens JWT Url Form without input for new JWT', () => {
|
2023-06-27 15:49:15 +02:00
|
|
|
const { getByText } = renderWithProvider(<JwtUrlForm {...props} />, store);
|
2023-03-20 12:55:53 +01:00
|
|
|
|
|
|
|
expect(getByText('Add new token')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows JWT textarea with provided input text', () => {
|
2023-03-31 11:30:10 +02:00
|
|
|
const { getAllByTestId } = renderWithProvider(
|
|
|
|
<JwtUrlForm {...props} />,
|
|
|
|
store,
|
2023-03-20 12:55:53 +01:00
|
|
|
);
|
2023-03-31 11:30:10 +02:00
|
|
|
|
|
|
|
const btn = getAllByTestId('addNewToken-btn')[0];
|
2023-03-20 12:55:53 +01:00
|
|
|
fireEvent.click(btn);
|
|
|
|
expect(screen.getByText('input text')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('goes through the api url input', () => {
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
|
|
|
<JwtUrlForm {...props} />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
const apiUrlinput = queryByTestId('jwt-api-url-input');
|
|
|
|
fireEvent.change(apiUrlinput, { target: { value: 'url' } });
|
|
|
|
expect(apiUrlinput.value).toBe('url');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows JWT text area when no jwt token exists', () => {
|
|
|
|
const customProps = {
|
|
|
|
...props,
|
|
|
|
currentJwt: '',
|
|
|
|
jwtList: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<JwtUrlForm {...customProps} />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|