diff options
author | George Goldberg <george@gberg.me> | 2017-03-23 18:05:36 +0000 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-03-23 14:05:36 -0400 |
commit | 7d449e05562c76bb430efc1c36bd715675a84152 (patch) | |
tree | b6d5bbd143fbd31483c9c931b5031aec280ace2d /webapp/tests/client/client_channel.test.jsx | |
parent | c6ded1dbfd69a1da69add8d2b554f4b7dd0341b3 (diff) | |
download | chat-7d449e05562c76bb430efc1c36bd715675a84152.tar.gz chat-7d449e05562c76bb430efc1c36bd715675a84152.tar.bz2 chat-7d449e05562c76bb430efc1c36bd715675a84152.zip |
PLT-5755: Infrastructure for Component Testing. (#5814)
This migrates the existing webapp tests to using Jest and Enzyme. The
infrastructure is put in place for React component testing, and a few
simple example component tests are implemented.
This also adds snapshot testing of components, coverage checking for the
webapp (although that is not yet integrated to Coveralls), and the
ability to run npm run test:watch to automatically re-run affected tests
when working on the webapp codebase.
Diffstat (limited to 'webapp/tests/client/client_channel.test.jsx')
-rw-r--r-- | webapp/tests/client/client_channel.test.jsx | 488 |
1 files changed, 488 insertions, 0 deletions
diff --git a/webapp/tests/client/client_channel.test.jsx b/webapp/tests/client/client_channel.test.jsx new file mode 100644 index 000000000..dae70bca2 --- /dev/null +++ b/webapp/tests/client/client_channel.test.jsx @@ -0,0 +1,488 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import TestHelper from 'tests/helpers/client-test-helper.jsx'; + +describe('Client.Channels', function() { + test('createChannel', function(done) { + TestHelper.initBasic(done, () => { + var channel = TestHelper.fakeChannel(); + channel.team_id = TestHelper.basicTeam().id; + TestHelper.basicClient().createChannel( + channel, + function(data) { + expect(data.id.length).toBeGreaterThan(0); + expect(data.name).toBe(channel.name); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('createDirectChannel', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().createUser( + TestHelper.fakeUser(), + function(user2) { + TestHelper.basicClient().createDirectChannel( + user2.id, + function(data) { + expect(data.id.length).toBeGreaterThan(0); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('createGroupChannel', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().createUser( + TestHelper.fakeUser(), + (user1) => { + TestHelper.basicClient().createUser( + TestHelper.fakeUser(), + function(user2) { + TestHelper.basicClient().createGroupChannel( + [user2.id, user1.id], + function(data) { + expect(data.id.length).toBeGreaterThan(0); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('updateChannel', function(done) { + TestHelper.initBasic(done, () => { + var channel = TestHelper.basicChannel(); + channel.display_name = 'changed'; + TestHelper.basicClient().updateChannel( + channel, + function(data) { + expect(data.id.length).toBeGreaterThan(0); + expect(data.display_name).toEqual('changed'); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('updateChannelHeader', function(done) { + TestHelper.initBasic(done, () => { + var channel = TestHelper.basicChannel(); + channel.display_name = 'changed'; + TestHelper.basicClient().updateChannelHeader( + channel.id, + 'new header', + function(data) { + expect(data.id.length).toBeGreaterThan(0); + expect(data.header).toBe('new header'); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('updateChannelPurpose', function(done) { + TestHelper.initBasic(done, () => { + var channel = TestHelper.basicChannel(); + channel.display_name = 'changed'; + TestHelper.basicClient().updateChannelPurpose( + channel.id, + 'new purpose', + function(data) { + expect(data.id.length).toBeGreaterThan(0); + expect(data.purpose).toEqual('new purpose'); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('updateChannelNotifyProps', function(done) { + TestHelper.initBasic(done, () => { + var props = {}; + props.channel_id = TestHelper.basicChannel().id; + props.user_id = TestHelper.basicUser().id; + props.desktop = 'all'; + TestHelper.basicClient().updateChannelNotifyProps( + props, + function(data) { + expect(data.desktop).toEqual('all'); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('leaveChannel', function(done) { + TestHelper.initBasic(done, () => { + var channel = TestHelper.basicChannel(); + TestHelper.basicClient().leaveChannel( + channel.id, + function(data) { + expect(data.id).toEqual(channel.id); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('joinChannel', function(done) { + TestHelper.initBasic(done, () => { + var channel = TestHelper.basicChannel(); + TestHelper.basicClient().leaveChannel( + channel.id, + function() { + TestHelper.basicClient().joinChannel( + channel.id, + function() { + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('joinChannelByName', function(done) { + TestHelper.initBasic(done, () => { + var channel = TestHelper.basicChannel(); + TestHelper.basicClient().leaveChannel( + channel.id, + function() { + TestHelper.basicClient().joinChannelByName( + channel.name, + function() { + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('deleteChannel', function(done) { + TestHelper.initBasic(done, () => { + var channel = TestHelper.basicChannel(); + TestHelper.basicClient().deleteChannel( + channel.id, + function(data) { + expect(data.id).toEqual(channel.id); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('viewChannel', function(done) { + TestHelper.initBasic(done, () => { + var channel = TestHelper.basicChannel(); + TestHelper.basicClient().viewChannel( + channel.id, + '', + 0, + function() { + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('updateLastViewedAt', function(done) { + TestHelper.initBasic(done, () => { + var channel = TestHelper.basicChannel(); + TestHelper.basicClient().updateLastViewedAt( + channel.id, + true, + function(data) { + expect(data.id).toEqual(channel.id); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('getChannels', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().getChannels( + function(data) { + expect(data.length).toBe(3); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('getChannel', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().getChannel( + TestHelper.basicChannel().id, + function(data) { + expect(TestHelper.basicChannel().id).toEqual(data.channel.id); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('getMoreChannels', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().getMoreChannels( + function(data) { + expect(data.length).toBe(0); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('getMoreChannelsPage', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().getMoreChannelsPage( + 0, + 100, + function(data) { + expect(data.length).toBe(0); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('searchMoreChannels', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().searchMoreChannels( + 'blargh', + function(data) { + expect(data.length).toBe(0); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('autocompleteChannels', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().autocompleteChannels( + TestHelper.basicChannel().name, + function(data) { + expect(data).not.toBeNull(); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('getChannelCounts', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().getChannelCounts( + function(data) { + expect(data.counts[TestHelper.basicChannel().id]).toBe(1); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('getMyChannelMembers', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().getMyChannelMembers( + function(data) { + expect(data.length).toBeGreaterThan(0); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('getMyChannelMembersForTeam', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().getMyChannelMembersForTeam( + TestHelper.basicTeam().id, + function(data) { + expect(data.length).toBeGreaterThan(0); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('getChannelStats', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().getChannelStats( + TestHelper.basicChannel().id, + function(data) { + expect(data.member_count).toBe(1); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('getChannelMember', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().getChannelMember( + TestHelper.basicChannel().id, + TestHelper.basicUser().id, + function(data) { + expect(data.channel_id).toEqual(TestHelper.basicChannel().id); + expect(data.user_id).toEqual(TestHelper.basicUser().id); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('addChannelMember', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().createUserWithInvite( + TestHelper.fakeUser(), + null, + null, + TestHelper.basicTeam().invite_id, + function(user2) { + TestHelper.basicClient().addChannelMember( + TestHelper.basicChannel().id, + user2.id, + function(data) { + expect(data.channel_id.length).toBeGreaterThan(0); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('removeChannelMember', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().removeChannelMember( + TestHelper.basicChannel().id, + TestHelper.basicUser().id, + function(data) { + expect(data.channel_id.length).toBeGreaterThan(0); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); + + test('getChannelByName', function(done) { + TestHelper.initBasic(done, () => { + TestHelper.basicClient().getChannelByName( + TestHelper.basicChannel().name, + function(data) { + expect(data.name).toEqual(TestHelper.basicChannel().name); + done(); + }, + function(err) { + done.fail(new Error(err.message)); + } + ); + }); + }); +}); + |