Skip to content

Commit

Permalink
File tests
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii committed Aug 30, 2024
1 parent c133154 commit 4a96fcd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![npm](https://img.shields.io/npm/v/hyperparam)](https://www.npmjs.com/package/hyperparam)
[![workflow status](https://github.com/hyparam/hyperparam-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/hyparam/hyperparam-cli/actions)
[![mit license](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
![coverage](https://img.shields.io/badge/Coverage-28-darkred)
![coverage](https://img.shields.io/badge/Coverage-37-darkred)

This is the hyperparam cli tool.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@rollup/plugin-typescript": "11.1.6",
"@testing-library/react": "16.0.1",
"@types/node": "22.5.1",
"@types/react": "18.3.4",
"@types/react": "18.3.5",
"@types/react-dom": "18.3.0",
"@typescript-eslint/eslint-plugin": "8.3.0",
"@vitejs/plugin-react": "4.3.1",
Expand Down
34 changes: 34 additions & 0 deletions test/components/File.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { render } from '@testing-library/react'
import React from 'react'
import { describe, expect, it } from 'vitest'
import File from '../../src/components/File.js'

describe('File Component', () => {
it('renders a local file path', () => {
const { getByText } = render(<File file="folder/subfolder/test.txt" />)

expect(getByText('/')).toBeDefined()
expect(getByText('folder/')).toBeDefined()
expect(getByText('subfolder/')).toBeDefined()
expect(getByText('test.txt')).toBeDefined()
})

it('renders a URL', () => {
const url = 'https://example.com/test.txt'
const { getByText } = render(<File file={url} />)

expect(getByText(url)).toBeDefined()
})

it('renders correct breadcrumbs for nested folders', () => {
const { getAllByRole } = render(<File file="folder1/folder2/folder3/test.txt" />)

const links = getAllByRole('link')
expect(links[0].getAttribute('href')).toBe('/')
expect(links[1].getAttribute('href')).toBe('/files')
expect(links[2].getAttribute('href')).toBe('/files?key=folder1/')
expect(links[3].getAttribute('href')).toBe('/files?key=folder1/folder2/')
expect(links[4].getAttribute('href')).toBe('/files?key=folder1/folder2/folder3/')
expect(links[5].getAttribute('href')).toBe('/files?key=folder1/folder2/folder3/test.txt')
})
})

0 comments on commit 4a96fcd

Please sign in to comment.