Changed actions tests to use TestHelper
This commit is contained in:
parent
15a44ad453
commit
8c3f60e41d
2 changed files with 55 additions and 41 deletions
|
|
@ -6,64 +6,67 @@ import assert from 'assert';
|
|||
import * as Actions from 'actions/general.js';
|
||||
import Client from 'client/client_instance.js';
|
||||
import configureStore from 'store/configureStore.js';
|
||||
import TestHelper from 'test_helper.js';
|
||||
|
||||
describe('Actions.General', () => {
|
||||
beforeEach(() => {
|
||||
Client.setUrl('http://localhost:8065');
|
||||
});
|
||||
|
||||
it('getClientConfig', (done) => {
|
||||
const store = configureStore();
|
||||
TestHelper.initClient(Client, () => {
|
||||
const store = configureStore();
|
||||
|
||||
store.subscribe(() => {
|
||||
const clientConfig = store.getState().entities.general.clientConfig;
|
||||
store.subscribe(() => {
|
||||
const clientConfig = store.getState().entities.general.clientConfig;
|
||||
|
||||
if (!clientConfig.loading) {
|
||||
if (clientConfig.error) {
|
||||
done(new Error(clientConfig.error));
|
||||
} else {
|
||||
// Check a few basic fields since they may change over time
|
||||
assert.ok(clientConfig.data.Version);
|
||||
assert.ok(clientConfig.data.BuildNumber);
|
||||
assert.ok(clientConfig.data.BuildDate);
|
||||
assert.ok(clientConfig.data.BuildHash);
|
||||
if (!clientConfig.loading) {
|
||||
if (clientConfig.error) {
|
||||
done(new Error(clientConfig.error));
|
||||
} else {
|
||||
// Check a few basic fields since they may change over time
|
||||
assert.ok(clientConfig.data.Version);
|
||||
assert.ok(clientConfig.data.BuildNumber);
|
||||
assert.ok(clientConfig.data.BuildDate);
|
||||
assert.ok(clientConfig.data.BuildHash);
|
||||
|
||||
done();
|
||||
done();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Actions.getClientConfig()(store.dispatch, store.getState);
|
||||
Actions.getClientConfig()(store.dispatch, store.getState);
|
||||
});
|
||||
});
|
||||
|
||||
it('getPing', (done) => {
|
||||
const store = configureStore();
|
||||
TestHelper.initClient(Client, () => {
|
||||
const store = configureStore();
|
||||
|
||||
store.subscribe(() => {
|
||||
const ping = store.getState().entities.general.ping;
|
||||
store.subscribe(() => {
|
||||
const ping = store.getState().entities.general.ping;
|
||||
|
||||
if (ping.error) {
|
||||
done(new Error(ping.error));
|
||||
} else if (!ping.loading) {
|
||||
done();
|
||||
}
|
||||
if (ping.error) {
|
||||
done(new Error(ping.error));
|
||||
} else if (!ping.loading) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
Actions.getPing()(store.dispatch, store.getState);
|
||||
});
|
||||
|
||||
Actions.getPing()(store.dispatch, store.getState);
|
||||
});
|
||||
|
||||
it('getPing - Invalid URL', (done) => {
|
||||
const store = configureStore();
|
||||
TestHelper.initClient(Client, () => {
|
||||
const store = configureStore();
|
||||
|
||||
store.subscribe(() => {
|
||||
const ping = store.getState().entities.general.ping;
|
||||
store.subscribe(() => {
|
||||
const ping = store.getState().entities.general.ping;
|
||||
|
||||
if (!ping.loading && ping.error) {
|
||||
done();
|
||||
}
|
||||
if (!ping.loading && ping.error) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
Client.setUrl('https://example.com/fake/url');
|
||||
Actions.getPing()(store.dispatch, store.getState);
|
||||
});
|
||||
|
||||
Client.setUrl('https://example.com/fake/url');
|
||||
Actions.getPing()(store.dispatch, store.getState);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ const PASSWORD = 'password1';
|
|||
class TestHelper {
|
||||
constructor() {
|
||||
this.basicClient = null;
|
||||
|
||||
this.basicUser = null;
|
||||
this.basicTeam = null;
|
||||
this.basicChannel = null;
|
||||
this.basicPost = null;
|
||||
}
|
||||
|
||||
assertStatusOkay = (data) => {
|
||||
|
|
@ -88,8 +93,8 @@ class TestHelper {
|
|||
};
|
||||
}
|
||||
|
||||
initBasic = (callback) => {
|
||||
const client = this.createClient();
|
||||
initClient = (client, callback) => {
|
||||
client.setUrl('http://localhost:8065');
|
||||
|
||||
client.createUser(
|
||||
this.fakeUser(),
|
||||
|
|
@ -160,6 +165,12 @@ class TestHelper {
|
|||
}
|
||||
);
|
||||
}
|
||||
|
||||
initBasic = (callback) => {
|
||||
this.basicClient = this.createClient();
|
||||
|
||||
this.initClient(this.basicClient, callback);
|
||||
}
|
||||
}
|
||||
|
||||
export default new TestHelper();
|
||||
Loading…
Reference in a new issue