Skip to content

Commit

Permalink
ADD: Unit Tests for Actions, Reducers, Validation, and Components
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Greene committed Jul 12, 2016
1 parent 7a1dfa6 commit f8964d9
Show file tree
Hide file tree
Showing 28 changed files with 2,911 additions and 654 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [ "es2015", "stage-2", "react" ]
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Simulator/wdc-simulator.js
Simulator/tests
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: node_js
node_js:
- node
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 3
script:
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && npm run test:travis || npm run unit:coveralls'
addons:
sauce_connect:
username: jaustingreene
access_key:
secure: HJoFcs33myPRMQjYxgYnGG1VbxYdbzxUiNRK713qhmCKoIFfZahy7PpOimQ8+0dRJ2rv33DSK5v20LbH7tiOWVWEfEwVOVln8ItPjLTBHX3dUaO8OuO+JA18MFLVBwIWqdrd+h3lvACCjRTnl5DMYbVT37vMPe81xYgee0VqEFaD/3otHwvqVwkWC6GA3r6siXXA45ZeJod1qFQI4G9pixUuFQ6h5cjyk8PFi9n4XWeREgiRjFx6PUVzyK9MnA9swuRHRkLuICmlrpfGjxT0mt/a2m6vbgxf9prFijXV1ngV7GXaqT4hAsk5vnyAQt6kfnIDUBOywnRXLHOHZpzI2ZTRwV8JJ3DIMhEtJZ9At3u+FzXWvaFG7MMBinujQ39iUipKWYgKPJTEkjwOsfROVhclgMC6VZKG/f7FJw85/vKogssxkYimWfqLeDboHjzVzMhUzUPoky59JcNrt48/95Ko7TLMze46mwkmdFMY/5aeekGZhwS2qUHUEb+VV5LxloXkoV6lxlQCCgmNhMRvzYbh2otozjuDvCNOkUU4k+onE2+UfwkVtRlvisA4TLVAltwAMF6h4iVUEz/OiA37756E9qg3rMarV+HKJbjvOtnXOYEzY047LRL17dUl1Ovcg2yKdmaeJa3By0O6Z0mkIDSsIVtDp/pKpr44i2sKsmY=
6 changes: 4 additions & 2 deletions Examples/OAuthProxyExample/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ app.use(express.static(__dirname + '/public'));
// -------------------------------------------------- //
// Variables
// -------------------------------------------------- //
var clientID = config.CLIENT_ID
var clientSecret = config.CLIENT_SECRET
var clientID = process.env.FOURSQUARE_CLIENT_ID || config.CLIENT_ID;
var clientSecret = process.env.FOURSQUARE_CLIENT_SECRET || config.CLIENT_SECRET;
console.log(clientID);
console.log(clientSecret);
var redirectURI = config.HOSTPATH + ":" + config.PORT + config.REDIRECT_PATH

