Files
remark42/frontend/app/components/auth/auth.test.tsx
T
Pavel MineevandUmputun 93fd445bd4 On-demand auth
* auth block was moved to comment form
* if comments on page read only auth form shows in old place
* comment value in form will be saved between refreshes (it is side effect form saving comment value between unauth and auth states)
2020-03-12 15:44:31 -05:00

71 lines
2.1 KiB
TypeScript

/** @jsx createElement */
import { createElement } from 'preact';
import { IntlProvider } from 'react-intl';
import { Provider } from 'react-redux';
import enMessages from '@app/locales/en.json';
import { mockStore } from '@app/testUtils/mockStore';
import { StaticStore } from '@app/common/static_store';
import Auth from './auth';
import { mount } from 'enzyme';
import { Button } from '../button';
import { StoreState } from '@app/store';
const initialStore = {
provider: { name: 'google' },
theme: 'light',
comments: {
sort: '-score',
} as StoreState['comments'],
} as const;
describe('<Auth/>', () => {
const createWrapper = (store?: Partial<StoreState>) =>
mount(
<IntlProvider locale="en" messages={enMessages}>
<Provider store={mockStore(store || initialStore)}>
<Auth />
</Provider>
</IntlProvider>
);
it('should render login form with google and github provider', () => {
StaticStore.config.auth_providers = ['google', 'github'];
const element = createWrapper();
const providersButtons = element.find(Button);
expect(element.text()).toEqual(expect.stringContaining('Login:'));
expect(providersButtons.at(0).text()).toEqual('Google');
expect(providersButtons.at(1).text()).toEqual('GitHub');
});
describe('providers sorting', () => {
it('should do nothing if provider not found', () => {
StaticStore.config.auth_providers = ['google', 'github'];
const element = createWrapper({
...initialStore,
provider: { name: 'baidu' },
});
const providerLinks = element.find(Button);
expect(providerLinks.at(0).text()).toEqual('Google');
expect(providerLinks.at(1).text()).toEqual('GitHub');
});
it('should place selected provider first', () => {
StaticStore.config.auth_providers = ['google', 'github'];
const element = createWrapper({
...initialStore,
provider: { name: 'github' },
});
const providerLinks = element.find(Button);
expect(providerLinks.at(0).text()).toEqual('GitHub');
expect(providerLinks.at(1).text()).toEqual('Google');
});
});
});