<commit_before>import '../src/editor/state'
import {state, listen, setState, _reset} from 'lape'

const defaultState = state

// https://facebook.github.io/jest/docs/en/expect.html#content

afterEach(() => {
    _reset()
    setState(defaultState)
})

test('SetState sets the state', done => {
    done()
});<commit_msg>Add example tests for event functions<commit_after>import R from 'ramda'
import { state, listen, setState, _reset } from 'lape'
import '../src/editor/state.js'
import * as events from '../src/editor/events.js'

const defaultState = state

class MockEvent {
    constructor(target) {
        this.target = target
    }

    preventDefault() {
    }
}

afterEach(() => {
    _reset()
    setState(defaultState)
})

test('setState sets the state', done => {
    done()
})

test('CHANGE_STATE_NODE_TITLE changes state node title', () => {
    function createState(stateRef, title) {
        const currentDefinitionId = '7eddd63b'

        return {
            currentDefinitionId,
            definitionList: {
                [currentDefinitionId]: {
                    [stateRef.ref]: {
                        [stateRef.id]: {
                            title,
                            type: 'text',
                        },
                    },
                },
            },
        }
    }

    const stateRef = {
        ref: 'state',
        id: 'd2588376',
    }

    const oldState = createState(stateRef, 'oldTitle')
    setState(oldState)

    const event = new MockEvent({ value: 'newTitle' })
    events.CHANGE_STATE_NODE_TITLE(stateRef, event)

    const expectedState = createState(stateRef, event.target.value)

    expect(state).toEqual(expectedState)
})

test('DELETE_TRANSFORMATION deletes a specific transformation', () => {
    function createState(pipeRef, transformations) {
        const currentDefinitionId = '7eddd63b'

        return {
            currentDefinitionId,
            definitionList: {
                [currentDefinitionId]: {
                    [pipeRef.ref]: {
                        [pipeRef.id]: {
                            transformations,
                            type: 'text',
                        },
                    },
                },
            },
        }
    }

    const pipeRef = {
        ref: 'pipe',
        id: 'd2588376',
    }

    const unneededTransformationRef = {
        ref: 'toUpperCase',
        id: 'daebf1f2',
    }

    const remainingTransformationRef = {
        ref: 'toLowerCase',
        id: '2beee9a4',
    }

    const oldState = createState(pipeRef, [unneededTransformationRef, remainingTransformationRef])
    setState(oldState)

    events.DELETE_TRANSFORMATION(pipeRef, unneededTransformationRef)

    const expectedState = createState(pipeRef, [remainingTransformationRef])

    expect(state).toEqual(expectedState)
})
{'fraction_non_alphanumeric': 0.11271067415730338, 'fraction_numerical': 0.00877808988764045, 'mean_word_length': 1.9250513347022586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 1, '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': '1030992', 'n_tokens_mistral': 822, 'n_tokens_neox': 784, 'n_words': 158}