generated from rdilweb/template-docusaurus-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from jy95/testing
Testing
- Loading branch information
Showing
35 changed files
with
10,174 additions
and
376 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Tests | ||
on: | ||
push: | ||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v3.3.0 | ||
- name: Set up Node.js ✨ | ||
uses: actions/setup-node@v3.6.0 | ||
with: | ||
node-version: '18.x' | ||
- name: Install 💻 | ||
run: | | ||
npm install | ||
- name: Build 🤖 | ||
run: | | ||
npm run build | ||
- name: Test 🧪 | ||
run: | | ||
npm run test:coverage | ||
- name: Run codacy-coverage-reporter | ||
uses: codacy/codacy-coverage-reporter-action@v1.3.0 | ||
with: | ||
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} | ||
coverage-reports: 'coverage/lcov.info' |
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,25 @@ | ||
import React, { ReactNode } from "react" | ||
|
||
type Props = { | ||
[x: string]: any | ||
children: string | ||
values?: { | ||
[x: string]: ReactNode | ||
} | ||
} | ||
|
||
export default function Translate(props: Props): JSX.Element { | ||
// Return fallback message with basic replacements (what matter is that) | ||
|
||
let replacedString = props.children | ||
if (props.values) { | ||
Object.entries(props.values).forEach(([key, value]) => { | ||
// Well enough for the tests context | ||
replacedString = replacedString.replace( | ||
new RegExp(`{${key}}`), | ||
value as string | ||
) | ||
}) | ||
} | ||
return <>{replacedString}</> | ||
} |
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,13 @@ | ||
import React, { ReactNode } from "react" | ||
|
||
type Props = { | ||
children: ReactNode | ||
} | ||
|
||
export default function CodeBlock({ children }: Props): JSX.Element { | ||
// Keep it simple, as lib is not using advanced feature | ||
let rawString = | ||
typeof children === "string" ? children : JSON.stringify(children) | ||
|
||
return <code>{rawString}</code> | ||
} |
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,17 @@ | ||
import React, { ReactNode } from "react" | ||
|
||
export type Props = { | ||
readonly children: ReactNode | ||
readonly hidden?: boolean | ||
readonly className?: string | ||
readonly default?: boolean | ||
readonly label?: string | ||
} | ||
|
||
export default function TabItem({ children, hidden }: Props): JSX.Element { | ||
return ( | ||
<div role="tabpanel" {...{ hidden }}> | ||
{children} | ||
</div> | ||
) | ||
} |
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,92 @@ | ||
// Dummy mock for the sake Jest doesn't wire internal Docusaurus packages | ||
import React, { ReactElement, ReactNode } from "react" | ||
|
||
interface TabItemProps { | ||
readonly children: ReactNode | ||
readonly value: string | ||
readonly default?: boolean | ||
readonly label?: string | ||
readonly hidden?: boolean | ||
readonly className?: string | ||
readonly attributes?: { [key: string]: unknown } | ||
} | ||
|
||
interface TabValue { | ||
readonly value: string | ||
readonly label?: string | ||
readonly attributes?: { [key: string]: unknown } | ||
readonly default?: boolean | ||
} | ||
|
||
type Props = { | ||
readonly children: | ||
| readonly ReactElement<TabItemProps>[] | ||
| ReactElement<TabItemProps> | ||
readonly defaultValue?: string | null | ||
readonly values?: readonly TabValue[] | ||
} | ||
|
||
export default function Tabs({ | ||
children, | ||
defaultValue, | ||
values, | ||
}: Props): JSX.Element { | ||
// Find out values & label | ||
const items: readonly { | ||
value: string | ||
label?: string | ||
}[] = | ||
values !== undefined | ||
? values | ||
: Array.isArray(children) | ||
? (children as ReactElement<TabItemProps>[]).map((c) => ({ | ||
label: c.props.label, | ||
value: c.props.value, | ||
})) | ||
: [ | ||
{ | ||
label: (children as ReactElement<TabItemProps>).props.label, | ||
value: (children as ReactElement<TabItemProps>).props.value, | ||
}, | ||
] | ||
|
||
const [selectedTab, setSelectedTab] = React.useState( | ||
defaultValue || items[0].value | ||
) | ||
const childrenAsArray: ReactElement<TabItemProps>[] = Array.isArray(children) | ||
? children | ||
: [children] | ||
|
||
return ( | ||
<div className="tabs-container" key={"dummy-key"}> | ||
<ul role="tablist" aria-orientation="horizontal" className="tabs"> | ||
{items.map((item, idx) => { | ||
let isSelected = selectedTab === item.value | ||
return ( | ||
<li | ||
onClick={() => setSelectedTab(item.value)} | ||
tabIndex={isSelected ? 0 : -1} | ||
aria-selected={isSelected} | ||
key={item.value} | ||
> | ||
{item.label || idx} | ||
</li> | ||
) | ||
})} | ||
</ul> | ||
<div> | ||
{childrenAsArray.map((c) => { | ||
return ( | ||
<div | ||
role="tabpanel" | ||
hidden={c.props.value !== selectedTab} | ||
key={c.props.value} | ||
> | ||
{c} | ||
</div> | ||
) | ||
})} | ||
</div> | ||
</div> | ||
) | ||
} |
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 @@ | ||
module.exports = {} |
Oops, something went wrong.