-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redux logic errors #1954
Merged
outoftime
merged 28 commits into
popcodeorg:master
from
joshling1919:redux-logic-errors
Jan 31, 2020
Merged
Redux logic errors #1954
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4168920
Start migration updateProjectSource saga
joshling1919 c26af06
Update updateProjectSource
joshling1919 fe8d719
Use redux-logic for errors
joshling1919 9bf3a0d
Remove errors sagas unit tests
joshling1919 1227492
Reorganize errors logic
joshling1919 e40ff0f
Start validateProjectOnChange tests
joshling1919 982f9d4
Finish validateProjectOnChange specs
joshling1919 e429d3b
Write test for validateSource helper
joshling1919 7a6faef
Start validateCurrentProject test
joshling1919 4e4e64c
Finish validateProjectOnChange tests
joshling1919 adfd45b
Merge branch 'master' of https://github.com/popcodeorg/popcode into r…
joshling1919 9d7a55c
Refactor validateSource logic tests
joshling1919 1080acb
Lint validateCurrentProject and validateProjectOnChange
joshling1919 33eb932
Improve validateCurrentProject and validateProjectOnChange tests
joshling1919 80cf62f
Ensure that only current validations are dispatched
joshling1919 9a6a751
Merge branch 'master' of https://github.com/popcodeorg/popcode into r…
joshling1919 12b20a0
Merge branch 'master' of https://github.com/popcodeorg/popcode into r…
joshling1919 99c37ca
Lint errors logic
joshling1919 c2be8db
Merge branch 'master' of https://github.com/popcodeorg/popcode into r…
joshling1919 5520295
Start validateProject logic
joshling1919 23c2613
Refactor errors logic to use validateProject
joshling1919 c81b993
Merge branch 'master' of https://github.com/popcodeorg/popcode into r…
joshling1919 c12991d
Run lint
joshling1919 5a567a8
Merge branch 'master' into redux-logic-errors
outoftime 3b666dd
Refactor validateProject
joshling1919 fbe3d0c
Merge branch 'redux-logic-errors' of https://github.com/joshling1919/…
joshling1919 8826d1e
Merge branch 'master' of https://github.com/popcodeorg/popcode into r…
joshling1919 43505c8
Merge branch 'master' into redux-logic-errors
outoftime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
projectRestoredFromLastSession as projectRestoredFromLastSessionAction, | ||
snapshotImported as snapshotImportedAction, | ||
} from '../../actions/clients'; | ||
import {validatedSource} from '../../actions/errors'; | ||
import { | ||
changeCurrentProject as changeCurrentProjectAction, | ||
gistImported as gistImportedAction, | ||
toggleLibrary as toggleLibraryAction, | ||
updateProjectSource as updateProjectSourceAction, | ||
} from '../../actions/projects'; | ||
import validateProject from '../validateProject'; | ||
|
||
import {applyActions, makeTestLogic} from './helpers'; | ||
|
||
import {firebaseProjectFactory} from '@factories/data/firebase'; | ||
import {consoleErrorFactory} from '@factories/validations/errors'; | ||
|
||
jest.mock('../../analyzers'); | ||
|
||
const mockCssValidationErrors = [ | ||
consoleErrorFactory.build({ | ||
text: 'You have a starting { but no ending } to go with it.', | ||
}), | ||
]; | ||
|
||
const mockHtmlValidationErrors = [ | ||
consoleErrorFactory.build({ | ||
text: 'Closing tag missing', | ||
}), | ||
]; | ||
|
||
jest.mock('../../validations', () => ({ | ||
css: jest.fn(() => mockCssValidationErrors), | ||
html: jest.fn(() => mockHtmlValidationErrors), | ||
javascript: jest.fn(() => []), | ||
})); | ||
|
||
const testLogic = makeTestLogic(validateProject); | ||
for (const action of [ | ||
changeCurrentProjectAction, | ||
gistImportedAction, | ||
snapshotImportedAction, | ||
projectRestoredFromLastSessionAction, | ||
toggleLibraryAction, | ||
]) { | ||
test(`validates current project on ${action}`, async () => { | ||
const mockProject = firebaseProjectFactory.build(); | ||
const state = applyActions( | ||
projectRestoredFromLastSessionAction(mockProject), | ||
); | ||
|
||
const dispatch = await testLogic(action(mockProject.projectKey), { | ||
state, | ||
}); | ||
|
||
expect(dispatch).toHaveBeenCalledWith( | ||
validatedSource('html', mockHtmlValidationErrors), | ||
); | ||
expect(dispatch).toHaveBeenCalledWith( | ||
validatedSource('css', mockCssValidationErrors), | ||
); | ||
}); | ||
} | ||
|
||
test('UPDATE_PROJECT_SOURCE should validate newSource', async () => { | ||
const mockProject = firebaseProjectFactory.build(); | ||
const state = applyActions(projectRestoredFromLastSessionAction(mockProject)); | ||
|
||
const dispatch = await testLogic( | ||
updateProjectSourceAction(mockProject.projectKey, 'css', 'div {'), | ||
{state}, | ||
); | ||
|
||
expect(dispatch).toHaveBeenCalledWith( | ||
validatedSource('css', mockCssValidationErrors), | ||
); | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import map from 'lodash-es/map'; | ||
import {createLogic} from 'redux-logic'; | ||
|
||
import {validatedSource} from '../actions/errors'; | ||
import Analyzer from '../analyzers'; | ||
import {getCurrentProject} from '../selectors'; | ||
import retryingFailedImports from '../util/retryingFailedImports'; | ||
|
||
function importValidations() { | ||
return retryingFailedImports(() => | ||
import( | ||
/* webpackChunkName: "mainAsync" */ | ||
'../validations' | ||
), | ||
); | ||
} | ||
|
||
async function validateSource({language, source, projectAttributes}, dispatch) { | ||
const validations = await importValidations(); | ||
const validate = validations[language]; | ||
const validationErrors = await validate(source, projectAttributes); | ||
dispatch(validatedSource(language, validationErrors)); | ||
} | ||
|
||
async function validateSources({sources, projectAttributes}, dispatch) { | ||
const validatePromises = map(Reflect.ownKeys(sources), language => | ||
validateSource( | ||
{ | ||
language, | ||
source: sources[language], | ||
projectAttributes, | ||
}, | ||
dispatch, | ||
), | ||
); | ||
|
||
await Promise.all(validatePromises); | ||
} | ||
|
||
export default createLogic({ | ||
type: [ | ||
'CHANGE_CURRENT_PROJECT', | ||
'GIST_IMPORTED', | ||
'SNAPSHOT_IMPORTED', | ||
'PROJECT_RESTORED_FROM_LAST_SESSION', | ||
'TOGGLE_LIBRARY', | ||
'UPDATE_PROJECT_SOURCE', | ||
], | ||
latest: true, | ||
async process( | ||
{ | ||
getState, | ||
action: { | ||
type, | ||
payload: {language, newValue}, | ||
}, | ||
}, | ||
dispatch, | ||
done, | ||
) { | ||
const state = getState(); | ||
const currentProject = getCurrentProject(state); | ||
const projectAttributes = new Analyzer(currentProject); | ||
|
||
if (type === 'UPDATE_PROJECT_SOURCE') { | ||
await validateSource( | ||
{language, source: newValue, projectAttributes}, | ||
dispatch, | ||
); | ||
} else { | ||
await validateSources( | ||
{sources: currentProject.sources, projectAttributes}, | ||
dispatch, | ||
); | ||
} | ||
|
||
done(); | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely not going to block on this, but a minor improvement here would be to map over
sources
itself, which would give you(source, language)
as the arguments to the iterator.