Skip to content

Commit 0f010a7

Browse files
authored
Merge pull request #307 from Code102SoftwareProject/dev
Dev
2 parents a456056 + 909c8b5 commit 0f010a7

56 files changed

Lines changed: 5117 additions & 4725 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/badge-assignment.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: CI - Build and Test
2+
3+
on:
4+
# Trigger on pull requests to main branch
5+
pull_request:
6+
branches: [ main, master ]
7+
8+
# Trigger on pushes to main branch (merges)
9+
push:
10+
branches: [ main, master ]
11+
12+
# Allow manual trigger
13+
workflow_dispatch:
14+
15+
jobs:
16+
build-and-test:
17+
runs-on: ubuntu-latest
18+
19+
strategy:
20+
matrix:
21+
node-version: [18.x, 20.x]
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Setup Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
cache: 'npm'
32+
33+
- name: Install dependencies
34+
run: npm ci
35+
36+
- name: Run tests
37+
run: npm test
38+
continue-on-error: false
39+
env:
40+
CI: true
41+
42+
- name: Build application
43+
run: npm run build
44+
continue-on-error: false
45+
env:
46+
CI: true
47+
48+
- name: Check build output
49+
run: |
50+
if [ ! -d ".next" ]; then
51+
echo "Build failed - .next directory not found"
52+
exit 1
53+
fi
54+
echo "Build successful - .next directory exists"
55+
56+
- name: Upload build artifacts (on failure)
57+
if: failure()
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: build-logs-${{ matrix.node-version }}
61+
path: |
62+
.next/
63+
npm-debug.log*
64+
yarn-debug.log*
65+
yarn-error.log*
66+
retention-days: 5
67+
68+
# Additional job for documentation build (if needed)
69+
build-docs:
70+
runs-on: ubuntu-latest
71+
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
72+
73+
steps:
74+
- name: Checkout code
75+
uses: actions/checkout@v4
76+
77+
- name: Setup Node.js
78+
uses: actions/setup-node@v4
79+
with:
80+
node-version: '20.x'
81+
cache: 'npm'
82+
83+
- name: Install main dependencies
84+
run: npm ci
85+
86+
- name: Install documentation dependencies
87+
run: |
88+
cd documentation
89+
npm ci
90+
91+
- name: Build documentation
92+
run: |
93+
cd documentation
94+
npm run build
95+
continue-on-error: false
96+
97+
# Security and quality checks
98+
security-audit:
99+
runs-on: ubuntu-latest
100+
101+
steps:
102+
- name: Checkout code
103+
uses: actions/checkout@v4
104+
105+
- name: Setup Node.js
106+
uses: actions/setup-node@v4
107+
with:
108+
node-version: '20.x'
109+
cache: 'npm'
110+
111+
- name: Install dependencies
112+
run: npm ci
113+
114+
- name: Run security audit
115+
run: npm audit --audit-level=high
116+
continue-on-error: true
117+
118+
- name: Check for outdated packages
119+
run: npm outdated || true
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: PR Quality Check
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
issues: write
11+
12+
jobs:
13+
quick-check:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '20.x'
24+
cache: 'npm'
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Build check
30+
run: npm run build
31+
env:
32+
CI: true
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import UserDashboardContent from '@/components/User/DashboardContent/UserDashboardContent';
4+
import { useAuth } from '@/lib/context/AuthContext';
5+
import { useSessionTimer } from '@/lib/hooks/useSessionTimer';
6+
7+
8+
// Mock child components
9+
jest.mock('@/components/Dashboard/UserSkills', () => {
10+
const MockUserSkills = () => <div data-testid="UserSkills" />;
11+
MockUserSkills.displayName = 'MockUserSkills';
12+
return MockUserSkills;
13+
});
14+
jest.mock('@/components/Dashboard/SkillsRequested', () => ({
15+
SkillsRequested: () => <div data-testid="SkillsRequested" />,
16+
SkillsOffered: () => <div data-testid="SkillsOffered" />
17+
}));
18+
jest.mock('@/components/Dashboard/ReviewSummary', () => ({
19+
ReviewSummary: () => <div data-testid="ReviewSummary" />
20+
}));
21+
jest.mock('@/components/Dashboard/EarnedBadges', () => {
22+
const MockEarnedBadges = () => <div data-testid="EarnedBadges" />;
23+
MockEarnedBadges.displayName = 'MockEarnedBadges';
24+
return MockEarnedBadges;
25+
});
26+
27+
jest.mock('@/components/Dashboard/ProfileCard', () => {
28+
const MockProfileCard = () => <div data-testid="ProfileCard" />;
29+
MockProfileCard.displayName = 'MockProfileCard';
30+
return MockProfileCard;
31+
});
32+
jest.mock('@/components/Dashboard/TimeSpentChart', () => ({
33+
TimeSpentChart: () => <div data-testid="TimeSpentChart" />
34+
}));
35+
jest.mock('@/components/Dashboard/SkillMatchOverview', () => {
36+
const MockSkillMatchOverview = () => <div data-testid="SkillMatchOverview" />;
37+
MockSkillMatchOverview.displayName = 'MockSkillMatchOverview';
38+
return MockSkillMatchOverview;
39+
});
40+
41+
// Mock hooks
42+
jest.mock('@/lib/context/AuthContext', () => ({
43+
useAuth: jest.fn()
44+
}));
45+
jest.mock('@/lib/hooks/useSessionTimer', () => ({
46+
useSessionTimer: jest.fn()
47+
}));
48+
49+
describe('UserDashboardContent', () => {
50+
const mockUser = {
51+
_id: '123',
52+
firstName: 'Samha',
53+
lastName: 'fathima'
54+
};
55+
56+
beforeEach(() => {
57+
(useAuth as jest.Mock).mockReturnValue({ user: mockUser });
58+
(useSessionTimer as jest.Mock).mockReturnValue(null);
59+
});
60+
61+
it('renders greeting with user full name', () => {
62+
render(
63+
<UserDashboardContent
64+
onNavigateToMySkills={jest.fn()}
65+
onNavigateToReviews={jest.fn()}
66+
/>
67+
);
68+
69+
expect(screen.getByText(/Hi Samha fathima, Welcome back!/i)).toBeInTheDocument();
70+
});
71+
72+
it('renders all child components when user is present', () => {
73+
render(
74+
<UserDashboardContent
75+
onNavigateToMySkills={jest.fn()}
76+
onNavigateToReviews={jest.fn()}
77+
/>
78+
);
79+
80+
expect(screen.getByTestId('UserSkills')).toBeInTheDocument();
81+
expect(screen.getByTestId('SkillsRequested')).toBeInTheDocument();
82+
expect(screen.getByTestId('SkillsOffered')).toBeInTheDocument();
83+
expect(screen.getByTestId('ReviewSummary')).toBeInTheDocument();
84+
expect(screen.getByTestId('EarnedBadges')).toBeInTheDocument();
85+
expect(screen.getByTestId('ProfileCard')).toBeInTheDocument();
86+
expect(screen.getByTestId('TimeSpentChart')).toBeInTheDocument();
87+
expect(screen.getByTestId('SkillMatchOverview')).toBeInTheDocument();
88+
});
89+
});

0 commit comments

Comments
 (0)