Skip to content

Commit

Permalink
Merge pull request #9 from jy95/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
jy95 authored Feb 7, 2023
2 parents 7200bfd + b36561a commit f66ad08
Show file tree
Hide file tree
Showing 35 changed files with 10,174 additions and 376 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ jobs:
node-version: "lts/*"
- name: Install dependencies 💻
run: npm ci
- name: Build
run: npm run build 🤖
- name: Build 🤖
run: npm run build
- name: Test 🧪
run: npm run test
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
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'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ JSON Schema viewer / editor in Docusaurus v2.
<img src="https://img.shields.io/badge/dynamic/json?style=for-the-badge&logo=meta&color=blueviolet&label=Docusaurus&query=peerDependencies%5B%22%40docusaurus%2Fcore%22%5D&url=https%3A%2F%2Fraw.githubusercontent.com%2Fjy95%2Fdocusaurus-json-schema-plugin%2Fmain%2Fpackage.json" />
<br/><br/>

[![License: AGPL v3](https://img.shields.io/badge/License-AGPL_v3-blue.svg)](https://github.com/jy95/docusaurus-json-schema-plugin/blob/main/LICENSE) [![npm latest package](https://img.shields.io/npm/v/docusaurus-json-schema-plugin/latest.svg)] [![npm downloads](https://img.shields.io/npm/dm/docusaurus-json-schema-plugin.svg)] [![Codacy Badge](https://app.codacy.com/project/badge/Grade/43d9fa27054841f5a884afc88188ef01)](https://www.codacy.com/gh/jy95/docusaurus-json-schema-plugin/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=jy95/docusaurus-json-schema-plugin&amp;utm_campaign=Badge_Grade) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/jy95/docusaurus-json-schema-plugin/blob/main/CONTRIBUTING.md) [![prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) <a href="https://www.buymeacoffee.com/GPFR" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="41" width="174" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;" ></a>
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL_v3-blue.svg)](https://github.com/jy95/docusaurus-json-schema-plugin/blob/main/LICENSE) [![npm latest package](https://img.shields.io/npm/v/docusaurus-json-schema-plugin/latest.svg)] [![npm downloads](https://img.shields.io/npm/dm/docusaurus-json-schema-plugin.svg)] [![Codacy Badge](https://app.codacy.com/project/badge/Grade/43d9fa27054841f5a884afc88188ef01)](https://www.codacy.com/gh/jy95/docusaurus-json-schema-plugin/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=jy95/docusaurus-json-schema-plugin&amp;utm_campaign=Badge_Grade) [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/43d9fa27054841f5a884afc88188ef01)](https://www.codacy.com/gh/jy95/docusaurus-json-schema-plugin/dashboard?utm_source=github.com&utm_medium=referral&utm_content=jy95/docusaurus-json-schema-plugin&utm_campaign=Badge_Coverage) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/jy95/docusaurus-json-schema-plugin/blob/main/CONTRIBUTING.md) [![prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) <a href="https://www.buymeacoffee.com/GPFR" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="41" width="174" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;" ></a>
<br />

</div>
Expand Down
25 changes: 25 additions & 0 deletions __mocks__/@docusaurus/Translate.tsx
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}</>
}
13 changes: 13 additions & 0 deletions __mocks__/@theme-original/CodeBlock.tsx
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>
}
17 changes: 17 additions & 0 deletions __mocks__/@theme-original/TabItem.tsx
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>
)
}
92 changes: 92 additions & 0 deletions __mocks__/@theme-original/Tabs.tsx
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>
)
}
1 change: 1 addition & 0 deletions __mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
Loading

0 comments on commit f66ad08

Please sign in to comment.