From 01f1135df1bbf44217124e78850cf1e12911e01e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 27 Jun 2018 21:37:29 +0300 Subject: LoginButton refactoring and snapshots --- vnext/src/api/index.js | 16 +- vnext/src/components/LoginButton.js | 16 +- vnext/src/components/__tests__/LoginButton.test.js | 16 ++ .../__snapshots__/LoginButton.test.js.snap | 178 +++++++++++++++++++++ 4 files changed, 217 insertions(+), 9 deletions(-) create mode 100644 vnext/src/components/__tests__/LoginButton.test.js create mode 100644 vnext/src/components/__tests__/__snapshots__/LoginButton.test.js.snap diff --git a/vnext/src/api/index.js b/vnext/src/api/index.js index b190bc48..591f874a 100644 --- a/vnext/src/api/index.js +++ b/vnext/src/api/index.js @@ -1,7 +1,9 @@ import axios from 'axios'; +const apiBaseUrl = 'https://api.juick.com'; + const client = axios.create({ - baseURL: 'https://api.juick.com/' + baseURL: apiBaseUrl }); client.interceptors.request.use(config => { if (localStorage.visitor) { @@ -61,4 +63,16 @@ export function comment(mid, rid, body, attach) { form.append('body', body); form.append('attach', attach); return client.post('/comment', form) +} + +function socialLink(network) { + return `${apiBaseUrl}/_${network}login?state=${window.location.protocol}//${window.location.host}${window.location.pathname}`; +} + +export function facebookLink() { + return socialLink('fb'); +} + +export function vkLink() { + return socialLink('vk'); } \ No newline at end of file diff --git a/vnext/src/components/LoginButton.js b/vnext/src/components/LoginButton.js index e59dabdf..05f5df97 100644 --- a/vnext/src/components/LoginButton.js +++ b/vnext/src/components/LoginButton.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import Icon from './Icon'; import Modal from './Modal'; -import { me } from '../api'; +import { me, facebookLink, vkLink } from '../api'; export default class LoginButton extends React.Component { constructor(props) { @@ -51,13 +51,13 @@ export default class LoginButton extends React.Component {

Please, introduce yourself:

- - Log in - - - - Log in - + + Log in + + + + Log in +

Already registered?

diff --git a/vnext/src/components/__tests__/LoginButton.test.js b/vnext/src/components/__tests__/LoginButton.test.js new file mode 100644 index 00000000..0b672365 --- /dev/null +++ b/vnext/src/components/__tests__/LoginButton.test.js @@ -0,0 +1,16 @@ +import React from 'react'; + +import LoginButton from '../LoginButton'; +import renderer from 'react-test-renderer'; + +test('Login button and form are renders correctly', () => { + const button = renderer.create( + {}} /> + ); + let link = button.toJSON(); + expect(link).toMatchSnapshot(); + + button.root.instance.toggleModal(); + let modal = button.toJSON(); + expect(modal).toMatchSnapshot(); +}); \ No newline at end of file diff --git a/vnext/src/components/__tests__/__snapshots__/LoginButton.test.js.snap b/vnext/src/components/__tests__/__snapshots__/LoginButton.test.js.snap new file mode 100644 index 00000000..cc01126f --- /dev/null +++ b/vnext/src/components/__tests__/__snapshots__/LoginButton.test.js.snap @@ -0,0 +1,178 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Login button and form are renders correctly 1`] = ` + +
+ ", + } + } + /> +
+ Log in +
+`; + +exports[`Login button and form are renders correctly 2`] = ` +Array [ + +
+ ", + } + } + /> +
+ Log in +
, +
+
+
+
+
+ ", + } + } + /> +
+
+
+
+

+ Please, introduce yourself: +

+ +

+ Already registered? +

+ + +
+ +
+ + +
+
+
, +] +`; -- cgit v1.2.3