Skip to content

Commit 74f9429

Browse files
committed
test: Refactor archived badge tests for consistency and clarity in RepositoryNode, CardDetailsPage, and RepositoriesCard components
1 parent 27d3ec1 commit 74f9429

File tree

4 files changed

+38
-79
lines changed

4 files changed

+38
-79
lines changed

backend/tests/apps/github/api/internal/nodes/repository_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,22 @@ def test_url_method(self):
207207
def test_is_archived_field_exists(self):
208208
"""Test that is_archived field is exposed in the GraphQL schema."""
209209
field_names = {field.name for field in RepositoryNode.__strawberry_definition__.fields}
210-
assert "is_archived" in field_names, "is_archived field should be exposed in RepositoryNode"
210+
assert "is_archived" in field_names, (
211+
"is_archived field should be exposed in RepositoryNode"
212+
)
211213

212214
def test_is_archived_field_returns_true(self):
213215
"""Test is_archived field returns True for archived repositories."""
214216
mock_repository = Mock()
215217
mock_repository.is_archived = True
216-
218+
217219
# Since is_archived is a direct field mapping, we just verify the mock
218220
assert mock_repository.is_archived is True
219221

220222
def test_is_archived_field_returns_false(self):
221223
"""Test is_archived field returns False for non-archived repositories."""
222224
mock_repository = Mock()
223225
mock_repository.is_archived = False
224-
226+
225227
# Since is_archived is a direct field mapping, we just verify the mock
226228
assert mock_repository.is_archived is False

frontend/__tests__/unit/components/ArchivedBadge.test.tsx

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { faArchive } from '@fortawesome/free-solid-svg-icons'
21
import { render, screen } from '@testing-library/react'
3-
import React from 'react'
42
import ArchivedBadge from 'components/ArchivedBadge'
53

