-
Notifications
You must be signed in to change notification settings - Fork 43
Review and test file system #36
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
edf4839
Test the fs layer and add file versions.
microbit-matt-hillsdon c6a9578
Fix tests.
microbit-matt-hillsdon a485fb7
Interesting cases.
microbit-matt-hillsdon b8f291f
Fix editing of changed modules.
microbit-matt-hillsdon 2de9dd4
Docs/import tidying.
microbit-matt-hillsdon df851a6
This API is clearer with an enum.
microbit-matt-hillsdon 6ebc412
Avoid making `initialize` private for now.
microbit-matt-hillsdon e2e8c64
Fix test compile errors.
microbit-matt-hillsdon 9907c9f
Fix test name
microbit-matt-hillsdon 8bde3f4
Seems to work fine.
microbit-matt-hillsdon a4039dd
Basic error handling here.
microbit-matt-hillsdon 0f24207
More error handling.
microbit-matt-hillsdon 3c33294
Add an upload button.
microbit-matt-hillsdon 32f7276
Fix icon.
microbit-matt-hillsdon 7dcea39
Missing test + fixes.
microbit-matt-hillsdon 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 hidden or 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 hidden or 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,65 @@ | ||
| import { Button, ButtonProps, Input } from "@chakra-ui/react"; | ||
| import React, { useCallback, useRef } from "react"; | ||
| import { RiFolderOpenLine } from "react-icons/ri"; | ||
|
|
||
| interface OpenButtonProps extends ButtonProps { | ||
| onOpen: (file: File) => void; | ||
| /** | ||
| * File input tag accept attribute. | ||
| */ | ||
| accept?: string; | ||
| } | ||
|
|
||
| /** | ||
| * File open button, with an associated input field. | ||
| */ | ||
| const FileInputButton = ({ | ||
| accept, | ||
| onOpen, | ||
| leftIcon = <RiFolderOpenLine />, | ||
| children, | ||
| ...props | ||
| }: OpenButtonProps) => { | ||
| const ref = useRef<HTMLInputElement>(null); | ||
|
|
||
| const handleChooseFile = useCallback(() => { | ||
| ref.current && ref.current.click(); | ||
| }, []); | ||
|
|
||
| const handleOpenFile = useCallback( | ||
| async (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| const files = e.target.files; | ||
| if (files) { | ||
| const file = files.item(0); | ||
| // Clear the input so we're triggered if the user opens the same file again. | ||
| ref.current!.value = ""; | ||
| if (file) { | ||
| onOpen(file); | ||
| } | ||
| } | ||
| }, | ||
| [onOpen] | ||
| ); | ||
|
|
||
| return ( | ||
| <> | ||
| <Input | ||
| data-testid={ | ||
| (props as any)["data-testid"] | ||
| ? (props as any)["data-testid"] + "-input" | ||
| : undefined | ||
| } | ||
| type="file" | ||
| accept={accept} | ||
| display="none" | ||
| onChange={handleOpenFile} | ||
| ref={ref} | ||
| /> | ||
| <Button leftIcon={leftIcon} onClick={handleChooseFile} {...props}> | ||
| {children} | ||
| </Button> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default FileInputButton; |
This file contains hidden or 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 hidden or 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,28 @@ | ||
| import { App } from "./app"; | ||
|
|
||
| describe("Browser - multiple and missing file cases", () => { | ||
| const app = new App(); | ||
| beforeEach(app.reload.bind(app)); | ||
| afterAll(app.dispose.bind(app)); | ||
|
|
||
| it("Copes with hex with no Python files", async () => {}); | ||
|
|
||
| it("Prevents deleting main.py", async () => {}); | ||
|
|
||
| it("Copes with currently open file being updated (module)", async () => { | ||
| await app.open("testData/module.py"); | ||
| await app.switchToEditing("module.py"); | ||
| await app.findVisibleEditorContents(/1.0.0/); | ||
|
|
||
| await app.open("testData/updated/module.py"); | ||
|
|
||
| await app.findVisibleEditorContents(/1.1.0/); | ||
| await app.findVisibleEditorContents(/Now with documentation/); | ||
| }); | ||
|
|
||
| it("Copes with currently open file being deleted", async () => {}); | ||
|
|
||
| it("Doesn't offer editor for non-Python file", async () => {}); | ||
|
|
||
| it("Shows some kind of error for non-UTF-8 main.py", async () => {}); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.