Back to Repositories

Testing Level Progression Management in learnGitBranching

This test suite validates the core functionality of the LevelStore component in the learnGitBranching application. It focuses on testing level sequence management, level completion tracking, and reset functionality within the application’s level progression system.

Test Coverage Overview

The test suite provides comprehensive coverage of the LevelStore’s key functionality:

  • Verification of sequence and level mapping integrity
  • Level completion state management
  • Best completion status tracking
  • Level reset functionality
Integration points include the LevelActions module and sequence-to-level mapping system.

Implementation Analysis

The testing approach utilizes Jest’s describe/it pattern for organizing test cases. Each test validates discrete functionality using expect assertions to verify state changes. The implementation leverages the Flux architecture pattern with stores and actions, testing both the state management and action dispatch effects.

Key patterns include:
  • Store state verification
  • Action dispatch testing
  • State reset validation

Technical Details

Testing tools and configuration:

  • Jest testing framework
  • Flux architecture components
  • Module-level imports for store and actions
  • Assertion-based verification

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Isolated test cases for specific functionality
  • Clear test case descriptions
  • State verification before and after actions
  • Comprehensive edge case coverage
  • Proper test cleanup through reset functionality

pcottle/learngitbranching

__tests__/LevelStore.spec.js

            
var LevelActions = require('../src/js/actions/LevelActions');
var LevelStore = require('../src/js/stores/LevelStore');

describe('this store', function() {

  it('has sequences and levels', function() {
    var sequenceMap = LevelStore.getSequenceToLevels();
    Object.keys(sequenceMap).forEach(function(levelSequence) {
      expect(LevelStore.getSequences().indexOf(levelSequence) >= 0)
        .toEqual(true);

      sequenceMap[levelSequence].forEach(function(level) {
        expect(LevelStore.getLevel(level.id)).toEqual(level);
      }.bind(this));
    }.bind(this));
  });

  it('can solve a level and then reset', function() {
    var sequenceMap = LevelStore.getSequenceToLevels();
    var firstLevel = sequenceMap[
      Object.keys(sequenceMap)[0]
    ][0];

    expect(LevelStore.isLevelSolved(firstLevel.id))
      .toEqual(false);
    LevelActions.setLevelSolved(firstLevel.id, false);
    expect(LevelStore.isLevelSolved(firstLevel.id))
      .toEqual(true);
    LevelActions.resetLevelsSolved();
    expect(LevelStore.isLevelSolved(firstLevel.id))
      .toEqual(false);
  });

  it('can solve a level with best status and then reset', function() {
    var sequenceMap = LevelStore.getSequenceToLevels();
    var firstLevel = sequenceMap[
      Object.keys(sequenceMap)[0]
    ][0];
  
    expect(LevelStore.isLevelBest(firstLevel.id))
      .toEqual(false);
    LevelActions.setLevelSolved(firstLevel.id, true);
    expect(LevelStore.isLevelBest(firstLevel.id))
      .toEqual(true);
    LevelActions.resetLevelsSolved();
    expect(LevelStore.isLevelBest(firstLevel.id))
      .toEqual(false);
  });
  

});