-
-
Save apark0720/28d0a5c07d39b45604ae5e3bfddf5ca0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const actionTypes = { | |
ADD_ASSERTION: 'ADD_ASSERTION', | |
DELETE_ASSERTION: 'DELETE_ASSERTION', | |
}; | |
export const addAction = () => ({ | |
type: actionTypes.ADD_ACTION, | |
}); | |
export const deleteAction = id => ({ | |
type: actionTypes.DELETE_ACTION, | |
id, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createContext } from 'react'; | |
import { actionTypes } from './testCaseActions'; | |
export const TestCaseContext = createContext(null); | |
export const testCaseState = { | |
testStatement: '', | |
statements: [ | |
{ | |
id: 0, | |
type: 'render', | |
componentName: '', | |
filePath: '', | |
props: [], | |
hasProp: false, | |
}, | |
{ | |
id: 1, | |
type: 'assertion', | |
queryVariant: '', | |
querySelector: '', | |
queryValue: '', | |
isNot: false, | |
matcherType: '', | |
matcherValue: '', | |
suggestions: [], | |
}, | |
], | |
}; | |
let statementId = 2; | |
const createAssertion = () => ({ | |
id: statementId++, | |
type: 'assertion', | |
queryVariant: '', | |
querySelector: '', | |
queryValue: '', | |
isNot: false, | |
matcherType: '', | |
matcherValue: '', | |
suggestions: [], | |
}); | |
export const testCaseReducer = (state, action) => { | |
Object.freeze(state); | |
let statements = [...state.statements]; | |
let lastAssertionStatement; | |
switch (action.type) { | |
case actionTypes.ADD_ASSERTION: | |
lastAssertionStatement = statements.pop(); | |
statements.push(createAssertion(), lastAssertionStatement); | |
return { | |
...state, | |
statements, | |
}; | |
case actionTypes.DELETE_ASSERTION: | |
lastAssertionStatement = statements.pop(); | |
statements = statements.filter(statement => statement.id !== action.id); | |
statements.push(lastAssertionStatement); | |
return { | |
...state, | |
statements, | |
}; | |
default: | |
return state; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment