-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
feat(design-system): FileExplorer #15513
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f1a4901
wip: cleaning up the specs list and swapping it to be a filetree
JessicaSachs d1bc1ec
Merge branch 'develop' into feat/spec-list-runner-ct
lmiller1990 032652a
wip: refactor
lmiller1990 4032a76
wip: refactor
lmiller1990 228fe88
wip: work on refactor
lmiller1990 98c62f8
chore: improve types
lmiller1990 e882438
styling
lmiller1990 024ed22
chore: remove all references to Cypress in tree list
lmiller1990 364f937
chore: remove all references to Cypress in tree list
lmiller1990 43070d8
extract spec list component
lmiller1990 7d8a2d3
write some tests
lmiller1990 24985b4
correctly update state
lmiller1990 bbae2dd
chore: refactor
lmiller1990 c36aa44
update test
lmiller1990 6eca2bf
make props optional
lmiller1990 66fdee3
Merge branch 'develop' into feat/spec-list-refactor
JessicaSachs ba6faa3
optimizations
lmiller1990 0713905
add back search
lmiller1990 b44f46f
Merge branch 'feat/spec-list-refactor' of https://github.com/cypress-…
lmiller1990 0dce853
use memo
lmiller1990 50a6525
run spec
lmiller1990 dd9f517
run spec
lmiller1990 5a9f421
fix a11l nav
lmiller1990 83beeac
add tests for spec list a11y nav
lmiller1990 4512aa7
fix tests:
lmiller1990 1a18b70
remove unused
lmiller1990 1d34aa7
update version
lmiller1990 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"watch-ignore": [ | ||
"./test/_test-output", | ||
"node_modules" | ||
], | ||
"require": "ts-node/register", | ||
"exit": true | ||
} |
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,2 @@ | ||
import 'regenerator-runtime/runtime' | ||
import 'cypress-real-events/support' |
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
48 changes: 48 additions & 0 deletions
48
npm/design-system/src/components/FileExplorer/FileExplorer.module.scss
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,48 @@ | ||
@use '../../index.scss' as *; | ||
|
||
.nav { | ||
user-select: none; | ||
white-space: nowrap; | ||
} | ||
|
||
.ul { | ||
margin-block-start: 0; | ||
margin-block-end: 0; | ||
margin-inline-start: 0; | ||
margin-inline-end: 0; | ||
padding-inline-start: 0; | ||
&:before { | ||
display: none; | ||
} | ||
} | ||
|
||
.li.li { | ||
padding-left: 20px; | ||
} | ||
|
||
|
||
.ul, .li { | ||
position: relative; | ||
list-style: none; | ||
font-size: $text-s; | ||
line-height: 1.6; | ||
} | ||
|
||
.a { | ||
position: relative; | ||
color: unset; | ||
text-decoration: none; | ||
display: inline-block; | ||
width: 100%; | ||
&:hover { | ||
cursor: pointer; | ||
} | ||
} | ||
|
||
.ul .ul { | ||
margin-inline-start: $text-xs; | ||
} | ||
|
||
.isSelected, .isSelected:hover { | ||
text-decoration: underline; | ||
} |
130 changes: 130 additions & 0 deletions
130
npm/design-system/src/components/FileExplorer/FileExplorer.spec.tsx
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,130 @@ | ||
import { mount } from '@cypress/react' | ||
import React from 'react' | ||
import { FileExplorer, FileComponentProps, FolderComponentProps } from './FileExplorer' | ||
import { FileNode, makeFileHierarchy, TreeNode } from './helpers/makeFileHierarchy' | ||
|
||
import styles from './FileExplorer.module.scss' | ||
|
||
const specs: Cypress.Cypress['spec'][] = [ | ||
{ | ||
relative: 'foo/bar/foo.spec.js', | ||
absolute: 'Users/code/foo/bar/foo.spec.js', | ||
name: 'foo/bar/foo.spec.js', | ||
}, | ||
{ | ||
relative: 'bar/foo.spec.tsx', | ||
absolute: 'bar/foo.spec.tsx', | ||
name: 'bar/foo.spec.tsx', | ||
}, | ||
{ | ||
relative: 'merp/map.spec.ts', | ||
absolute: 'merp/map.spec.ts', | ||
name: 'merp/map.spec.ts', | ||
}, | ||
] | ||
|
||
interface FileExplorerTestProps { | ||
clickFileStub: typeof cy.stub | ||
clickFolderStub: typeof cy.stub | ||
} | ||
|
||
function createFileExplorer (testProps: FileExplorerTestProps): React.FC { | ||
return () => { | ||
const [selectedFile, setSelectedFile] = React.useState<string>() | ||
|
||
const onFileClick = (file: FileNode) => { | ||
setSelectedFile(file.absolute) | ||
} | ||
|
||
const files = makeFileHierarchy(specs.map((spec) => spec.relative)) | ||
|
||
const FileComponent: React.FC<FileComponentProps> = (props) => { | ||
return ( | ||
<div onClick={() => { | ||
testProps.clickFileStub(props.item) | ||
props.onClick(props.item) | ||
}}> | ||
{props.item.name} | ||
</div> | ||
) | ||
} | ||
|
||
const FolderComponent: React.FC<FolderComponentProps> = (props) => { | ||
return ( | ||
<div onClick={() => { | ||
testProps.clickFolderStub() | ||
props.onClick() | ||
}}> | ||
{props.item.name} | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<FileExplorer | ||
files={files} | ||
cssModule={styles} | ||
selectedFile={selectedFile} | ||
fileComponent={FileComponent} | ||
folderComponent={FolderComponent} | ||
onFileClick={onFileClick} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
describe('FileExplorer', () => { | ||
it('basic usage', () => { | ||
const files: TreeNode[] = [ | ||
{ | ||
type: 'folder', | ||
name: 'foo', | ||
absolute: 'foo', | ||
files: [ | ||
{ | ||
type: 'file', | ||
name: 'bar.js', | ||
absolute: 'foo/bar.js', | ||
}, | ||
], | ||
}, | ||
] | ||
|
||
const FileComponent: React.FC<FileComponentProps> = (props) => <div>{props.item.name}</div> | ||
const FolderComponent: React.FC<FolderComponentProps> = (props) => <div>{props.item.name}</div> | ||
|
||
mount( | ||
<FileExplorer | ||
files={files} | ||
selectedFile={undefined} | ||
fileComponent={FileComponent} | ||
folderComponent={FolderComponent} | ||
onFileClick={() => {}} | ||
/>, | ||
) | ||
}) | ||
|
||
it('clicks file and folders', () => { | ||
const clickFolderStub = cy.stub() | ||
const clickFileStub = cy.stub() | ||
|
||
const Wrapper = createFileExplorer({ | ||
clickFolderStub, | ||
clickFileStub, | ||
}) | ||
|
||
mount(<Wrapper />) | ||
|
||
cy.get('div').contains('bar').click().then(() => { | ||
expect(clickFolderStub).to.have.been.calledWith() | ||
}) | ||
|
||
cy.get('div').contains('map.spec.ts').click().then(() => { | ||
expect(clickFileStub).to.have.been.calledWith({ | ||
type: 'file', | ||
absolute: 'merp/map.spec.ts', | ||
name: 'map.spec.ts', | ||
}) | ||
}) | ||
}) | ||
}) |
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.
In ideal (non-test) usage, these would be statically defined at the module level, rather than inline. Alternatively, they could be memoed.
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.
Yep, this is just for testing purposes. We should make a new component in practice. I'll make this change in the other file where they are declared inline.