Skip to content

Commit

Permalink
fix transformConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin-Lin authored and chentsulin committed Aug 18, 2018
1 parent 8d88cc8 commit 6f7ddde
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/__tests__/transformConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ it('should transform catch-all event', () => {
},
};

expect(transformConfig(config, { events: ['OTHER_A', 'OTHER_B'] })).toEqual({
expect(
transformConfig(config, { events: ['SOMETHING', 'OTHER_A', 'OTHER_B'] })
).toEqual({
states: {
a: {
on: {
Expand Down Expand Up @@ -65,13 +67,27 @@ it('should work with hierarchical machines', () => {
},
};

expect(transformConfig(config, { events: ['OTHER_A', 'OTHER_B'] })).toEqual({
expect(
transformConfig(config, {
events: [
'SOMETHING',
'TIMER',
'POWER_OUTAGE',
'PED_COUNTDOWN',
'OTHER_A',
'OTHER_B',
],
})
).toEqual({
key: 'light',
initial: 'green',
states: {
a: {
on: {
SOMETHING: 'somthing',
TIMER: 'other',
POWER_OUTAGE: 'other',
PED_COUNTDOWN: 'other',
OTHER_A: 'other',
OTHER_B: 'other',
},
Expand All @@ -85,13 +101,19 @@ it('should work with hierarchical machines', () => {
states: {
walk: {
on: {
SOMETHING: 'other',
TIMER: 'other',
POWER_OUTAGE: 'other',
PED_COUNTDOWN: 'wait',
OTHER_A: 'other',
OTHER_B: 'other',
},
},
wait: {
on: {
SOMETHING: 'other',
TIMER: 'other',
POWER_OUTAGE: 'other',
PED_COUNTDOWN: 'stop',
OTHER_A: 'other',
OTHER_B: 'other',
Expand Down
2 changes: 1 addition & 1 deletion src/transformConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ function transformStateOn(on, { events }) {
(result, value, key) => {
if (key === '*') {
return {
...result,
...events.reduce(
(acc, curr) => ({
...acc,
[curr]: value,
}),
{}
),
...result,
};
}

Expand Down

0 comments on commit 6f7ddde

Please sign in to comment.