// -------------------------------------------------- //
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Currently in development is version 2.0 of the web data connector API.
# Tableau Web Data Connector SDK
[![Coverage Status](https://coveralls.io/repos/github/jagreene/webdataconnector/badge.svg?branch=tests)](https://coveralls.io/github/jagreene/webdataconnector?branch=tests) [![Build Status](https://travis-ci.org/jagreene/webdataconnector.svg?branch=tests)](https://travis-ci.org/jagreene/webdataconnector)

Currently in development is version 2.0 of the web data connector API.

All of the information for this content can be found in our beta docs: [http://tableau.github.io/webdataconnector](http://tableau.github.io/webdataconnector/).

Expand Down
16 changes: 10 additions & 6 deletions Simulator/actions/messaging_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export function receiveMessage(payload) {
return (dispatch) => {
try {
const { msgData, msgName, props: attrs, version } = JSON.parse(payload.data);

if(version=== "1.1.0" || version === "1.1.1") {
var errmsg = 'this simulator only supports wdcs that are using version 2.0 of the api or later, your wdc\'s version is: ' + wdcapiversion;
toastr.error(errmsg, 'unsupported wdc version error:')
}

if (attrs) {
dispatch(simulatorActions.setWdcAttrs(attrs));
}
Expand All @@ -20,6 +26,7 @@ export function receiveMessage(payload) {

case eventNames.LOADED: {
dispatch(handleLoaded(version));
handleLoaded();
break;
}

Expand Down Expand Up @@ -192,13 +199,13 @@ export function handleAbortForAuth(errMsg) {
'use the "Start Auth Phase" to test ' +
'your WDC Auth Mode:';
dispatch(simulatorActions.setPhaseInProgress(false));
dispatch(simulatorActions.closeSimulator());
dispatch(simulatorActions.closeSimulatorWindow());
toastr.error(errMsg, toastTitle);
};
}

// Send message thunks
export function sendMessage(messageName, payload) {
export function sendMessage(messageName, payload = {}) {
return (dispatch, getState) => {
// Construct payload and send info to whichever
// window we are posting too
Expand All @@ -209,9 +216,6 @@ export function sendMessage(messageName, payload) {
props: wdcAttrs,
});
simulatorWindow.postMessage(messagePayload, '*');

// if (simulatorWindow) {
// }
};
}

Expand All @@ -228,7 +232,7 @@ export function sendGetHeaders() {
};
}

// Takes an array of tableuInfo/incValue paris
// Takes an array of tableuInfo/incValue pairs
export function sendGetData(tablesAndIncrementValues, isFreshFetch) {
return (dispatch) => {
if (isFreshFetch) {
Expand Down
15 changes: 11 additions & 4 deletions Simulator/actions/simulator_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ export const setTables = createAction('SET_TABLES');
export const addTables = createAction('ADD_TABLES');

// Reset Actions
export const resetState = createAction('RESET_STATE');
export const resetState = createAction('RESET_STATE', () => {
const wdcUrl = Cookie.get('lastUrl') || '../Examples/html/earthquakeUSGS.html';
return { ...consts.defaultState, wdcUrl };
});

export const resetPhaseState = createAction('RESET_PHASE_STATE');
export const resetWdcAttrs = createAction('RESET_WDC_ATTRS');
export const resetTables = createAction('RESET_TABLES');
export const resetTableData = createAction('RESET_TABLE_Data');
export const resetTableData = createAction('RESET_TABLE_DATA');


// Thunks (and Composed Actions)
Expand Down Expand Up @@ -71,7 +75,7 @@ export function startGatherDataPhase() {
export function setWindowAsExternal() {
return (dispatch, getState) => {
const { wdcUrl } = getState();
const simulatorWindow = window.open(wdcUrl, 'simulator', consts.WINDOW_PROPS);
const simulatorWindow = window.open(wdcUrl, 'wdc', consts.WINDOW_PROPS);
dispatch(setSimulatorWindow(simulatorWindow));
};
}
Expand All @@ -82,7 +86,10 @@ export function setWindowAsExternal() {
// in the desktop version of the connector lifecycle
export function setWindowAsGatherFrame(iframe) {
return (dispatch) => {
dispatch(setSimulatorWindow(iframe.contentWindow));
//ref function might be called by react without a valid reference
if (!!iframe) {
dispatch(setSimulatorWindow(iframe.contentWindow));
}
};
}

Expand Down
3 changes: 2 additions & 1 deletion Simulator/components/AddressBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ class AddressBar extends Component {
<ControlLabel> Connector URL </ControlLabel>
<InputGroup>
<FormControl
id="address-input"
type="text"
disabled={this.props.disabled}
label="WDC URL"
value={this.props.wdcUrl}
onChange={this.handleWdcUrlChange}
/>
<InputGroup.Button>
<Button onClick={this.props.resetSimulator}> Reset </Button>
<Button id="reset-btn" onClick={this.props.resetSimulator}> Reset </Button>
</InputGroup.Button>
</InputGroup>
</FormGroup>
Expand Down
1 change: 0 additions & 1 deletion Simulator/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class App extends Component {

const inDataGatherPhase = this.props.currentPhase === consts.phases.GATHER_DATA;


const hasData = !!this.props.tables && Object.keys(this.props.tables).length > 0;
const isWdcUrlEmpty = (this.props.wdcUrl === '');

Expand Down
2 changes: 2 additions & 0 deletions Simulator/components/StartConnectorGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ class StartConnectorGroup extends Component {
</div>
<div>
<Button
id="interactive-btn"
onClick={this.props.startInteractivePhase}
bsStyle="success"
disabled={this.props.isInProgress || this.props.isWDCUrlEmpty}
>
Start Interactive Phase
</Button>
<Button
id="auth-btn"
onClick={this.props.startAuthPhase}
bsStyle="success"
style={{ marginLeft: '4px' }}
Expand Down
22 changes: 19 additions & 3 deletions Simulator/components/TablePreview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ class TablePreview extends Component {
{
!this.props.fetchInProgress ?
<Button
className="fetch-btn"
onClick={this.freshFetch}
bsStyle="success"
>
Fetch Table Data
</Button> :
<Button
className="fetch-btn"
disabled
bsStyle="success"
>
Expand All @@ -93,6 +95,7 @@ class TablePreview extends Component {
{
canIncrementalUpdate ?
<Button
className="incremental-fetch-btn"
onClick={this.incrementalRefresh}
style={{ marginLeft: '4px' }}
>
Expand Down Expand Up @@ -145,9 +148,15 @@ class TablePreview extends Component {
<td key={columnTableRowKey++}> {cellVal} </td>
);

return <tr key={columnTableRowKey++}>{cells}</tr>;
return (
<tr
className="metadata-row"
key={columnTableRowKey++}
>
{cells}
</tr>
);
});

return columnElements;
}

Expand Down Expand Up @@ -183,7 +192,14 @@ class TablePreview extends Component {
}
return <td key={dataTableColKey++}> {String(cellValue)} </td>;
});
return <tr key={dataTableRowKey++}>{cells}</tr>;
return (
<tr
className="data-row"
key={dataTableRowKey++}
>
{cells}
</tr>
);
});
}
return dataElements;
Expand Down
5 changes: 2 additions & 3 deletions Simulator/reducers/reducers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { handleActions } from 'redux-actions';
import { defaultState } from '../utils/consts';

// The redux reducers, which create the next state object
// from the payload of any given action.
Expand Down Expand Up @@ -31,10 +30,10 @@ export default handleActions({
({ ...state, tables: action.payload }),
ADD_TABLES: (state, action) =>
({ ...state, tables: { ...state.tables, ...action.payload } }),
RESET_STATE: () => (defaultState),
RESET_STATE: (state, action) => action.payload,
RESET_PHASE_STATE: (state) => ({
...state,
phaseInPropgress: false,
phaseInProgress: false,
phaseSubmitCalled: false,
phaseInitCallbackCalled: false,
}),
Expand Down
Loading

0 comments on commit f8964d9

Please sign in to comment.