-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the app to keep code history This PR: - Add code history to keep the last N executions - Bump bootstrap version from 4 to 5 - Persist theme selection in local storage - Introduce Modal component
- Loading branch information
Showing
25 changed files
with
427 additions
and
139 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
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,77 @@ | ||
import React from 'react'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { AppContext } from 'context/AppContext'; | ||
import { AppAactions } from 'context/Reducer'; | ||
import HistoryModal from 'components/HistoryModal'; | ||
import * as StorageService from 'services/storage'; | ||
|
||
const getHistorySpy = jest.spyOn(StorageService, 'getHistory'); | ||
const mockHistory = [ | ||
{ | ||
date: 'second', | ||
code: 'const a = 10', | ||
}, | ||
{ | ||
date: 'first', | ||
code: 'const b = 20', | ||
}, | ||
]; | ||
|
||
describe('<HistoryModal />', () => { | ||
const state = { | ||
historyModalShown: true, | ||
} as AppState; | ||
const mockSetState = jest.fn(); | ||
const dispatch = jest.fn(); | ||
|
||
beforeEach(() => { | ||
getHistorySpy.mockReturnValue(mockHistory); | ||
jest.spyOn(React, 'useState').mockReturnValue([0, mockSetState]); | ||
render( | ||
<AppContext.Provider value={{ state, dispatch }}> | ||
<HistoryModal /> | ||
</AppContext.Provider> | ||
); | ||
}); | ||
|
||
afterEach(jest.clearAllMocks); | ||
|
||
it('render history list', () => { | ||
const historyElement = screen.getByTestId('history-accordion'); | ||
expect(historyElement.children.length).toEqual(2); | ||
}); | ||
|
||
it('calls closes the modal on button click', () => { | ||
fireEvent.click(screen.getByTestId('modal-close-btn')); | ||
|
||
expect(dispatch).toHaveBeenCalledWith({ | ||
type: AppAactions.TOGGLE_HISTORY_MODAL, | ||
}); | ||
}); | ||
|
||
describe('when restoring history', () => { | ||
const historyItemIndex = 0; | ||
beforeEach(async () => { | ||
const restoreButtons = await screen.findAllByRole('button', { | ||
name: /Restore/, | ||
}); | ||
fireEvent.click(restoreButtons[historyItemIndex]); | ||
}); | ||
|
||
it('restore history when restore button click', () => { | ||
expect(dispatch).toHaveBeenNthCalledWith(1, { | ||
type: AppAactions.LOAD_CODE_SAMPLE, | ||
payload: { | ||
codeSample: mockHistory[historyItemIndex].code, | ||
codeSampleName: '', | ||
}, | ||
}); | ||
}); | ||
|
||
it('dismiss the modal', () => { | ||
expect(dispatch).toHaveBeenNthCalledWith(2, { | ||
type: AppAactions.TOGGLE_HISTORY_MODAL, | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.