Add Unit Tests

This commit is contained in:
2024-04-21 16:38:18 -04:00
parent df60173b49
commit 6c54d38efc
15 changed files with 5228 additions and 21 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
{
"extends": ["next", "next/core-web-vitals"],
"extends": ["next/core-web-vitals"],
"rules": {
"no-unused-vars": ["warn", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }],
"jsx-a11y/alt-text": "off",
+22
View File
@@ -0,0 +1,22 @@
import { Chat } from "../src/components/app/datatypes";
import renderer from 'react-test-renderer';
var exampleChatObj = {
body: "Hello, World!",
isSystem: false,
timestamp: 1710527946340,
user: "TestUser"
}
var exampleUser = {
uid: "123456",
username: "TestUser",
lastOnline: true
}
it('Chat Renders Correctly', () => {
const tree = renderer
.create((<Chat chatObj={exampleChatObj} user={exampleUser} />))
.toJSON();
expect(tree).toMatchSnapshot();
});
@@ -0,0 +1,14 @@
import { ChatRoomSidebar } from "../src/components/app/datatypes";
import renderer from 'react-test-renderer';
var exampleRoom = {
name: "TestRoom",
description: "This is a test room.",
}
it('ChatRoomSidebar Renders Correctly', () => {
const tree = renderer
.create((<ChatRoomSidebar roomObj={exampleRoom} />))
.toJSON();
expect(tree).toMatchSnapshot();
});
+30
View File
@@ -0,0 +1,30 @@
import { DM } from "../src/components/app/friends/dm";
import renderer from 'react-test-renderer';
var message = "Hello, World! This is a test message. https://www.google.com"
var exampleUser = {
uid: "123456",
username: "TestUser",
firstName: "Test",
lastName: "User",
lastOnline: true,
pfp: "https://th.bing.com/th/id/OIP.K5VoTfw97JiEc1OBODAjmQHaHO?rs=1&pid=ImgDetMain"
}
var friendObj = {
uid: "123456",
username: "TestUser",
firstName: "Test",
lastName: "Friend",
lastOnline: true,
pfp: "https://th.bing.com/th/id/OIP.K5VoTfw97JiEc1OBODAjmQHaHO?rs=1&pid=ImgDetMain"
}
it('RMF Renders Correctly', () => {
const tree = renderer
.create(<DM user={exampleUser} friendObj={friendObj} />)
.toJSON();
expect(tree).toMatchSnapshot();
});
+25
View File
@@ -0,0 +1,25 @@
import { FirstPage } from "@mui/icons-material";
import { Member } from "../src/components/app/datatypes";
import renderer from 'react-test-renderer';
var exampleChatObj = {
body: "Hello, World!",
isSystem: false,
timestamp: 1710527946340,
user: "TestUser"
}
var exampleUser = {
uid: "123456",
username: "TestUser",
firstName: "Test",
lastName: "User",
lastOnline: true
}
it('Member Renders Correctly', () => {
const tree = renderer
.create((<Member memberObj={exampleUser} />))
.toJSON();
expect(tree).toMatchSnapshot();
});
+11
View File
@@ -0,0 +1,11 @@
import { RMF } from "../src/components/app/datatypes";
import renderer from 'react-test-renderer';
var message = "Hello, World! This is a test message. https://www.google.com"
it('RMF Renders Correctly', () => {
const tree = renderer
.create((RMF(message)))
.toJSON();
expect(tree).toMatchSnapshot();
});
@@ -0,0 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Chat Renders Correctly 1`] = `
<div
className="width-[100%] bg-white rounded-lg mt-1 text-left p-1 grid grid-cols-2 mr-2"
>
<div>
<span
className="mr-[5px]"
style={
{
"color": "#133337",
}
}
>
<a
className="hover:font-bold cursor-pointer"
href="/user?uid=undefined"
onClick={[Function]}
onMouseEnter={[Function]}
onTouchStart={[Function]}
>
TestUser
</a>
</span>
Hello, World!
</div>
<div
className="text-right text-[#d1d1d1]"
>
3/15/2024, 2:39:06 PM
</div>
</div>
`;
@@ -0,0 +1,54 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ChatRoomSidebar Renders Correctly 1`] = `
<div
className="border-[black] border-1 shadow-lg p-2 m-2 rounded-lg cursor-pointer"
>
<a
href="/chat?room=undefined/TestRoom-undefined"
onClick={[Function]}
onMouseEnter={[Function]}
onTouchStart={[Function]}
>
<div
className="grid grid-cols-3"
>
<div
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<svg
aria-hidden={true}
className="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-testid="PersonIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4m0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4"
/>
</svg>
<div>
0
/
0
</div>
</div>
<div
className="col-span-2"
>
<div
className="font-bold"
>
TestRoom
</div>
<div
className="italic"
>
This is a test room.
</div>
</div>
</div>
</a>
</div>
`;
@@ -0,0 +1,76 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`RMF Renders Correctly 1`] = `
<div
className="border-[black] border-1 shadow-lg m-2 rounded-lg"
>
<div
className="grid grid-cols-4"
>
<div
className="place-content-center"
>
<svg
aria-hidden={true}
className="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium cursor-pointer css-i4bv87-MuiSvgIcon-root"
data-testid="ChatIcon"
focusable="false"
onClick={[Function]}
viewBox="0 0 24 24"
>
<path
d="M20 2H4c-1.1 0-1.99.9-1.99 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2M6 9h12v2H6zm8 5H6v-2h8zm4-6H6V6h12z"
/>
</svg>
</div>
<div
className="col-span-3 cursor-pointer"
>
<div
onClick={[Function]}
>
<div
className="grid grid-cols-2 justify-items-center"
>
<div
className="mr-8"
>
<img
className="w-[50px] h-[50px]"
src="https://th.bing.com/th/id/OIP.K5VoTfw97JiEc1OBODAjmQHaHO?rs=1&pid=ImgDetMain"
/>
</div>
<div
className=""
>
<div
className="font-bold"
>
<svg
aria-hidden={true}
className="MuiSvgIcon-root MuiSvgIcon-fontSize20px text-lime-600 mr-1 relative top-[-2px] css-821wyw-MuiSvgIcon-root"
data-testid="CircleIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2"
/>
</svg>
Test
Friend
</div>
<div
className=""
>
@
TestUser
</div>
</div>
</div>
</div>
</div>
</div>
</div>
`;
@@ -0,0 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Member Renders Correctly 1`] = `
<a
href="/user?uid=123456"
onClick={[Function]}
onMouseEnter={[Function]}
onTouchStart={[Function]}
>
<div
className="cursor-pointer g-[aliceblue] rounded-lg m-3 shadow-xl p-2"
>
<svg
aria-hidden={true}
className="MuiSvgIcon-root MuiSvgIcon-fontSize20px text-lime-600 mr-1 relative top-[-1px] css-821wyw-MuiSvgIcon-root"
data-testid="CircleIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2"
/>
</svg>
TestUser
</div>
</a>
`;
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`RMF Renders Correctly 1`] = `
<span
className="mr-2"
>
Hello, World! This is a test message.
<img
className="max-w-[100%]"
src="https://www.google.com"
/>
</span>
`;
+204
View File
@@ -0,0 +1,204 @@
const nextJest = require('next/jest')
/**
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/
/** @type {import('jest').Config} */
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})
const config = {
testEnvironment: 'jsdom',
// All imported modules in your tests should be mocked automatically
// automock: false,
// Stop running tests after `n` failures
// bail: 0,
// The directory where Jest should store its cached dependency information
// cacheDirectory: "C:\\Users\\Nick\\AppData\\Local\\Temp\\jest",
// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,
// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,
// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,
// The directory where Jest should output its coverage files
coverageDirectory: "coverage",
// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],
// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",
// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],
// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,
// A path to a custom dependency extractor
// dependencyExtractor: undefined,
// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,
// The default configuration for fake timers
// fakeTimers: {
// "enableGlobally": false
// },
// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],
// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,
// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,
// A set of global variables that need to be available in all test environments
// globals: {},
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",
// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],
// An array of file extensions your modules use
// moduleFileExtensions: [
// "js",
// "mjs",
// "cjs",
// "jsx",
// "ts",
// "tsx",
// "json",
// "node"
// ],
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
// moduleNameMapper: {},
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],
// Activates notifications for test results
// notify: false,
// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",
// A preset that is used as a base for Jest's configuration
// preset: undefined,
// Run tests from one or more projects
// projects: undefined,
// Use this configuration option to add custom reporters to Jest
// reporters: undefined,
// Automatically reset mock state before every test
// resetMocks: false,
// Reset the module registry before running each individual test
// resetModules: false,
// A path to a custom resolver
// resolver: undefined,
// Automatically restore mock state and implementation before every test
// restoreMocks: false,
// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,
// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],
// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",
// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],
// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],
// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],
// The test environment that will be used for testing
// testEnvironment: "jest-environment-node",
// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
// Adds a location field to test results
// testLocationInResults: false,
// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],
// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],
// This option allows the use of a custom results processor
// testResultsProcessor: undefined,
// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",
// A map from regular expressions to paths to transformers
// transform: undefined,
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "\\\\node_modules\\\\",
// "\\.pnp\\.[^\\\\]+$"
// ],
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
// Indicates whether each individual test should be reported during the run
// verbose: undefined,
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],
// Whether to use watchman for file crawling
// watchman: true,
};
module.exports = createJestConfig(config)
+4705 -17
View File
File diff suppressed because it is too large Load Diff
+11 -2
View File
@@ -6,9 +6,13 @@
"dev": "next dev",
"build": "next build",
"start": "npx serve@latest out",
"lint": "next lint"
"lint": "next lint",
"test": "jest"
},
"dependencies": {
"@babel/core": "^7.24.4",
"@babel/preset-env": "^7.24.4",
"@babel/preset-react": "^7.24.1",
"@capacitor/android": "^5.7.4",
"@capacitor/core": "^5.7.4",
"@capacitor/geolocation": "^5.0.7",
@@ -25,14 +29,19 @@
"react-beforeunload": "^2.6.0",
"react-dom": "^18.2.0",
"react-firebase-hooks": "^5.1.1",
"react-hook-form": "^7.50.1"
"react-hook-form": "^7.50.1",
"react-test-renderer": "^18.2.0"
},
"devDependencies": {
"@capacitor/assets": "^3.0.5",
"@capacitor/cli": "^5.7.4",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^15.0.2",
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.1.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"postcss": "^8",
"tailwindcss": "^3.3.0"
}
@@ -63,7 +63,7 @@ function imageProcessing(url) {
* @param {String} message - Message to Format
* @returns {String} - Formatted Message (IN HTML)
*/
function RMF(message) {
export function RMF(message) {
var URLREGEX = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g;
var URLmatch = message.match(URLREGEX);
var newMessage = URLmatch ? [] : message