Skip to content
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

QA Tests & Docker #52

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
930c51f
Add React as a global variable
jyoonbcit May 15, 2024
dcaeda2
Setup Playwright (#27)
jyoonbcit May 15, 2024
ce7a8dd
Design login tests (#27)
jyoonbcit May 17, 2024
7c4788b
Setup GitHub Actions workflow for testing
jyoonbcit May 17, 2024
4c952bd
Clear comment
jyoonbcit May 22, 2024
d76ca8d
Create basic authentication tests
jyoonbcit May 22, 2024
c3b7803
Merge remote-tracking branch 'origin' into devops/qa-testing
jyoonbcit May 22, 2024
d79988e
Merge branch 'devops/qa-testing' of https://github.com/Vero-Ventures/…
jyoonbcit May 22, 2024
1d0d8e7
Update tests
jyoonbcit May 27, 2024
8bc7a46
Relocate files
jyoonbcit May 27, 2024
5cd9957
Rename file for Jest Playwright
jyoonbcit May 27, 2024
4c14f07
Update testing configurations (#27)
jyoonbcit May 27, 2024
02d225e
Add Jest and code coverage
jyoonbcit May 27, 2024
afd7f65
Ignore nyc output
jyoonbcit May 27, 2024
6141948
Update test directory (#27)
jyoonbcit May 27, 2024
251df30
Add tsx for code coverage (#27)
jyoonbcit May 27, 2024
7437a1c
add @types/jest dependancy (#27)
hiem55 May 27, 2024
bc6b33f
add jest config (#27)
hiem55 May 27, 2024
bf3f44c
lib utils test cases (#27)
hiem55 May 27, 2024
f8ac241
Remove nyc
jyoonbcit May 28, 2024
e3f9e7a
add test cases (#27)
hiem55 May 28, 2024
7922856
Merge remote-tracking branch 'origin/main' into devops/qa-testing
jyoonbcit May 28, 2024
94f6bc7
Merge remote-tracking branch 'origin' into devops/qa-testing
jyoonbcit May 28, 2024
5dd7090
Update dependencies
jyoonbcit May 28, 2024
3bf3a29
Update README.md
jyoonbcit May 30, 2024
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
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"globals": {
"React": "true"
},
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/main.yml → .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,3 @@ jobs:
with:
commit_message: Apply formatting changes
branch: ${{ github.head_ref }}

# - name: Notify failure
# if: failure()
# uses: actions/github-script@v4
# with:
# github-token: ${{ secrets.ACTIONS_TOKEN }}
# script: |
# github.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: 'Formatting failed. Please check the logs.'
# })
29 changes: 29 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test Features
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
format:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-node@v3
with:
node-version: "20.x"

- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ bun.lockb
# virtual environment
venv

# playwright
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright/.auth/

# code coverage
.nyc_output/
# books
src/app/model/books/ALU 101 TEXTBOOK BASIC LIFE INSURANCE UNDERWRITING (Academy of Life Underwriting).pdf
src/app/model/books/ALU 201 Intermediate Medical Life Insurance Underwriting (Academy of Life Underwriting).pdf
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,18 @@ This project aims to develop a custom Large Language Model (LLM) to assist busin

- The development will focus on Python and Typescript.
- Data science, machine learning libraries, and LLM APIs will be used to create the LLM's questioning pipeline and charter compilation functionalities.

## Testing
- Install packages using `npm i`, and run one of the following commands:
- npm run test : Runs Jest unit tests (**Be warned that there may be a bit of lag, as there is an existing bug in the configuration/code**).
- npm run test:e2e : Runs Playwright E2E tests, can use --debug to follow step by step.
- npm run coverage: Runs Jest unit tests with code coverage and creates formatted coverage report in console.

## Pre-commits
- Install the pre-commits locally by installing packages using `npm i`.
- Be warned that if you ignore, uninstall, or forget to install the pre-commit hooks, there is a good chance that the GitHub Actions workflow that runs on push/pull request will fail due to formatting/linting issues you may have failed to notice.

## Docker
- The root directory contains a compose.yaml to build a container running the docker image with the existing Dockerfile.
- To build an image using the Dockerfile, run `docker build -t [name] .` in the root directory.
- To build a compose container of all the images, run `docker compose up -d` in the root directory.
77 changes: 77 additions & 0 deletions jest-playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './playwright_tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
19 changes: 19 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: [
"/node_modules/",
"/playwright_tests/"
],
collectCoverage: true,
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov'],
collectCoverageFrom: [
'src/**/*.ts',
'src/**/*.tsx',
'!src/**/*.d.ts',
'!src/**/*.test.ts',
'!src/**/*.spec.ts',
],
};
44 changes: 44 additions & 0 deletions jest_tests/family_crest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { generateCrest } from '../src/app/family-crest/generate-crest';

jest.mock('openai', () => ({
__esModule: true,
default: jest.fn().mockImplementation(() => ({
images: {
generate: jest.fn().mockResolvedValue({
data: [{ url: 'https://example.com/image.jpg' }],
}),
},
})),
}));

describe('generateCrest', () => {
it('returns URL of generated image with all properties defined', async () => {
const imageUrl = await generateCrest({
symbol: 'symbol',
name: 'name',
color: 'color',
motto: 'motto',
animal: 'animal',
details: 'details',
});
expect(imageUrl).toBe('https://example.com/image.jpg');
});
it('returns URL of generated image with some properties defined', async () => {
const imageUrl = await generateCrest({
symbol: 'symbol',
name: 'name',
color: 'color',
motto: 'motto',
});
expect(imageUrl).toBe('https://example.com/image.jpg');
});

it('returns URL of generated image with no properties defined', async () => {
const imageUrl = await generateCrest({
symbol: 'symbol',
name: 'name',
color: 'color',
});
expect(imageUrl).toBe('https://example.com/image.jpg');
});
});
24 changes: 24 additions & 0 deletions jest_tests/lib_utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { cn, moneyFormatter } from '../src/lib/utils';
import { twMerge } from 'tailwind-merge';
import { clsx } from 'clsx';

describe('cn function', () => {
it('should handle empty input', () => {
const result = cn();
expect(result).toEqual('');
});
it('should merge class names using twMerge and clsx', () => {
const classNames = ['class1', 'class2', 'class3'];
const result = cn(...classNames);
const expected = twMerge(clsx(...classNames));
expect(result).toEqual(expected);
});
});

describe('moneyFormatter function', () => {
it('should format money correctly', () => {
const expected = '$1,000.00';
const result = moneyFormatter.format(1000);
expect(result).toEqual(expected);
});
});
32 changes: 32 additions & 0 deletions jest_tests/ui.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
Collapsible,
CollapsibleTrigger,
CollapsibleContent,
} from '../src/components/ui/collapsible';
import { AspectRatio } from '../src/components/ui/aspect-ratio';
import * as AspectRatioPrimitive from '@radix-ui/react-aspect-ratio';
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';

describe('Collapsible component', () => {
it('should assign CollapsiblePrimitive.Root to Collapsible', () => {
expect(Collapsible).toEqual(CollapsiblePrimitive.Root);
});
});

describe('Collapsible trigger', () => {
it('should assign CollapsiblePrimitive.CollapsibleTrigger to CollapsibleTrigger', () => {
expect(CollapsibleTrigger).toEqual(CollapsiblePrimitive.CollapsibleTrigger);
});
});

describe('Collapsible content', () => {
it('should assign CollapsiblePrimitive.CollapsibleContent to CollapsibleContent', () => {
expect(CollapsibleContent).toEqual(CollapsiblePrimitive.CollapsibleContent);
});
});

describe('AspectRatio component', () => {
it('should assign AspectRatioPrimitive.Root to AspectRatio', () => {
expect(AspectRatio).toEqual(AspectRatioPrimitive.Root);
});
});
39 changes: 39 additions & 0 deletions jest_tests/wealth_forest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { wealthItems } from '../src/app/wealth-forest/data';
interface WealthItem {
alt: string;
src: string;
description: string;
}
describe('wealthItems array', () => {
it('should be properly defined', () => {
expect(Array.isArray(wealthItems)).toBe(true);
});

it('should contain the expected number of items', () => {
expect(wealthItems.length).toBe(7);
});
it('should contain the expected items', () => {
wealthItems.forEach((item: WealthItem) => {
expect(item).toHaveProperty('alt');
expect(item).toHaveProperty('src');
expect(item).toHaveProperty('description');
});
});
it('each item should have a non-empty alt property', () => {
wealthItems.forEach((item: WealthItem) => {
expect(item.alt).toBeTruthy();
});
});

it('each item should have a non-empty src property', () => {
wealthItems.forEach((item: WealthItem) => {
expect(item.src).toBeTruthy();
});
});

it('each item should have a non-empty description property', () => {
wealthItems.forEach((item: WealthItem) => {
expect(item.description).toBeTruthy();
});
});
});
Loading
Loading