Skip to content

Commit

Permalink
[#136164537] - Fixed up wiring of front-end actions to backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
cfreeman committed Mar 2, 2017
1 parent 495b1cb commit 26aafe6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion frontend/src/components/primaryActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ CalibrateAction.contextTypes = {
var SaveAction = React.createClass({
handleSave: function() {
const { store } = this.context;
console.log(store);
UpdateActiveLocation(store, "name", document.getElementById('locationInput').value);
store.dispatch({ type:'SAVE_LOCATION' })
},
Expand Down Expand Up @@ -128,7 +129,7 @@ var SettingsAction = React.createClass({

render: function() {
return (
<a href="#" onClick={this.handleSettings}>[<i className="fa fa-cog"></i> settings]</a>
<a id="settings" href="#" onClick={this.handleSettings}>[<i className="fa fa-cog"></i> settings]</a>
);
}
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function SaveActiveLocation(store) {

// Push the active location to the backend.
var httpreq = new XMLHttpRequest();
httpreq.open("PUT", "http://"+window.location.host+"/scouts/"+l.id, true);
httpreq.open("PUT", "http://"+window.location.host+"/scouts/"+l.uuid, true);
httpreq.send(JSON.stringify(l));
httpreq.onreadystatechange = function() {
if (httpreq.readyState == 4 && httpreq.status == 200) {
Expand All @@ -63,7 +63,7 @@ function UpdateActiveLocation(store, field, value) {
Reflect.set(l, field, value);
state.locations[state.active] = l;

this.SaveActiveLocation(store);
SaveActiveLocation(store);
}

function Mothership(state, action) {
Expand Down
16 changes: 16 additions & 0 deletions frontend/test/components/primaryActions.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ const mockStore = configureStore();

describe('components', () => {
describe('PrimaryActions', () => {
it('should display a settings button', () => {
var s = {locations:[{id:2, uuid:'800fd548-2d2b-4185-885d-6323ccbe88a0', port:8080, authorised:true, name:'NYPL', state:'idle'}], active:0};

var c = mount(<Provider store={mockStore(s)}><PrimaryActions /></Provider>);
expect(c.find('#settings').length).toEqual(1);
})

it('settings button should dispatch an edit settings action on click', () => {
var s = {locations:[{id:2, uuid:'800fd548-2d2b-4185-885d-6323ccbe88a0', port:8080, authorised:true, name:'NYPL', state:'idle'}], active:0};
var st = mockStore(s);
var c = mount(<Provider store={st}><PrimaryActions /></Provider>);

c.find('#settings').simulate('click');
expect(st.getActions()).toEqual([{type:'EDIT_SETTINGS'}])
})

it('should provide an activate/deactivate button based on authorised state', () => {
var s = {locations:[{id:2, uuid:'800fd548-2d2b-4185-885d-6323ccbe88a0', port:8080, authorised:true, name:'NYPL', state:'idle'}], active:0};

Expand Down

0 comments on commit 26aafe6

Please sign in to comment.