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

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Used immutable instead of plain js where needed.
Commented out console.error stubs (temporarily).
  • Loading branch information
voidxnull committed Oct 30, 2016
1 parent d840f5f commit 5175c2b
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 131 deletions.
12 changes: 6 additions & 6 deletions test/integration/anonym-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ let bookshelf = initBookshelf($dbConfig);
let User = bookshelf.model('User');

describe('pages that are available for anonym', function () {
before(() => {
sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
});
// before(() => {
// sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
// });

after(() => {
console.error.restore();
});
// after(() => {
// console.error.restore();
// });


describe('when user is not logged in', function () {
Expand Down
12 changes: 6 additions & 6 deletions test/integration/pages/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ let Post = bookshelf.model('Post');
let User = bookshelf.model('User');

describe('ListPage', () => {
before(() => {
sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
});
// before(() => {
// sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
// });

after(() => {
console.error.restore();
});
// after(() => {
// console.error.restore();
// });

it('anonymous can not open /', async () => {
await expect('/', 'to redirect');
Expand Down
4 changes: 2 additions & 2 deletions test/integration/pages/new-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ describe('NewPassword page', () => {
let user;

before(async () => {
sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
// sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
await bookshelf.knex('users').del();
user = await User.create('test', 'test', 'test@example.com');
await user.save({email_check_hash: '', reset_password_hash: 'foo'},{require:true});
});

after(async () => {
await user.destroy();
console.error.restore();
// console.error.restore();
});

it('user can open new password page and see form', async () => {
Expand Down
12 changes: 6 additions & 6 deletions test/integration/pages/school.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const User = bookshelf.model('User');
const School = bookshelf.model('School');

describe('School page', () => {
before(() => {
sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
});
// before(() => {
// sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
// });

after(() => {
console.error.restore();
});
// after(() => {
// console.error.restore();
// });


describe('when user is logged in', () => {
Expand Down
13 changes: 7 additions & 6 deletions test/unit/components/follow-button.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*eslint-env node, mocha */
import { shallow } from 'enzyme';
import { v4 as uuid4 } from 'uuid';
import i from 'immutable';

import { expect, React } from '../../../test-helpers/expect-unit';
import FollowButton from '../../../src/components/follow-button';
Expand Down Expand Up @@ -35,9 +36,9 @@ describe('Follow button Test', function () {

it('should render "Follow" for unfollowed users', () => {
const props = {
active_user: currentUser,
following: [uuid4(), uuid4()],
user: userFactory.build()
active_user: i.fromJS(currentUser),
following: i.fromJS([uuid4(), uuid4()]),
user: i.fromJS(userFactory.build())
};
const wrapper = shallow(<FollowButton {...props} />);
return expect(wrapper.text(), 'to be', 'Follow');
Expand All @@ -47,9 +48,9 @@ describe('Follow button Test', function () {
const user = userFactory.build();

const props = {
active_user: currentUser,
following: [uuid4(), uuid4(), user.id],
user
active_user: i.fromJS(currentUser),
following: i.fromJS([uuid4(), uuid4(), user.id]),
user: i.fromJS(user)
};
const wrapper = shallow(<FollowButton {...props} />);
return expect(wrapper.text(), 'to be', 'Following');
Expand Down
25 changes: 13 additions & 12 deletions test/unit/components/tag-edit-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@
import { mount } from 'enzyme';
import { v4 as uuid4 } from 'uuid';
import sinon from 'sinon';
import i from 'immutable';

import { expect, React } from '../../../test-helpers/expect-unit';
import { TAG_LOCATION, TAG_HASHTAG } from '../../../src/consts/tags';

import TagEditForm from '../../../src/components/tag-edit-form/tag-edit-form';

describe('TagEditForm', () => {
before(() => {
sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
});
// before(() => {
// sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
// });

after(() => {
console.error.restore();
});
// after(() => {
// console.error.restore();
// });

const date = new Date().toString();
const uuid = uuid4();
Expand All @@ -41,19 +42,19 @@ describe('TagEditForm', () => {
describe('GeotagEditForm', () => {
it('MUST render description field with correct initial data', () => {
const description = 'Geotag test description';
const geotag = {
const geotag = i.fromJS({
created_at: date,
id: uuid,
more: { description },
name: 'test',
updated_at: date,
url_name: 'test',
post_count: 0
};
});

const wrapper = mount(
<TagEditForm
messages={[]}
messages={i.List()}
processing={false}
saveHandler={saveHandler}
tag={geotag}
Expand All @@ -72,18 +73,18 @@ describe('TagEditForm', () => {
describe('HashtagEditForm', () => {
it('MUST render description field with correct initial data', () => {
const description = 'Hashtag test description';
const hashtag = {
const hashtag = i.fromJS({
created_at: date,
id: uuid,
more: { description },
name: 'test',
updated_at: date,
post_count: 0
};
});

const wrapper = mount(
<TagEditForm
messages={[]}
messages={i.List()}
processing={false}
saveHandler={saveHandler}
tag={hashtag}
Expand Down
8 changes: 5 additions & 3 deletions test/unit/pages/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
*/
/*eslint-env node, mocha */
import ga from 'react-google-analytics';
import { TestUtils, unexpected, expect, React } from '../../../test-helpers/expect-unit';
import i from 'immutable';

import { TestUtils, unexpected, expect, React } from '../../../test-helpers/expect-unit';
import { App } from '../../../src/pages/app';


const props = {
ui: {
ui: i.fromJS({
sidebarIsVisible: false
}
})
}

const GAInitializer = ga.Initializer;
Expand Down
22 changes: 11 additions & 11 deletions test/unit/pages/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import { TestUtils, expect, React } from '../../../test-helpers/expect-unit';
import Helmet from 'react-helmet';
import sinon from 'sinon';
import i from 'immutable';

import { Auth } from '../../../src/pages/auth';
import Messages from '../../../src/components/messages';
Expand All @@ -30,18 +31,18 @@ import Register from '../../../src/components/register';


describe('Auth page with redux', function() {
before(() => {
sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
});
// before(() => {
// sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
// });

after(() => {
console.error.restore();
});
// after(() => {
// console.error.restore();
// });


it('MUST render important components', () => {
const renderer = TestUtils.createRenderer();
renderer.render(<Auth is_logged_in messages={[]} ui={{}} />);
renderer.render(<Auth is_logged_in messages={i.List()} ui={i.Map()} />);

return expect(
renderer,
Expand All @@ -53,20 +54,20 @@ describe('Auth page with redux', function() {

it('MUST render passed messages', () => {
const renderer = TestUtils.createRenderer();
renderer.render(<Auth is_logged_in messages={[{ message: 'Im foo message' }]} ui={{}} />);
renderer.render(<Auth is_logged_in messages={i.fromJS([{ message: 'Im foo message' }])} ui={i.Map()} />);

return expect(
renderer,
'to contain',
<div>
<Messages messages={[{message: 'Im foo message'}]} />
<Messages messages={i.fromJS([{ message: 'Im foo message' }])} />
</div>
);
});

it('MUST pass ui.registrationSuccess to Register component', () => {
const renderer = TestUtils.createRenderer();
renderer.render(<Auth is_logged_in messages={[]} ui={{ registrationSuccess: false }} />);
renderer.render(<Auth is_logged_in messages={i.List()} ui={i.fromJS({ registrationSuccess: false })} />);

return expect(
renderer,
Expand All @@ -76,5 +77,4 @@ describe('Auth page with redux', function() {
</div>
);
});

});
26 changes: 13 additions & 13 deletions test/unit/pages/geotag.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@
import { shallow } from 'enzyme';
import { TestUtils, expect, React } from '../../../test-helpers/expect-unit';
import sinon from 'sinon';
import i from 'immutable';

import { GeotagPage } from '../../../src/pages/geotag';
import NotFound from '../../../src/pages/not-found';

describe('GeotagPage', () => {
before(() => {
sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
});
// before(() => {
// sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
// });

after(() => {
console.error.restore();
});
// after(() => {
// console.error.restore();
// });

it('MUST render nothing when geotag is not yet loaded', () => {
const wrapper = shallow(
<GeotagPage
comments={{}}
geotag_posts={{}}
geotags={{}}
comments={i.Map()}
geotag_posts={i.Map()}
geotags={i.Map()}
is_logged_in={false}
params={{ url_name: 'test' }}
posts={{}}
schools={{}}
users={{}}
posts={i.Map()}
schools={i.Map()}
users={i.Map()}
/>
);

return expect(wrapper.equals(null), 'to be true');
});

});
32 changes: 17 additions & 15 deletions test/unit/pages/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { TestUtils, expect, React } from '../../../test-helpers/expect-unit';
import Helmet from 'react-helmet';
import uuid from 'uuid';
import sinon from 'sinon';
import i from 'immutable';

import { List } from '../../../src/pages/list';
import Header from '../../../src/components/header';
Expand All @@ -34,21 +35,21 @@ import SideSuggestedUsers from '../../../src/components/side-suggested-users';
import CreatePost from '../../../src/components/create-post';

describe('List page with redux', () => {
before(() => {
sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
});
// before(() => {
// sinon.stub(console, 'error', (warning) => { throw new Error(warning); });
// });

after(() => {
console.error.restore();
});
// after(() => {
// console.error.restore();
// });

it('MUST render important components', () => {
const renderer = TestUtils.createRenderer();
renderer.render(
<List
comments={{}}
create_post_form={{ text: 'foo' }}
current_user={{
comments={i.Map()}
create_post_form={i.fromJS({ text: 'foo' })}
current_user={i.fromJS({
id: uuid.v4(),
favourites: [],
followed_geotags: [],
Expand Down Expand Up @@ -76,13 +77,14 @@ describe('List page with redux', () => {
updated_at: '',
username: 'test'
}
}}
})}
following={i.Map()}
is_logged_in
users={[]}
posts={{}}
river={[]}
schools={{}}
ui={{ progress: {} }}
posts={i.Map()}
river={i.List()}
schools={i.Map()}
ui={i.fromJS({ progress: {} })}
users={i.Map()}
/>
);

Expand Down

0 comments on commit 5175c2b

Please sign in to comment.