<commit_before>import {ActionDispatcher} from "./action-dispatcher"
import {ICommandStack, CommandStack} from "./command-stack"
import {UndoAction, RedoAction, ActionHandlerRegistry} from "./actions"
import {expect} from 'chai'
import {Command} from "./commands"
import {ContainerModule, Container} from "inversify"
import defaultModule from "../../../src/base/container-module"
import {TYPES} from "../types"
import {SetModelCommand, SetModelAction} from "./model-manipulation"
import {SModel} from "../model/smodel"
import EMPTY_ROOT = SModel.EMPTY_ROOT

describe('action dispatcher', () => {

    let execCount = 0
    let undoCount = 0
    let redoCount = 0

    const mockCommandStack: ICommandStack = {
        execute() { ++execCount },
        undo() { ++undoCount },
        redo() { ++redoCount }
    }

    const module = new ContainerModule((bind, unbind, isBound, rebind) => {
        rebind(TYPES.ICommandStack).toConstantValue(mockCommandStack)
    })

    const container = new Container()
    container.load(defaultModule, module)

    const actionDispatcher = container.get(ActionDispatcher)

    const registry = container.get(ActionHandlerRegistry)
    registry.registerCommand(SetModelAction.KIND, SetModelCommand)
    
    it('undo/redo/execute', () => {
        actionDispatcher.dispatch(new UndoAction)
        expect(execCount).to.be.equal(0)
        expect(undoCount).to.be.equal(1)
        expect(redoCount).to.be.equal(0)
    
        actionDispatcher.dispatch(new RedoAction)
        expect(execCount).to.be.equal(0)
        expect(undoCount).to.be.equal(1)
        expect(redoCount).to.be.equal(1)
    
        actionDispatcher.dispatch({kind: 'unknown'})
        expect(execCount).to.be.equal(0)
        expect(undoCount).to.be.equal(1)
        expect(redoCount).to.be.equal(1)
    
        actionDispatcher.dispatch(new SetModelAction(EMPTY_ROOT))
        expect(execCount).to.be.equal(1)
        expect(undoCount).to.be.equal(1)
        expect(redoCount).to.be.equal(1)
    })
})<commit_msg>[test] improved test<commit_after>import {ActionDispatcher} from "./action-dispatcher"
import {ICommandStack, CommandStack} from "./command-stack"
import {UndoAction, RedoAction, ActionHandlerRegistry} from "./actions"
import {expect} from 'chai'
import {Command} from "./commands"
import {ContainerModule, Container} from "inversify"
import defaultModule from "../../../src/base/container-module"
import {TYPES} from "../types"
import {SetModelCommand, SetModelAction} from "./model-manipulation"
import {MoveCommand, MoveAction} from "./move"
import {SModel} from "../model/smodel"
import EMPTY_ROOT = SModel.EMPTY_ROOT

describe('action dispatcher', () => {

    let execCount = 0
    let undoCount = 0
    let redoCount = 0

    const mockCommandStack: ICommandStack = {
        execute() { ++execCount },
        undo() { ++undoCount },
        redo() { ++redoCount }
    }

    const module = new ContainerModule((bind, unbind, isBound, rebind) => {
        rebind(TYPES.ICommandStack).toConstantValue(mockCommandStack)
    })

    const container = new Container()
    container.load(defaultModule, module)

    const actionDispatcher = container.get(ActionDispatcher)

    it('undo/redo/execute', () => {
        actionDispatcher.dispatch(new UndoAction)
        expect(execCount).to.be.equal(0)
        expect(undoCount).to.be.equal(1)
        expect(redoCount).to.be.equal(0)
    
        actionDispatcher.dispatch(new RedoAction)
        expect(execCount).to.be.equal(0)
        expect(undoCount).to.be.equal(1)
        expect(redoCount).to.be.equal(1)
    
        actionDispatcher.dispatch({kind: 'unknown'})
        expect(execCount).to.be.equal(0)
        expect(undoCount).to.be.equal(1)
        expect(redoCount).to.be.equal(1)

        // SetModelAction is registered by default
        actionDispatcher.dispatch(new SetModelAction(EMPTY_ROOT))
        expect(execCount).to.be.equal(1)
        expect(undoCount).to.be.equal(1)
        expect(redoCount).to.be.equal(1)
    
        // MoveAction is not registered by default
        actionDispatcher.dispatch(new MoveAction([], false))
        expect(execCount).to.be.equal(1)
        expect(undoCount).to.be.equal(1)
        expect(redoCount).to.be.equal(1)

        const registry = container.get(ActionHandlerRegistry)
        registry.registerCommand(MoveAction.KIND, MoveCommand)
    
        actionDispatcher.dispatch(new MoveAction([], false))
        expect(execCount).to.be.equal(2)
        expect(undoCount).to.be.equal(1)
        expect(redoCount).to.be.equal(1)
    })
})
{'fraction_non_alphanumeric': 0.13445561871447312, 'fraction_numerical': 0.007870572802798426, 'mean_word_length': 3.255813953488372, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4145764', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1384, 'n_words': 252}