64
jest.mock('@fortawesome/react-fontawesome', () => ({
7-
FontAwesomeIcon: ({ icon, className }: { icon: any; className: string }) => (
5+
FontAwesomeIcon: ({ className }: { className: string }) => (
86
<i data-testid="archive-icon" className={className} />
97
),
108
}))
@@ -13,53 +11,50 @@ describe('ArchivedBadge', () => {
1311
describe('Basic Rendering', () => {
1412
it('renders successfully with default props', () => {
1513
render(<ArchivedBadge />)
16-
14+
1715
expect(screen.getByText('Archived')).toBeInTheDocument()
1816
})
1917

2018
it('displays the archived text', () => {
2119
render(<ArchivedBadge />)
22-
20+
2321
const badge = screen.getByText('Archived')
2422
expect(badge).toBeVisible()
2523
})
2624

2725
it('has the correct tooltip', () => {
2826
render(<ArchivedBadge />)
29-
27+
3028
const badge = screen.getByText('Archived')
31-
expect(badge).toHaveAttribute(
32-
'title',
33-
'This repository has been archived and is read-only'
34-
)
29+
expect(badge).toHaveAttribute('title', 'This repository has been archived and is read-only')
3530
})
3631
})
3732

3833
describe('Size Variants', () => {
3934
it('renders with small size', () => {
4035
render(<ArchivedBadge size="sm" />)
41-
36+
4237
const badge = screen.getByText('Archived')
4338
expect(badge).toHaveClass('px-2', 'py-1', 'text-xs')
4439
})
4540

4641
it('renders with medium size (default)', () => {
4742
render(<ArchivedBadge size="md" />)
48-
43+
4944
const badge = screen.getByText('Archived')
5045
expect(badge).toHaveClass('px-3', 'py-1', 'text-sm')
5146
})
5247

5348
it('renders with large size', () => {
5449
render(<ArchivedBadge size="lg" />)
55-
50+
5651
const badge = screen.getByText('Archived')
5752
expect(badge).toHaveClass('px-4', 'py-2', 'text-base')
5853
})
5954

6055
it('defaults to medium size when size prop is not provided', () => {
6156
render(<ArchivedBadge />)
62-
57+
6358
const badge = screen.getByText('Archived')
6459
expect(badge).toHaveClass('px-3', 'py-1', 'text-sm')
6560
})
@@ -68,28 +63,28 @@ describe('ArchivedBadge', () => {
6863
describe('Icon Display', () => {
6964
it('shows icon by default', () => {
7065
render(<ArchivedBadge />)
71-
66+
7267
const icon = screen.getByTestId('archive-icon')
7368
expect(icon).toBeInTheDocument()
7469
})
7570

7671
it('shows icon when showIcon is true', () => {
7772
render(<ArchivedBadge showIcon={true} />)
78-
73+
7974
const icon = screen.getByTestId('archive-icon')
8075
expect(icon).toBeInTheDocument()
8176
})
8277

8378
it('hides icon when showIcon is false', () => {
8479
render(<ArchivedBadge showIcon={false} />)
85-
80+
8681
const icon = screen.queryByTestId('archive-icon')
8782
expect(icon).not.toBeInTheDocument()
8883
})
8984

9085
it('applies correct icon class', () => {
9186
render(<ArchivedBadge />)
92-
87+
9388
const icon = screen.getByTestId('archive-icon')
9489
expect(icon).toHaveClass('h-3', 'w-3')
9590
})
@@ -98,31 +93,21 @@ describe('ArchivedBadge', () => {
9893
describe('Styling', () => {
9994
it('has correct base styling classes', () => {
10095
render(<ArchivedBadge />)
101-
96+
10297
const badge = screen.getByText('Archived')
103-
expect(badge).toHaveClass(
104-
'inline-flex',
105-
'items-center',
106-
'gap-1.5',
107-
'rounded-full',
108-
'border'
109-
)
98+
expect(badge).toHaveClass('inline-flex', 'items-center', 'gap-1.5', 'rounded-full', 'border')
11099
})
111100

112101
it('has correct light mode color classes', () => {
113102
render(<ArchivedBadge />)
114-
103+
115104
const badge = screen.getByText('Archived')
116-
expect(badge).toHaveClass(
117-
'border-yellow-600',
118-
'bg-yellow-50',
119-
'text-yellow-800'
120-
)
105+
expect(badge).toHaveClass('border-yellow-600', 'bg-yellow-50', 'text-yellow-800')
121106
})
122107

123108
it('has correct dark mode color classes', () => {
124109
render(<ArchivedBadge />)
125-
110+
126111
const badge = screen.getByText('Archived')
127112
expect(badge).toHaveClass(
128113
'dark:border-yellow-500',
@@ -133,7 +118,7 @@ describe('ArchivedBadge', () => {
133118

134119
it('has font-medium class', () => {
135120
render(<ArchivedBadge />)
136-
121+
137122
const badge = screen.getByText('Archived')
138123
expect(badge).toHaveClass('font-medium')
139124
})
@@ -142,21 +127,21 @@ describe('ArchivedBadge', () => {
142127
describe('Custom ClassName', () => {
143128
it('applies custom className', () => {
144129
render(<ArchivedBadge className="custom-class" />)
145-
130+
146131
const badge = screen.getByText('Archived')
147132
expect(badge).toHaveClass('custom-class')
148133
})
149134

150135
it('preserves default classes with custom className', () => {
151136
render(<ArchivedBadge className="ml-2" />)
152-
137+
153138
const badge = screen.getByText('Archived')
154139
expect(badge).toHaveClass('ml-2', 'inline-flex', 'rounded-full')
155140
})
156141

157142
it('handles empty custom className', () => {
158143
render(<ArchivedBadge className="" />)
159-
144+
160145
const badge = screen.getByText('Archived')
161146
expect(badge).toBeInTheDocument()
162147
})
@@ -165,14 +150,14 @@ describe('ArchivedBadge', () => {
165150
describe('Accessibility', () => {
166151
it('renders as a span element', () => {
167152
render(<ArchivedBadge />)
168-
153+
169154
const badge = screen.getByText('Archived')
170155
expect(badge.tagName).toBe('SPAN')
171156
})
172157

173158
it('has descriptive tooltip for screen readers', () => {
174159
render(<ArchivedBadge />)
175-
160+
176161
const badge = screen.getByText('Archived')
177162
const title = badge.getAttribute('title')
178163
expect(title).toBeTruthy()
@@ -182,22 +167,16 @@ describe('ArchivedBadge', () => {
182167

183168
it('has appropriate semantic structure with icon', () => {
184169
render(<ArchivedBadge />)
185-
170+
186171
const badge = screen.getByText('Archived')
187172
expect(badge).toContainHTML('i')
188173
})
189174
})
190175

191176
describe('Edge Cases', () => {
192177
it('handles all props together', () => {
193-
render(
194-
<ArchivedBadge
195-
size="lg"
196-
showIcon={false}
197-
className="extra-margin"
198-
/>
199-
)
200-
178+
render(<ArchivedBadge size="lg" showIcon={false} className="extra-margin" />)
179+
201180
const badge = screen.getByText('Archived')
202181
expect(badge).toBeInTheDocument()
203182
expect(badge).toHaveClass('px-4', 'py-2', 'text-base', 'extra-margin')
@@ -206,18 +185,18 @@ describe('ArchivedBadge', () => {
206185

207186
it('renders consistently across multiple instances', () => {
208187
const { rerender } = render(<ArchivedBadge />)
209-
188+
210189
const firstRender = screen.getByText('Archived').className
211-
190+
212191
rerender(<ArchivedBadge />)
213-
192+
214193
const secondRender = screen.getByText('Archived').className
215194
expect(firstRender).toBe(secondRender)
216195
})
217196

218197
it('does not render any interactive elements', () => {
219198
const { container } = render(<ArchivedBadge />)
220-
199+
221200
expect(container.querySelector('button')).not.toBeInTheDocument()
222201
expect(container.querySelector('a')).not.toBeInTheDocument()
223202
expect(container.querySelector('input')).not.toBeInTheDocument()

frontend/__tests__/unit/components/CardDetailsPage.test.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,14 +1467,6 @@ describe('CardDetailsPage', () => {
14671467
})
14681468

14691469
it('archived badge renders with medium size', () => {
1470-
const archivedProps = {
1471-
...defaultProps,
1472-
type: 'repository',
1473-
isArchived: true,
1474-
}
1475-
1476-
const { container } = render(<CardDetailsPage {...archivedProps} />)
1477-
14781470
const badge = screen.getByText('Archived')
14791471
expect(badge).toHaveClass('px-3', 'py-1', 'text-sm')
14801472
})
@@ -1483,7 +1475,7 @@ describe('CardDetailsPage', () => {
14831475
const nullArchivedProps = {
14841476
...defaultProps,
14851477
type: 'repository',
1486-
isArchived: null as any,
1478+
isArchived: null,
14871479
}
14881480

14891481
render(<CardDetailsPage {...nullArchivedProps} />)

frontend/__tests__/unit/components/RepositoriesCard.test.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,25 +225,11 @@ describe('RepositoriesCard', () => {
225225
})
226226

227227
it('archived badge has small size on cards', () => {
228-
const archivedRepo: RepositoryCardProps = {
229-
...createMockRepository(0),
230-
isArchived: true,
231-
}
232-
233-
const { container } = render(<RepositoriesCard repositories={[archivedRepo]} />)
234-
235228
const badge = screen.getByText('Archived')
236229
expect(badge).toHaveClass('px-2', 'py-1', 'text-xs')
237230
})
238231

239232
it('archived badge does not show icon on cards', () => {
240-
const archivedRepo: RepositoryCardProps = {
241-
...createMockRepository(0),
242-
isArchived: true,
243-
}
244-
245-
const { container } = render(<RepositoriesCard repositories={[archivedRepo]} />)
246-
247233
const badge = screen.getByText('Archived')
248234
const icon = badge.querySelector('[data-testid="archive-icon"]')
249235
expect(icon).not.toBeInTheDocument()
@@ -278,7 +264,7 @@ describe('RepositoriesCard', () => {
278264
it('handles null isArchived gracefully', () => {
279265
const repo: RepositoryCardProps = {
280266
...createMockRepository(0),
281-
isArchived: null as any,
267+
isArchived: null,
282268
}
283269

284270
render(<RepositoriesCard repositories={[repo]} />)

0 commit comments

Comments
 (0)