-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dffc23
commit ad451c2
Showing
13 changed files
with
10,023 additions
and
4,712 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
{ | ||
"extends": ["eslint:recommended", "next", "prettier"] | ||
"extends": ["eslint:recommended", "next", "prettier"], | ||
"overrides": [ | ||
{ | ||
"files": ["**/__tests__/**/*"], | ||
"env": { | ||
"jest": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Unit Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- '*' | ||
pull_request: | ||
branches: | ||
- '*' | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [20.x, 22.x] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
|
||
- run: npm ci | ||
|
||
- name: Run Unit Tests | ||
run: npm run test:unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { cn } from "@/lib/utils" | ||
|
||
describe('check classnames (twMerge)', () => { | ||
it('normal checks', () => { | ||
expect(cn("w-full", "h-full")).toBe("w-full h-full"); | ||
expect(cn("md:max-h-[1vw]", "md:hover:max-h-[10vw]")).toBe( | ||
"md:max-h-[1vw] md:hover:max-h-[10vw]" | ||
); | ||
}) | ||
|
||
it('whitespace check', () => { | ||
expect(cn(" w-full", "h-full ")).toBe( | ||
"w-full h-full" | ||
); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { escapeText } from "@/lib/utils" | ||
|
||
describe('escape text', () => { | ||
it('should return lower case of plainText', () => { | ||
expect(escapeText('plainText')).toBe('plaintext'); | ||
}) | ||
|
||
it('should return sluggified version of text', () => { | ||
expect(escapeText('Hello World')).toBe('hello-world'); | ||
expect(escapeText('Moonlit@grace')).toBe('moonlit-grace'); | ||
}) | ||
|
||
it('should handle multiplte special characters', () => { | ||
expect(escapeText('hello-----world')).toBe('hello-world'); | ||
expect(escapeText('moon&&&lit***grace')).toBe('moon-lit-grace') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { extractParagraphs } from "@/lib/utils" | ||
|
||
describe('extract paragraphs only from markdown', () => { | ||
it('should return paragraph', () => { | ||
const mockMarkdown = ` | ||
# Moonlitgrace | ||
> WHOAMI | ||
Moonlitgrace is a good bwoy!.` | ||
expect(extractParagraphs(mockMarkdown)).toBe('Moonlitgrace is a good bwoy!.') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { formatDate } from "@/lib/utils"; | ||
|
||
test('check formated date', () => { | ||
const date = new Date("2023-03-11T02:37:40.790Z"); | ||
expect(formatDate(date)).toBe("Mar 11, 2023"); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { stripHtmlTags } from "@/lib/utils" | ||
|
||
describe('stripe html tags', () => { | ||
it('should return plaintext itself', () => { | ||
expect(stripHtmlTags('plain-text')).toBe('plain-text') | ||
}) | ||
|
||
it('should return content inside', () => { | ||
expect(stripHtmlTags('<strong>Moonlitgrace</strong>')).toBe('Moonlitgrace') | ||
expect(stripHtmlTags('<h1><italic>Hello World</italic></h1>')).toBe('Hello World') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { truncate } from "@/lib/utils" | ||
|
||
describe('truncate char', () => { | ||
const exampleStr = 'Step into Moonlitgrace' | ||
|
||
it('shouldn"t truncate char shorter than n', () => { | ||
expect(truncate(exampleStr, 25)).toBe(exampleStr) | ||
}) | ||
|
||
it('shouldn truncate char larger than n', () => { | ||
expect(truncate(exampleStr, 20)).toBe('Step into Moonlit...') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { validateFile } from "@/lib/utils"; | ||
|
||
describe('check File validation', () => { | ||
it('should return true if File is valid', () => { | ||
const file = new File(['content'], 'test.txt', { type: 'text/plain' }); | ||
expect(validateFile(file)).toBeTruthy(); | ||
}) | ||
|
||
it('should return false if File is invalid', () => { | ||
const file = {} as File; | ||
expect(validateFile(file)).toBeFalsy(); | ||
}) | ||
|
||
it('should return false if File name is invalid', () => { | ||
const file = new File(['content'], '', { type: 'text/plain' }); | ||
expect(validateFile(file)).toBeFalsy(); | ||
}) | ||
|
||
it('should return false if File size is invalid', () => { | ||
const file = new File(['content'], 'test.txt', { type: 'text/plain' }); | ||
// force set size property | ||
Object.defineProperty(file, 'size', { | ||
value: 0 | ||
}) | ||
expect(validateFile(file)).toBeFalsy(); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { Config } from 'jest' | ||
import nextJest from 'next/jest.js' | ||
|
||
const createJestConfig = nextJest({ | ||
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment | ||
dir: './', | ||
}) | ||
|
||
// Add any custom config to be passed to Jest | ||
const config: Config = { | ||
coverageProvider: 'v8', | ||
testEnvironment: 'jsdom', | ||
// Add more setup options before each test is run | ||
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'], | ||
// Path alias | ||
moduleNameMapper: { | ||
'^@/(.*)$': '<rootDir>/$1', | ||
} | ||
} | ||
|
||
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async | ||
export default createJestConfig(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@testing-library/jest-dom'; |
Oops, something went wrong.