Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
beginning testing settings actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Boothroyd committed Sep 6, 2017
1 parent 1a1d33c commit 5125cf6
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 114 deletions.
2 changes: 1 addition & 1 deletion app/reducers/settingsUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type SettingsUIState = Readonly<{
tlsClientOverrideAuthorityError: boolean;
}>;

const initialSettingsUIState: SettingsUIState = {
export const initialSettingsUIState: SettingsUIState = {
endpointRequired: false,
endpointError: false,
protoDiscoveryRootError: false,
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "main.js",
"scripts": {
"test": "cross-env NODE_ENV=test node --trace-warnings ./test/runTests.js",
"test-all": "npm run test && npm run build && npm run test-e2e",
"test-all": "npm run test && npm run test-e2e",
"test-watch": "npm test -- --watch",
"test-e2e": "cross-env NODE_ENV=test node --trace-warnings ./test/runTests.js e2e",
"hot-server": "cross-env NODE_ENV=development node --max_old_space_size=2096 server.js",
Expand Down Expand Up @@ -138,6 +138,7 @@
"@types/text-encoding": "0.0.31",
"@types/universal-analytics": "^0.4.1",
"@types/valid-url": "^1.0.2",
"@types/webdriverio": "^4.8.4",
"@types/webfontloader": "^1.6.28",
"asar": "^0.13.0",
"boiler-room-custodian": "^0.6.2",
Expand Down
227 changes: 129 additions & 98 deletions test/e2e/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,102 +1,133 @@
// import * as electronPath from "electron";
// import * as path from "path";
/* tslint:disable:no-console */
import * as path from 'path';

// const { Application } = require("spectron"); // tslint:disable-line
import { Application } from 'spectron';

// const delay = (time: number) => new Promise((resolve) => setTimeout(resolve, time));

// describe("main window", function spec() {
// let app: any;
// beforeAll(async () => {
// app = new Application({
// path: electronPath,
// args: [path.join(__dirname, "..", "..", "app")],
// });
// return app.start();
// });

// afterAll(() => {
// if (app && app.isRunning()) {
// return app.stop();
// }
// });

// const findCounter = () => app.client.element("[data-tid='counter']");

// const findButtons = async () => {
// const { value } = await app.client.elements("[data-tclass='btn']");
// return value.map((btn: any) => btn.ELEMENT);
// };

// it("should open window", async () => {
// const { client, browserWindow } = app;

// await client.waitUntilWindowLoaded();
// await delay(500);
// const title = await browserWindow.getTitle();
// expect(title).toBe("Dragoman");
// });

// it("should navigate to Counter by "to Counter" link", async () => {
// const { client } = app;

// await client.click("[data-tid="container"] > a");
// await delay(100);
// expect(await findCounter().getText()).toBe("0");
// });

// it("should display updated count after increment button click", async () => {
// const { client } = app;

// const buttons = await findButtons();
// await client.elementIdClick(buttons[0]); // +
// expect(await findCounter().getText()).toBe("1");
// });

// it("should display updated count after descrement button click", async () => {
// const { client } = app;

// const buttons = await findButtons();
// await client.elementIdClick(buttons[1]); // -
// expect(await findCounter().getText()).toBe("0");
// });

// it("shouldn\"t change if even and if odd button clicked", async () => {
// const { client } = app;

// const buttons = await findButtons();
// await client.elementIdClick(buttons[2]); // odd
// expect(await findCounter().getText()).toBe("0");
// });

// it("should change if odd and if odd button clicked", async () => {
// const { client } = app;

// const buttons = await findButtons();
// await client.elementIdClick(buttons[0]); // +
// await client.elementIdClick(buttons[2]); // odd
// expect(await findCounter().getText()).toBe("2");
// });

// it("should change if async button clicked and a second later", async () => {
// const { client } = app;

// const buttons = await findButtons();
// await client.elementIdClick(buttons[3]); // async
// expect(await findCounter().getText()).toBe("2");
// await delay(1000);
// expect(await findCounter().getText()).toBe("3");
// });

// it("should navigate to home using back button", async () => {
// const { client } = app;
// await client.element(
// "[data-tid="backButton"] > a"
// ).click();
// await delay(100);

// expect(
// await client.isExisting("[data-tid="container"]")
// ).toBe(true);
// });
// });
describe('main window', function spec() {
let app: Application;
beforeAll(() => {
let pathToBinary;

switch (process.platform) {
case 'linux':
pathToBinary = path.join(__dirname, '../../release/linux-unpacked/dragoman');
break;

case 'darwin':
pathToBinary = path.join(__dirname, '../../release/mac/Dragoman.app/Contents/MacOS/Dragoman');
break;

case 'win32':
pathToBinary = path.join(__dirname, '../release/win-unpacked/Dragoman.exe');
break;

default:
throw new Error('Path to the built binary needs to be defined for this platform in test/index.js');
}

app = new Application({
path: pathToBinary,
});
return app.start();
});

afterAll(() => {
if (app && app.isRunning()) {
return app.stop();
} else {
return;
}
});

// const findCounter = () => app.client.element('[data-tid='counter']');

// const findButtons = async () => {
// const { value } = await app.client.elements('[data-tclass='btn']');
// return value.map((btn: any) => btn.ELEMENT);
// };

it('should open window', () => {
// delay(1000);
const { client, browserWindow } = app;

return client.waitUntilWindowLoaded()
.then(() => { return browserWindow.webContents.isDevToolsOpened(); })
.then((isDevToolsOpen) => {
expect(isDevToolsOpen).toBe(false);
});
});

it('should have a title', async () => {
const { client, browserWindow } = app;

await client.waitUntilWindowLoaded();
const title = await browserWindow.getTitle();
console.error(title);
expect(title).toBe('Dragoman');
});

// it('should navigate to Counter by 'to Counter' link', async () => {
// const { client } = app;

// await client.click('[data-tid='container'] > a');
// await delay(100);
// expect(await findCounter().getText()).toBe('0');
// });

// it('should display updated count after increment button click', async () => {
// const { client } = app;

// const buttons = await findButtons();
// await client.elementIdClick(buttons[0]); // +
// expect(await findCounter().getText()).toBe('1');
// });

// it('should display updated count after descrement button click', async () => {
// const { client } = app;

// const buttons = await findButtons();
// await client.elementIdClick(buttons[1]); // -
// expect(await findCounter().getText()).toBe('0');
// });

// it('shouldn\'t change if even and if odd button clicked', async () => {
// const { client } = app;

// const buttons = await findButtons();
// await client.elementIdClick(buttons[2]); // odd
// expect(await findCounter().getText()).toBe('0');
// });

// it('should change if odd and if odd button clicked', async () => {
// const { client } = app;

// const buttons = await findButtons();
// await client.elementIdClick(buttons[0]); // +
// await client.elementIdClick(buttons[2]); // odd
// expect(await findCounter().getText()).toBe('2');
// });

// it('should change if async button clicked and a second later', async () => {
// const { client } = app;

// const buttons = await findButtons();
// await client.elementIdClick(buttons[3]); // async
// expect(await findCounter().getText()).toBe('2');
// await delay(1000);
// expect(await findCounter().getText()).toBe('3');
// });

// it('should navigate to home using back button', async () => {
// const { client } = app;
// await client.element(
// '[data-tid='backButton'] > a'
// ).click();
// await delay(100);

// expect(
// await client.isExisting('[data-tid='container']')
// ).toBe(true);
// });
});
76 changes: 76 additions & 0 deletions test/reducers/settingsData.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import settingsData, { initialSettingsDataState } from '../../app/reducers/settingsData';
import * as settingsDataActions from '../../app/actions/settingsData';

describe('settings UI reducer', () => {
describe('endpoint error', () => {
it('should handle initial state', () => {
expect(settingsData(undefined, { type: 'UNKNOWN', payload: {} })).toEqual(initialSettingsDataState);
});

it('should handle SET_PROTO_DISCOVERY_ROOT', () => {
expect(settingsData(undefined, settingsDataActions.setProtoDiscoveryRoot('/Users')).protoDiscoveryRoot).toEqual('/Users');
});

it('should handle SET_ENDPOINT', () => {
expect(settingsData(undefined, settingsDataActions.setEndpoint('host:50')).endpoint).toEqual('host:50');
});

it('should handle SET_CONFIG_SET_PATH_ERROR', () => {
expect(settingsData(undefined, settingsDataActions.setConfigSetPath('/Users')).configSetPath).toEqual('/Users');
});

it('should handle SET_CONFIG_NAME', () => {
expect(settingsData(undefined, settingsDataActions.setConfigName('staging')).configName).toEqual('staging');
});

it('should handle SET_DEADLINE_MS', () => {
expect(settingsData(undefined, settingsDataActions.setDeadlineMs(50)).deadlineMs).toEqual(50);
});

it('should handle SET_ADD_PROTOC_INCLUDES', () => {
expect(settingsData(undefined, settingsDataActions.setAddProtocIncludes('/Users,/Users/peteboothroyd')).addProtocIncludes).toEqual('/Users,/Users/peteboothroyd');
});

it('should handle SET_OAUTH_REFRESH_TOKEN_ENDPOINT_URL', () => {
expect(settingsData(undefined, settingsDataActions.setOauthRefreshTokenEndpointUrl('https://improbable.io')).oauthRefreshTokenEndpointUrl).toEqual('https://improbable.io');
});

it('should handle SET_OAUTH_CLIENT_ID', () => {
expect(settingsData(undefined, settingsDataActions.setOauthClientId('id')).oauthClientId).toEqual('id');
});

it('should handle SET_OAUTH_CLIENT_SECRET', () => {
expect(settingsData(undefined, settingsDataActions.setOauthClientSecret('secret')).oauthClientSecret).toEqual('secret');
});

it('should handle SET_OAUTH_REFRESH_TOKEN_PATH', () => {
expect(settingsData(undefined, settingsDataActions.setOauthRefreshTokenPath('/Users')).oauthRefreshTokenPath).toEqual('/Users');
});

it('should handle SET_OAUTH_ACCESS_TOKEN_PATH', () => {
expect(settingsData(undefined, settingsDataActions.setOauthAccessTokenPath('/Users')).oauthAccessTokenPath).toEqual('/Users');
});

it('should handle SET_USE_TLS', () => {
expect(settingsData(undefined, settingsDataActions.setUseTls(true)).useTls).toEqual(true);
});

it('should handle SET_TLS_CA_CERT_PATH', () => {
expect(settingsData(undefined, settingsDataActions.setTlsCaCertPath('/Users')).tlsCaCertPath).toEqual('/Users');
});

it('should handle SET_TLS_CLIENT_KEY_PATH', () => {
expect(settingsData(undefined, settingsDataActions.setTlsClientKeyPath('/Users')).tlsClientKeyPath).toEqual('/Users');
});

it('should handle SET_TLS_CLIENT_CERT_PATH', () => {
expect(settingsData(undefined, settingsDataActions.setTlsClientCertPath('/Users')).tlsClientCertPath).toEqual('/Users');
});

it('should handle SET_TLS_CLIENT_OVERRRIDE_AUTHORITY', () => {
expect(settingsData(undefined, settingsDataActions.setTlsClientOverrideAuthority('authority')).tlsClientOverrideAuthority).toEqual('authority');
});

// TODO: Add tests for importing polyglot configs from an example config file
});
});
Loading

0 comments on commit 5125cf6

Please sign in to comment.