Skip to content

Commit

Permalink
📝 refactor CommitList component and tests; update ESLint rules to all…
Browse files Browse the repository at this point in the history
…ow console logs and 'any' type
  • Loading branch information
Jagoda11 committed Dec 22, 2024
1 parent b60016d commit 8c80142
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
4 changes: 2 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export default [
],
'@typescript-eslint/explicit-module-boundary-types': 'warn', // Ensure functions have explicit return types
'@typescript-eslint/no-unused-vars': 'warn', // Warn about unused variables
'@typescript-eslint/no-explicit-any': 'warn', // Warn about usage of the any type
'no-console': 'warn',
'@typescript-eslint/no-explicit-any': 'off', // Warn about usage of the any type
'no-console': 'off',
'jest/no-disabled-tests': 'warn', // Warn about disabled tests
'jest/no-focused-tests': 'error', // Error on focused tests
'jest/no-identical-title': 'error',
Expand Down
9 changes: 2 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React, { useState, useEffect } from 'react'
import React from 'react'
import { HashRouter as Router, Route, Routes, Link } from 'react-router-dom'
import Auth from './components/Auth'
import Dashboard from './components/Dashboard'
import CommitList from './components/CommitList'
import { fetchUserRepos } from './api/githubApi'

const App: React.FC = () => {
const token = localStorage.getItem('githubToken')
const username = localStorage.getItem('githubUsername') ?? ''

const isLocal = window.location.origin.includes('localhost')
const basename = isLocal ? '/' : '/github-insights-dashboard'
Expand All @@ -27,10 +25,7 @@ const App: React.FC = () => {
) : (
<>
<Route path="/" element={<Dashboard />} />
<Route
path="/commits"
element={<CommitList owner={username} />}
/>
<Route path="/commits" element={<CommitList />} />
</>
)}
</Routes>
Expand Down
28 changes: 3 additions & 25 deletions src/components/CommitList.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { render, screen, fireEvent } from '@testing-library/react'
import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import CommitList from './CommitList'

Expand All @@ -17,30 +17,8 @@ describe('CommitList Component 🎉', () => {
expect(screen.getByPlaceholderText('Search commits')).toBeInTheDocument()
})

it('🖊️ updates the username input value', () => {
it('🔍 renders without crashing', () => {
render(<CommitList />)
const usernameInput = screen.getByPlaceholderText('Enter GitHub username')
fireEvent.change(usernameInput, { target: { value: 'testuser' } })
expect(usernameInput).toHaveValue('testuser')
})

it('🔍 updates the search input value', () => {
render(<CommitList />)
const searchInput = screen.getByPlaceholderText('Search commits')
fireEvent.change(searchInput, { target: { value: 'fix' } })
expect(searchInput).toHaveValue('fix')
})

it('⚠️ displays an error message if no username is entered', () => {
render(<CommitList />)
const usernameInput = screen.getByPlaceholderText('Enter GitHub username')
const searchInput = screen.getByPlaceholderText('Search commits')

fireEvent.change(usernameInput, { target: { value: '' } })
fireEvent.change(searchInput, { target: { value: 'anything' } })

expect(
screen.queryByText('Error: Invalid username'),
).not.toBeInTheDocument()
expect(screen.getByText('Commit List')).toBeInTheDocument()
})
})

0 comments on commit 8c80142

Please sign in to comment.