Skip to content

Add test for subnetwork reducers #42

Open
@nolleto

Description

@nolleto

This issue can ben two PRs but, do the tests first to make sure nothing breaks.
Also, you can use ramda to refactor:

// current
case LOAD_NETWORK: {
  const { subnetworks } = action.payload.state.network;
  return subnetworks || [];
}
// with Ramda
import { path, defaultTo } from 'ramda';

const pathPayloadStateNetwork = path(['payload', 'state', 'network'])
const defaultToEmptyArray = defaultTo([]);

case LOAD_NETWORK: {
  return defaultToEmptyArray(pathPayloadStateNetwork(action))
}
// or
const onLoadNetwork = pipe(pathPayloadStateNetwork, defaultToEmptyArray);
case LOAD_NETWORK: {
  return onLoadNetwork(action)
}

Other details about this reducer:

  • There is a method called colorsNol that should be something like getRandomColor. I believe you can extract this to a new utils like /src/utils/colors or use a package for it. Just to be clear: a super-node is a sub-network that will receive a random color. Yes, I'm awere that super-node is a really bad name but I will change it in another PR.
  • There is a condition that I don't know if is valid: if (nodes && positions) {. This was made because we can receive two different networks: the current format and the old.

networks.zip

In this .zip you can find the two networks. You can move theses networks to a __fixtures__ folder and then use it in your tests.

  • first-version-network.json - the first/legacy version
  • simple-network.json - the current version

Well, thats it 😄

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions