Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 29 additions & 0 deletions .github/workflows/pr-agent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PR Agent

on:
pull_request_target:
types: [opened, synchronize, reopened]
workflow_dispatch:

permissions:
contents: read
pull-requests: write

jobs:
pr_agent:
runs-on: ubuntu-latest
steps:
- name: Run PR Agent
uses: qodo-ai/pr-agent@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_KEY: ${{ secrets.OPENAI_API_KEY }}
# Enable summary comments on PRs
PR_SUMMARIZER: true
# Optionally enable full reviews/checklists. Set to true if desired.
PR_REVIEWER: false
# Optional: model/provider tuning (defaults work fine)
# OPENAI_API_BASE: ${{ secrets.OPENAI_API_BASE }}
# OPENAI_MODEL: gpt-4o-mini


12 changes: 7 additions & 5 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';

// Mock App to avoid heavy imports (firebase, crypto libs) during unit tests
jest.mock('./App', () => () => <div>App</div>);
import App from './App';

test('renders learn react link', () => {
const { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
test('renders App mock', () => {
render(<App />);
expect(screen.getByText('App')).toBeInTheDocument();
});
33 changes: 33 additions & 0 deletions src/components/login/__tests__/GAuthTwoFAFormLogin.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import GAuthTwoFAFormLogin from '../GAuthTwoFAFormLogin';

describe('GAuthTwoFAFormLogin', () => {
test('shows validation error on empty submit', async () => {
const userSignInGAuth = jest.fn();
render(<GAuthTwoFAFormLogin userSignInGAuth={userSignInGAuth} />);

userEvent.click(screen.getByText(/Verify/i));

expect(await screen.findByText(/verification code is required/i)).toBeInTheDocument();
expect(userSignInGAuth).not.toHaveBeenCalled();
});

test('submits gAuth code value', (done) => {
const userSignInGAuth = jest.fn();
render(<GAuthTwoFAFormLogin userSignInGAuth={userSignInGAuth} />);

userEvent.type(screen.getByLabelText(/Insert the code from google authenticator/i), '654321');

userEvent.click(screen.getByText(/Verify/i));

setTimeout(() => {
expect(userSignInGAuth).toHaveBeenCalledTimes(1);
expect(userSignInGAuth.mock.calls[0][0]).toEqual({ gAuthCode: '654321' });
done();
}, 0);
});
});


48 changes: 48 additions & 0 deletions src/components/login/__tests__/LoginForm.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import LoginForm from '../LoginForm';

// shared user-context mock imported above

describe('LoginForm', () => {
test('renders inputs and enables submit after reCAPTCHA mock callback', () => {
const onLogin = jest.fn();
render(<LoginForm onLogin={onLogin} submitting={false} />);

// Inputs present
expect(screen.getByPlaceholderText(/Email/i)).toBeInTheDocument();
expect(screen.getByPlaceholderText(/Password/i)).toBeInTheDocument();

const submitButton = screen.getByText(/Login/i);
expect(submitButton).toBeEnabled();
});

test('validates and submits with email/password', (done) => {
const onLogin = jest.fn();
render(<LoginForm onLogin={onLogin} submitting={false} />);

userEvent.type(screen.getByPlaceholderText(/Email/i), 'user@example.com');
userEvent.type(screen.getByPlaceholderText(/Password/i), 'secret');

userEvent.click(screen.getByText(/Login/i));

setTimeout(() => {
expect(onLogin).toHaveBeenCalledTimes(1);
expect(onLogin.mock.calls[0][0]).toEqual({
email: 'user@example.com',
password: 'secret'
});
done();
}, 0);
});

test('disables submit when submitting prop is true', () => {
const onLogin = jest.fn();
render(<LoginForm onLogin={onLogin} submitting={true} />);
const submitButton = screen.getByText(/Login/i);
expect(submitButton).toBeDisabled();
});
});


36 changes: 36 additions & 0 deletions src/components/login/__tests__/SMSTwoFAFormLogin.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import SMSTwoFAFormLogin from '../SMSTwoFAFormLogin';

// shared user-context mock imported above

describe('SMSTwoFAFormLogin', () => {
test('shows validation error on empty submit', async () => {
const userSignInSms = jest.fn();
render(<SMSTwoFAFormLogin userSignInSms={userSignInSms} />);

userEvent.click(screen.getByText(/Verify/i));

// Error message from yup
expect(await screen.findByText(/verification code is required/i)).toBeInTheDocument();
expect(userSignInSms).not.toHaveBeenCalled();
});

test('submits phone code value', (done) => {
const userSignInSms = jest.fn();
render(<SMSTwoFAFormLogin userSignInSms={userSignInSms} />);

userEvent.type(screen.getByLabelText(/Insert the code sent to your phone/i), '123456');

userEvent.click(screen.getByText(/Verify/i));

setTimeout(() => {
expect(userSignInSms).toHaveBeenCalledTimes(1);
expect(userSignInSms.mock.calls[0][0]).toEqual({ phoneCode: '123456' });
done();
}, 0);
});
});


25 changes: 25 additions & 0 deletions src/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,28 @@
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';
import './test/setup-user-context-mock';

// Polyfill TextEncoder/TextDecoder for libs used in tests
try {
const { TextEncoder, TextDecoder } = require('util');
if (!global.TextEncoder) {
global.TextEncoder = TextEncoder;
}
if (!global.TextDecoder) {
global.TextDecoder = TextDecoder;
}
} catch (e) {
// ignore if not available
}

// Stub getComputedStyle to avoid jsdom not-implemented warnings from a11y queries
if (typeof window !== 'undefined' && typeof window.getComputedStyle !== 'function') {
window.getComputedStyle = () => ({
getPropertyValue: () => '',
display: 'block',
appearance: '',
'-moz-appearance': '',
'-webkit-appearance': ''
});
}
15 changes: 15 additions & 0 deletions src/test/setup-user-context-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Shared mock for user-context used across tests
jest.mock('../context/user-context', () => ({
useUser: () => ({
firebase: {
newRecaptchaVerifier: jest.fn((id, config) => {
if (config && typeof config.callback === 'function') {
config.callback();
}
return { render: jest.fn() };
})
}
})
}));