Commit f630b3cb authored by MrMan's avatar MrMan

Add sketons for almost-working end to end tests

parent e5bd47d5
......@@ -62,25 +62,33 @@ class AppPage extends React.Component {
<div className="pinned-to-bottom app-page-controls">
<div className="row landing-wide-button">
<button onClick={this.viewRecs.bind(this)} className="pure-u-1 pure-button button-lg squared button-success">
<button id="recs-page-link-button"
onClick={this.viewRecs.bind(this)}
className="pure-u-1 pure-button button-lg squared button-success">
<i className="fa fa-binoculars"></i> {this.i18n`nav.sections.findAMatch`}
</button>
</div>
<div className="row landing-wide-button">
<button onClick={this.viewMatches.bind(this)} className="pure-u-1 pure-button button-lg squared button-error">
<button id="matches-page-link-button"
onClick={this.viewMatches.bind(this)}
className="pure-u-1 pure-button button-lg squared button-error">
<i className="fa fa-heart"></i> {this.i18n`nav.sections.matches`}
</button>
</div>
<div className="row landing-wide-button">
<button onClick={this.goToPreferencesPage.bind(this)} className="pure-u-1 pure-button button-lg squared button-secondary wet-asphalt-bg">
<button id="preferences-page-link-button"
onClick={this.goToPreferencesPage.bind(this)}
className="pure-u-1 pure-button button-lg squared button-secondary wet-asphalt-bg">
<i className="fa fa-wrench"></i> {this.i18n`nav.sections.preferences`}
</button>
</div>
<div className="row landing-wide-button">
<button onClick={this.doLogout.bind(this)} className="pure-u-1 pure-button button-lg squared">
<button id="logout-button"
onClick={this.doLogout.bind(this)}
className="pure-u-1 pure-button button-lg squared">
<i className="fa fa-sign-out"></i> {this.i18n`nav.sections.logout`}
</button>
</div>
......
......@@ -2,6 +2,7 @@ import _ from "lodash";
import fetch from "vendor/fetch";
import Constants from "./constants";
import Actions from "./actions";
import { detectFFOSPlatform } from "./util";
let AUTHENTICATION_RETRIES = 0;
......
......@@ -2,6 +2,7 @@ import _ from "lodash";
import fetch from "vendor/fetch";
import Constants from "./constants";
import URI from "uri.js";
import "vendor/fetch";
// Error patterns for Tinder's FB auth request redirect
const re_login_resp_err = /error=([^&]+)/;
......@@ -114,3 +115,10 @@ export function updatePropertyWithEventTargetValue(propName, comp) {
comp.setState(statePartial);
};
}
/**
* Detect if app is on Firefox OS (assumed browser otherwise)
*/
export function detectFFOSPlatform() {
return !_.isNull(window.navigator.userAgent.match(/Mozilla.*Mobile;/));
}
import Q from 'q';
import Static from 'node-static';
import Http from 'http';
import NM from 'nightmare';
import "should";
import { every } from "lodash";
import { loginTestUserAndGotoRoot, mockFetch } from "./utils";
import E2ETestConstants from "./constants";
// Test constants
let STATIC_SERVER;
let NODE_SERVER;
const DIST_PATH = `${__dirname}/../../dist`;
// Page constants
const NAV_BUTTON_IDS = [
"#recs-page-link-button",
"#matches-page-link-button",
"#preferences-page-link-button",
"body"
];
describe("App main page", function() {
this.timeout(E2ETestConstants.DEFAULT_TIMEOUT);
let nm;
before(done => {
// Init nightmare instance (and electron process)
nm = NM();
// Create static server
STATIC_SERVER = new Static.Server(DIST_PATH);
NODE_SERVER = Http.createServer((req, resp) => {
req.addListener('end', () => {
STATIC_SERVER.serve(req, resp);
}).resume();
}).listen(E2ETestConstants.SERVER_PORT, () => {
// Log in before test starts
Q.all([
nm.loginTestUserAndGotoRoot(),
mockFetch(nm, /https:\/\/api.gotinder.com\/auth/, {data: "some data"}),
]).then(results => {
done();
});
});
});
it("The app main page should be up", (done) => {
Q.Promise.resolve(
nm.url()
).then(url => {
url.should.match(/index.html#\/app/);
done();
});
});
it("should contain expected navigation links", (done) => {
nm.exists("#recs-page-link-button").then(first => {
nm.exists("#preferences-page-link-buttonz").then(second => {
every([first,second]).should.be.true();
done();
});
});
});
after(done => {
// End the electron process and the node server
Promise.resolve(nm.end()).then(() => {
NODE_SERVER.close(done);
});
});
});
/**
* Wrap an nightmare exists call in a proper promise
*
* @param {object} nm - Nightmare instance
* @param {string} selector - The selector to look for
* @returns A Promise that resolves to true or rejects (if exists returns false)
*/
function existsPromise(nm, selector) {
return Q.Promise((resolve, reject) => {
nm.exists(selector)
.then(res => {
if (res) {
resolve(true);
} else {
reject(`Failed to find selector ${selector}`);
}
});
});
}
const SERVER_PORT = 8080;
const BASE_URL = `http://localhost:${SERVER_PORT}`;
const DEFAULT_TIMEOUT = 10000;
export default {
SERVER_PORT,
BASE_URL,
DEFAULT_TIMEOUT
};
......@@ -42,7 +42,7 @@ describe("Login page", function() {
});
});
it("Should show the login button", (done) => {
it("Should show the login button for a user that isn't logged in", (done) => {
Q.all(
nm.goto(BASE_URL).exists(LOGIN_BUTTON_ID),
nm.goto(BASE_URL).visible(LOGIN_BUTTON_ID)
......
import Q from 'q';
import NM from 'nightmare';
import E2ETestConstants from './constants';
const TEST_USER_FB_ID = "TESTUSERFBID";
const TEST_USER_TINDER_ID = "TESTUSERFBID";
const TEST_USER_FB_ID_EXPIRES_IN = "9999999";
const TEST_USER_CALLBACK_URL = E2ETestConstants.BASE_URL + `/index.html#/access_token=${TEST_USER_FB_ID}&expires_in=${TEST_USER_FB_ID_EXPIRES_IN}`;
// function setupUserLoginMocks() {
// }
/**
* Login test user and go to main app page
*/
NM.action('loginTestUserAndGotoRoot', function(done) {
Q.Promise.resolve(
this.goto(TEST_USER_CALLBACK_URL)
).then(done);
});
/**
* Mocka fetch
*/
export function mockFetch(nm, urlRegex, response) {
return nm.evaluate(function() {
window.originalFetch = window.fetch;
window.fetch = function(url, opts) {
if (url.match(urlRegex) != null) {
return response;
} else {
return originalFetch(url, opts);
}
};
});
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment