Skip to content

Commit

Permalink
Merge branch 'main' into feat/graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
abhayymishraa authored Jan 24, 2025
2 parents 6ee947f + 2f389e4 commit 401419c
Show file tree
Hide file tree
Showing 20 changed files with 1,193 additions and 952 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr-labeler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ jobs:
- uses: actions/labeler@v5
with:
configuration-path: .github/labeler.yml
sync-labels: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ __pycache__
.python-version
.ruff_cache
.vscode
venv/
*.code-workspace
*.local
*.log
Expand Down
96 changes: 48 additions & 48 deletions backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ graphene-django = "^3.2.2"
djlint = "^1.36.4"
isort = "^5.13.2"
pre-commit = "^4.1.0"
ruff = "^0.9.2"
ruff = "^0.9.3"

[tool.poetry.group.test.dependencies]
pytest = "^8.3.4"
Expand Down
55 changes: 55 additions & 0 deletions frontend/__tests__/src/data/mockChapterDetailsData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export const mockChaterDetailsData = {
name: 'OWASP Test Chapter',
suggested_location: 'Test City, Test Country',
region: 'Test Region',
is_active: true,
tags: 'test-tag',
updated_at: 1652129718,
url: 'https://owasp.org/test-chapter',
related_urls: [
'https://discord.com/test',
'https://www.instagram.com/test',
'https://www.linkedin.com/test',
'https://www.youtube.com/test',
'https://twitter.com/test',
'https://meetup.com/test',
],
summary: 'This is a test chapter summary.',
top_contributors: [
{
avatar_url: 'https://example.com/avatar1.jpg',
name: 'Contributor 1',
contributions_count: 10,
},
{
avatar_url: 'https://example.com/avatar2.jpg',
name: 'Contributor 2',
contributions_count: 8,
},
{
avatar_url: 'https://example.com/avatar3.jpg',
name: 'Contributor 3',
contributions_count: 6,
},
{
avatar_url: 'https://example.com/avatar4.jpg',
name: 'Contributor 4',
contributions_count: 4,
},
{
avatar_url: 'https://example.com/avatar5.jpg',
name: 'Contributor 5',
contributions_count: 2,
},
{
avatar_url: 'https://example.com/avatar6.jpg',
name: 'Contributor 6',
contributions_count: 1,
},
{
avatar_url: 'https://example.com/avatar7.jpg',
name: 'Contributor 7',
contributions_count: 1,
},
],
}
77 changes: 60 additions & 17 deletions frontend/__tests__/src/pages/ChapterDetails.test.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { screen, waitFor } from '@testing-library/react'

import { fetchAlgoliaData } from 'api/fetchAlgoliaData'
import { ChapterDetailsPage } from 'pages'
import { render } from 'wrappers/testUtil'
import { mockChaterDetailsData } from '@tests/data/mockChapterDetailsData'
jest.mock('api/fetchAlgoliaData')

import { mockChapterData } from '@tests/data/mockChapterData'

jest.mock('api/fetchAlgoliaData', () => ({
fetchAlgoliaData: jest.fn(),
}))
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: jest.fn(),
useParams: () => ({
chapterKey: 'test-chapter',
}),
}))

describe('ChapterDetailsPage Component', () => {
describe('chapterDetailsPage Component', () => {
beforeEach(() => {
;(fetchAlgoliaData as jest.Mock).mockResolvedValue({
hits: mockChapterData.chapters,
totalPages: 2,
})
;(fetchAlgoliaData as jest.Mock).mockImplementation(() =>
Promise.resolve({
hits: [mockChaterDetailsData],
})
)
})

afterEach(() => {
Expand All @@ -37,18 +36,62 @@ describe('ChapterDetailsPage Component', () => {
test('renders chapter data correctly', async () => {
render(<ChapterDetailsPage />)
await waitFor(() => {
expect(screen.getByText('Chapter 1')).toBeInTheDocument()
expect(screen.getByText('Test City, Test Country')).toBeInTheDocument()
})
expect(screen.getByText('This is a summary of Chapter 1.')).toBeInTheDocument()
const viewButton = screen.getByText('Join')
expect(viewButton).toBeInTheDocument()
expect(screen.getByText('Test Region')).toBeInTheDocument()
expect(screen.getByText('Test-tag')).toBeInTheDocument()
expect(screen.getByText('https://owasp.org/test-chapter')).toBeInTheDocument()
expect(screen.getByText('This is a test chapter summary.')).toBeInTheDocument()
})

test('displays "Chapter not found" when there are no chapters', async () => {
test('displays "No chapters found" when there are no chapters', async () => {
;(fetchAlgoliaData as jest.Mock).mockResolvedValue({ hits: [], totalPages: 0 })
render(<ChapterDetailsPage />)
await waitFor(() => {
expect(screen.getByText('Chapter not found')).toBeInTheDocument()
})
})

test('contributors visibility check', async () => {
render(<ChapterDetailsPage />)
await waitFor(() => {
expect(screen.getByText('Contributor 1')).toBeInTheDocument()
})
expect(screen.queryByText('Contributor 7')).not.toBeInTheDocument()
})

test('renders chapter URL as clickable link', async () => {
render(<ChapterDetailsPage />)

await waitFor(() => {
const link = screen.getByText('https://owasp.org/test-chapter')
expect(link.tagName).toBe('A')
expect(link).toHaveAttribute('href', 'https://owasp.org/test-chapter')
})
})

test('handles contributors with missing names gracefully', async () => {
const chapterDataWithIncompleteContributors = {
...mockChaterDetailsData,
top_contributors: [
{
name: 'user1',
avatar_url: 'https://example.com/avatar1.jpg',
contributions_count: 30,
},
],
}

;(fetchAlgoliaData as jest.Mock).mockImplementation(() =>
Promise.resolve({
hits: [chapterDataWithIncompleteContributors],
})
)

render(<ChapterDetailsPage />)

await waitFor(() => {
expect(screen.getByText('user1')).toBeInTheDocument()
})
})
})
Loading

0 comments on commit 401419c

Please sign in to comment.