-
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.
- Loading branch information
1 parent
b1fdf18
commit 380886a
Showing
16 changed files
with
3,289 additions
and
73 deletions.
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
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,168 @@ | ||
/* eslint-disable react/display-name */ | ||
/** @jsx jsx */ | ||
import { FC, useMemo, useCallback } from 'react'; | ||
import { jsx } from 'theme-ui'; | ||
import { Column } from 'react-table'; | ||
import AnsiUp from 'ansi_up'; | ||
|
||
import { Table, TableProps } from '@component-controls/components'; | ||
import { JestResult, Component } from '@component-controls/core'; | ||
|
||
type TestRow = { id: number } & Pick< | ||
JestResult, | ||
'leaks' | 'perfStats' | 'testFilePath' | ||
> & | ||
JestResult['testResults'][number]; | ||
export type BaseComponentTestsProps = { | ||
component?: Component; | ||
pagination?: TableProps<TestRow>['pagination']; | ||
}; | ||
|
||
/** | ||
* Displays commit history for a component | ||
*/ | ||
export const BaseComponentTests: FC<BaseComponentTestsProps> = ({ | ||
component, | ||
pagination = true, | ||
}) => { | ||
const ansi_up = useMemo(() => new AnsiUp(), []); | ||
|
||
console.log(component?.jest); | ||
const renderRowSubComponent = useCallback( | ||
({ row }) => { | ||
const errors = row.original.failureDetails.map( | ||
( | ||
failure: { | ||
message: string; | ||
}, | ||
index: number, | ||
) => ( | ||
<code key={`error_msg_${index}`}> | ||
<div | ||
style={{ padding: '10px' }} | ||
dangerouslySetInnerHTML={{ | ||
__html: ansi_up | ||
.ansi_to_html(failure.message) | ||
.replace(/\n/gi, '<div />'), | ||
}} | ||
/> | ||
</code> | ||
), | ||
); | ||
|
||
return ( | ||
<div> | ||
<div>{errors}</div> | ||
</div> | ||
); | ||
}, | ||
[ansi_up], | ||
); | ||
const columns = useMemo( | ||
() => | ||
[ | ||
{ | ||
Header: () => null, | ||
id: 'expander', | ||
Cell: ({ row }: { row: any }) => { | ||
if (row.original.failureDetails.length) { | ||
return ( | ||
<span {...row.getToggleRowExpandedProps()}> | ||
{row.isExpanded ? '👇' : '👉'} | ||
</span> | ||
); | ||
} | ||
return null; | ||
}, | ||
}, | ||
{ | ||
Header: '#', | ||
accessor: 'id', | ||
Cell: ({ | ||
row: { | ||
original: { id }, | ||
}, | ||
}) => <span>{id}</span>, | ||
}, | ||
{ | ||
Header: 'Test file', | ||
accessor: 'testFilePath', | ||
Cell: ({ | ||
row: { | ||
original: { testFilePath }, | ||
}, | ||
}) => { | ||
return ( | ||
<div> | ||
<div>{testFilePath}</div> | ||
</div> | ||
); | ||
}, | ||
}, | ||
{ | ||
Header: 'Full name', | ||
accessor: 'fullName', | ||
Cell: ({ | ||
row: { | ||
original: { fullName }, | ||
}, | ||
}) => <span sx={{ mr: 1 }}>{fullName}</span>, | ||
}, | ||
{ | ||
Header: 'Title', | ||
accessor: 'title', | ||
Cell: ({ | ||
row: { | ||
original: { title }, | ||
}, | ||
}) => <span>{title}</span>, | ||
}, | ||
{ | ||
Header: 'Status', | ||
accessor: 'status', | ||
Cell: ({ | ||
row: { | ||
original: { status }, | ||
}, | ||
}) => { | ||
return <span>{status}</span>; | ||
}, | ||
}, | ||
] as Column<TestRow>[], | ||
[], | ||
); | ||
|
||
if (!component?.jest) { | ||
return null; | ||
} | ||
|
||
const data: TestRow[] | undefined = component?.jest?.results.reduce( | ||
(acc: TestRow[], { testResults, ...rest }) => { | ||
return [ | ||
...acc, | ||
...testResults.map((r, rowNum) => ({ | ||
id: acc.length + rowNum, | ||
...rest, | ||
...r, | ||
})), | ||
]; | ||
}, | ||
[], | ||
); | ||
|
||
return ( | ||
<Table<TestRow> | ||
sorting={true} | ||
data={data} | ||
columns={columns} | ||
sortBy={[ | ||
{ | ||
id: 'id', | ||
desc: false, | ||
}, | ||
]} | ||
renderRowSubComponent={renderRowSubComponent} | ||
pagination={pagination} | ||
/> | ||
); | ||
}; |
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,20 @@ | ||
import React from 'react'; | ||
import { Document, Example } from '@component-controls/core'; | ||
import { ComponentTests, ComponentTestsProps } from './ComponentTests'; | ||
import { makeDecorators } from '../test/MockContext'; | ||
|
||
export default { | ||
title: 'Blocks/ComponentTests', | ||
component: ComponentTests, | ||
category: ' Component', | ||
decorators: makeDecorators('blocks-core-story-plain--controls'), | ||
} as Document; | ||
|
||
export const overview: Example = () => <ComponentTests id="." name="Commits" />; | ||
|
||
export const pagination: Example<ComponentTestsProps['pagination']> = props => ( | ||
<ComponentTests id="." name="Tests" pagination={props} /> | ||
); | ||
|
||
pagination.smartControls = { smart: false }; | ||
pagination.controls = { pageSize: 10, pageVisible: true }; |
Oops, something went wrong.