Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
test Auth page login component
Browse files Browse the repository at this point in the history
  • Loading branch information
RusAlex committed Jul 15, 2016
1 parent 6616765 commit fc52cd4
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/integration/pages/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
This file is a part of libertysoil.org website
Copyright (C) 2016 Loki Education (Social Enterprise)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* eslint-env node, mocha */
/* global $dbConfig,setTimeout */
import React from 'react';
import { mount } from 'enzyme';
import { Provider } from 'react-redux';

import { API_HOST } from '../../../src/config';
import ApiClient from '../../../src/api/client';
import { ActionsTrigger } from '../../../src/triggers';
import Login from '../../../src/components/login';
import initBookshelf from '../../../src/api/db';
import { initState } from '../../../src/store';
import expect from '../../../test-helpers/expect';
import UserFactory from '../../../test-helpers/factories/user';


const bookshelf = initBookshelf($dbConfig);
const User = bookshelf.model('User');

describe('Auth page', () => {
let user, store, client, triggers, userAttrs;

before(async () => {
userAttrs = UserFactory.build();
user = await User.create(userAttrs.username, userAttrs.password, userAttrs.email);

user.set('email_check_hash', null);
await user.save(null, { method: 'update' });
store = initState();
client = new ApiClient(API_HOST);
triggers = new ActionsTrigger(client, store.dispatch);
});

it('Login component should work', async (done) => {
const testComponent = <Login onLoginUser={triggers.login} />;
const wrapper = mount(testComponent);
wrapper.find('#loginUsername').node.value = userAttrs.username;
wrapper.find('#loginPassword').node.value = userAttrs.password;
wrapper.find('form').simulate('submit');

setTimeout(() => {
expect(user.get('id'), 'to equal', store.getState().getIn(['current_user', 'id']));
done();
}, 1000);
});
});

0 comments on commit fc52cd4

Please sign in to comment.