Skip to content

Feature/add missing unit tests #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3c7f1e8
feat: Add comprehensive unit tests for utils/searchBar.ts - 24/28 tes…
Jordan231111 May 22, 2025
5e1a15f
fix: Complete searchBar unit tests - all 28 tests now passing
Jordan231111 May 22, 2025
e2aea05
feat: Add unit tests for announcements API route - 6/10 tests passing
Jordan231111 May 22, 2025
c1cac66
feat: Update package dependencies and enhance footer component stylin…
Jordan231111 May 23, 2025
fe80fd7
refactor: Rename backendAnnouncements function to BackendAnnouncement…
Jordan231111 May 23, 2025
add049a
fix: Update sponsor link to use dynamic URL from sponsor data
Jordan231111 May 23, 2025
160459a
fix: Correct background image syntax in sponsors component for consis…
Jordan231111 May 23, 2025
bc53319
chore: Update GitHub Actions workflow to allow empty commits on non-m…
Jordan231111 May 23, 2025
2c1cb61
Update sponsors.tsx
Jordan231111 May 23, 2025
406aa72
Update sponsors.tsx
Jordan231111 May 23, 2025
f0e96d7
Configure jsxSingleQuote in Prettier
Jordan231111 May 23, 2025
1c796ba
Fix: Ensure double quotes in sponsors.tsx style prop
Jordan231111 May 23, 2025
b9d73b5
chore: Update Prettier action version and simplify options in GitHub …
Jordan231111 May 23, 2025
f429199
chore: Update Prettier options in GitHub Actions workflow to respect …
Jordan231111 May 23, 2025
3d54a4d
chore: Add jsxSingleQuote option to Prettier configuration and update…
Jordan231111 May 23, 2025
8e44680
chore: Update .gitignore to include repomix output files
Jordan231111 May 23, 2025
8b09c49
chore: Remove repomix-output.xml and repomix.config.json files as par…
Jordan231111 May 23, 2025
628679d
fix: remove template file
Jordan231111 May 24, 2025
fd5bdc9
fix: annoying ahh github CI FINALLY FIXED
Jordan231111 May 24, 2025
e64d2e3
chore: Update dependencies in package-lock.json to latest versions
Jordan231111 May 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 4 additions & 100 deletions .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,105 +48,11 @@ jobs:
- '**/*.{css,scss}'
- 'tailwind.config.{js,ts}'

# Lint and format job
lint:
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'pull_request' }}
# Grant specific permissions needed for lint job
permissions:
checks: write
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Make sure the actual branch is checked out when running on pull requests
ref: ${{ github.head_ref }}
# Full git history is needed for proper linting
fetch-depth: 0

- name: Prettify code
uses: creyD/[email protected]
with:
prettier_options: --write --tab-width=2 --use-tabs .
# Ensure Prettier config is respected or created if missing
prettier_plugins: prettier-plugin-tailwindcss
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: "🧹 Automated code formatting"
# Skip committing on main branch to avoid repository rule violations
same_commit: true
# Only commit changes when not on main branch
commit_options: ${{ github.ref != 'refs/heads/main' && '--no-verify' || '' }}

- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
echo "runner=yarn" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine package manager"
exit 1
fi

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: ${{ steps.detect-package-manager.outputs.manager }}

# Optimized caching strategy
- name: Cache node_modules
uses: actions/cache@v4
id: node-modules-cache
with:
path: node_modules
key: ${{ runner.os }}-${{ steps.detect-package-manager.outputs.manager }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-v2

- name: Install dependencies
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}

- name: Install additional dependencies for linting
run: |
${{ steps.detect-package-manager.outputs.manager }} add --save-dev eslint-plugin-prettier prettier-plugin-tailwindcss

# Enhanced linting strategy - auto-fix but don't fail on warnings
- name: Run ESLint with auto-fix
id: eslint-fix
continue-on-error: true
run: |
echo "Running ESLint with auto-fix..."
${{ steps.detect-package-manager.outputs.runner }} next lint --fix

# Check for errors, but allow warnings
- name: Check for ESLint errors
run: |
echo "Checking for ESLint errors (allowing warnings)..."
${{ steps.detect-package-manager.outputs.runner }} next lint --quiet || {
echo "::error::ESLint found errors that must be fixed. Please review the errors above.";
exit 1;
}

# Report warnings but don't fail the build
- name: Report ESLint warnings
run: |
echo "Checking for ESLint warnings (won't fail build)..."
${{ steps.detect-package-manager.outputs.runner }} next lint || echo "::warning::ESLint found warnings, but continuing build. Please consider fixing these warnings when possible."

# Build job - preserved your logic with optimizations
# Build job
build:
runs-on: ubuntu-latest
needs: [lint]
needs: [changes]
if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'pull_request' }}
timeout-minutes: 15
# Grant specific permissions needed for build job
permissions:
Expand Down Expand Up @@ -179,7 +85,7 @@ jobs:
node-version: "20"
cache: ${{ steps.detect-package-manager.outputs.manager }}

