Skip to content

Commit e2ee8d3

Browse files
author
madmax983
committed
Added tests for library compat. Updated Readme, unmanaged packages and links.
1 parent 81977fc commit e2ee8d3

File tree

3 files changed

+122
-3
lines changed

3 files changed

+122
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ middleware: You can include redux middleware like redux-thunk here. Lightning-Re
2323

2424
**registerReducer(name, reducer):** Adds the specified reducer function to the redux store with the specificed name as it's slice of state.
2525

26-
**connect(mapStateToAttributes, target):** mapStateToAttributes is a key pair object where the key is the attribute on the component you want set, and the value is either the value in the redux state graph, or a callback function. This function receives the component and state to compute the value. You can pass the component you want connected, but if it isn't populated, it will get populated by event.getSource(). It also sets a dispatch expando for convenience in the component's controller methods.
26+
**connect(mapStateToAttributes, target):** mapStateToAttributes either a key pair object where the key is the attribute on the component you want set, and the value is either the value in the redux state graph, or a callback function. mapStateToAttributes can also be a function that returns this key pair value. This function receives the state and component to compute the value. You can pass the component you want connected, but if it isn't populated, it will get populated by event.getSource(). It also sets a dispatch expando for convenience in the component's controller methods.
2727

2828
**getState():** Technically not a component method, this is a convenience expando that allows access to the Redux state.
2929

3030
## Installation
31-
Lightning-Redux Unmanaged Packaged (Redux Component, redux and redux-thunk static resource): https://login.salesforce.com/packaging/installPackage.apexp?p0=04t50000000M7PT
31+
Lightning-Redux Unmanaged Packaged (Redux Component, redux, redux-thunk, and reselect static resource): https://login.salesforce.com/packaging/installPackage.apexp?p0=04t50000000M7PY
3232

33-
Lightning-Redux-Examples (Counter and Todo Examples unmanaged package): https://login.salesforce.com/packaging/installPackage.apexp?p0=04t50000000M7Pn
33+
Lightning-Redux-Examples (Counter and Todo Examples unmanaged package): https://login.salesforce.com/packaging/installPackage.apexp?p0=04t50000000M7Px
3434

3535
Otherwise, you can use the SFDX CLI to convert the source and do a metadata deploy.
3636

force-app/test/default/aura/BaseTestRunnerCmp/BaseTestRunnerCmp.cmp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
$Resource.testutil,
1919
$Resource.redux,
2020
$Resource.reduxThunk,
21+
$Resource.reselect,
2122
v.testspecs
2223
)}"
2324
styles="{!join(',',

force-app/test/default/staticresources/reduxTests.resource

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,122 @@ describe("Redux Tests", function() {
313313
});
314314
});
315315
});
316+
317+
describe('Test Library Compatibility', function() {
318+
it('is compatible with Redux Thunk', function(done) {
319+
var renderInto = document.getElementById("renderTestComponents");
320+
$T.createComponent("c:Redux", {}, renderInto)
321+
.then(function(component) {
322+
function counterReducer(state, action) {
323+
switch (action.type) {
324+
case 'INCREMENT':
325+
return state + 1;
326+
case 'DECREMENT':
327+
return state - 1;
328+
default:
329+
var defaultState = 0;
330+
return defaultState;
331+
}
332+
}
333+
334+
function incrementThunk() {
335+
return function(dispatch) {
336+
return dispatch({
337+
type: "INCREMENT"
338+
});
339+
}
340+
}
341+
342+
function decrementThunk() {
343+
return function(dispatch) {
344+
return dispatch({
345+
type: "DECREMENT"
346+
});
347+
}
348+
}
349+
350+
component.createStore("counter", counterReducer, {}, ReduxThunk.default);
351+
component.dispatch(incrementThunk());
352+
expect(component.getState().counter).toBe(1);
353+
component.dispatch(decrementThunk());
354+
expect(component.getState().counter).toBe(0);
355+
done();
356+
}).catch(function(e) {
357+
done.fail(e);
358+
});
359+
});
360+
it('is compatible with Reselect', function(done) {
361+
var renderInto = document.getElementById("renderTestComponents");
362+
$T.createComponent("c:TestReduxContainer", {}, renderInto)
363+
.then(function(component) {
364+
365+
var redux = component.find("store");
366+
367+
function helloWorldReducer(state, action) {
368+
switch(action.type) {
369+
case "JOHN":
370+
return "Hello John";
371+
default:
372+
return "Hello World";
373+
}
374+
}
375+
376+
function counterReducer(state, action) {
377+
switch (action.type) {
378+
case 'INCREMENT':
379+
return state + 1;
380+
case 'DECREMENT':
381+
return state - 1;
382+
default:
383+
var defaultState = 0;
384+
return defaultState;
385+
}
386+
}
387+
388+
redux.createStore("helloWorld", helloWorldReducer);
389+
redux.registerReducer("counter", counterReducer);
390+
391+
var computeStateCalledCounter = 0;
392+
393+
394+
395+
var helloWorldSelector = function(state, component) {
396+
return state.helloWorld;
397+
}
398+
399+
function reverseState(helloWorld) {
400+
computeStateCalledCounter++;
401+
return helloWorld.split("").reverse().join("");
402+
}
403+
404+
var getReverseState = Reselect.createSelector(
405+
helloWorldSelector, reverseState
406+
)
407+
408+
var mapStateToAttributes = {
409+
"v.message": getReverseState
410+
};
411+
412+
redux.connect(mapStateToAttributes, component);
413+
414+
expect(computeStateCalledCounter).toBe(1);
415+
416+
component.dispatch({
417+
type: "INCREMENT"
418+
});
419+
420+
expect(computeStateCalledCounter).toBe(1);
421+
422+
component.dispatch({
423+
type: "JOHN"
424+
});
425+
426+
expect(computeStateCalledCounter).toBe(2);
427+
428+
done();
429+
}).catch(function(e) {
430+
done.fail(e);
431+
});
432+
});
433+
});
316434
});

0 commit comments

Comments
 (0)