# Reusing improved caching from above
# Optimized caching strategy
- name: Cache node_modules
uses: actions/cache@v4
id: node-modules-cache
Expand All @@ -202,7 +108,6 @@ jobs:
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} --no-audit --force

# Preserved from original workflow
- name: Add Amplify outputs file
run: touch amplify_outputs.json

Expand Down Expand Up @@ -261,7 +166,6 @@ jobs:
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} --no-audit --force

# Added Amplify file creation steps
- name: Add Amplify outputs file
run: touch amplify_outputs.json

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ amplifyconfiguration*
# Additional build caches
.swc/
.turbo/

# repomix
/repomix-output.xml
/repomix.config.json
21 changes: 7 additions & 14 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#!/bin/sh
#. "$(dirname "$0")/_/husky.sh"
# Run TypeScript check (excluding problematic test files)
echo "🧪 Checking TypeScript..."
npx tsc --noEmit

echo "🧪 Running TypeScript type check..."
# Run TypeScript but don't block commit on errors
#npx tsc --noEmit || echo "⚠️ TypeScript check found issues. Consider fixing them, but proceeding with commit."
# Run Prettier + ESLint on staged files
echo "🧹 Formatting and linting staged files..."
npx lint-staged

# Run Prettier to format code
echo "🧹 Running Prettier..."
#npx prettier --write --tab-width=2 --use-tabs .

# Run ESLint but don't block commit on errors
echo "🛠️ Running ESLint..."
#npx next lint --fix || echo "⚠️ ESLint found issues. Consider fixing them, but proceeding with commit."

echo "✅ Pre-commit checks completed! (Warnings were allowed to proceed)"
echo "✅ Pre-commit checks passed!"
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"useTabs": true,
"semi": true,
"singleQuote": false,
"jsxSingleQuote": false,
"trailingComma": "all",
"bracketSpacing": true,
"bracketSameLine": false,
Expand Down
8 changes: 8 additions & 0 deletions __mocks__/jquery-ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Mock implementation of jQuery UI for testing
module.exports = {
ui: {
widgets: {
autocomplete: {},
},
},
};
2 changes: 2 additions & 0 deletions __mocks__/jquery-ui/ui/widgets/autocomplete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Mock implementation of jQuery UI autocomplete widget for testing
module.exports = {};
17 changes: 17 additions & 0 deletions __mocks__/jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Mock implementation of jQuery for testing
const mockAutocomplete = jest.fn();
const mockOn = jest.fn();
const mockVal = jest.fn().mockReturnValue("");

const mockJQuery = jest.fn((selector) => ({
autocomplete: mockAutocomplete,
on: mockOn,
val: mockVal,
}));

// Expose the mock functions for test access
mockJQuery.mockAutocomplete = mockAutocomplete;
mockJQuery.mockOn = mockOn;
mockJQuery.mockVal = mockVal;

module.exports = mockJQuery;
49 changes: 37 additions & 12 deletions __tests__/__mocks__/mockRegistry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,46 @@ export const MockNavBar = ({
/**
* Mock for the Footer component
*/
export const MockFooter = () => {
export function MockFooter() {
return (
<footer data-testid="footer" role="contentinfo" aria-label="Site Footer">
<div data-testid="footer-nav" role="navigation" aria-label="Footer Navigation">
<a href="/privacy" role="link" aria-label="Privacy Policy">
Privacy Policy
</a>
<a href="/terms" role="link" aria-label="Terms of Service">
Terms of Service
</a>
<div className="footer" data-testid="mock-footer">
<div className="flex flex-col items-center justify-center w-full min-h-fit">
<div className="flex flex-col md:flex-row items-start justify-left w-full">
<div className="logo">
<img src="/mock-logo.png" alt="HackRPI Logo" data-testid="footer-logo" />
</div>
<div className="info">
<h2 data-testid="footer-title">
<span className="font-bold">HackRPI</span> Retro V. Modern
</h2>
<div className="address">
<p>Darrin Communications Center @ Rensselaer Polytechnic Institute</p>
<p>110 8th St, Troy, NY 12180</p>
</div>
</div>
<div className="links">
<div className="registration-link">Register Now</div>
<div className="social-links">
<a href="#" aria-label="Discord">
Discord
</a>
<a href="#" aria-label="Twitter">
Twitter
</a>
<a href="#" aria-label="Instagram">
Instagram
</a>
</div>
</div>
</div>
<div className="copyright">
<p>Made with ❤️ by HackRPI.</p>
<p>&copy; 2025 HackRPI</p>
</div>
</div>
<p>© 2025 HackRPI. All rights reserved.</p>
</footer>
</div>
);
};
}

/**
* Mock for the Title component
Expand Down
Loading
Loading