Skip to content

Commit

Permalink
test tweaks, more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kremalicious committed Sep 10, 2023
1 parent b042f89 commit 0507493
Show file tree
Hide file tree
Showing 15 changed files with 399 additions and 55 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ env:
PUBLIC_WALLETCONNECT_ID: ${{ secrets.GATSBY_WALLETCONNECT_ID }}

jobs:
lint:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
node: ['18']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'npm'
- run: npm ci
- run: npm run lint

test-unit:
strategy:
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ All unit test files live beside the respective component with naming pattern `*.

Testing setup, fixtures, and mocks shared between unit & integration tests can be found in `./test` folder.

To run all linting and unit tests:
To run all unit tests:

```bash
npm run test:unit
Expand Down
153 changes: 150 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"build": "astro build --config '.config/astro.config.ts'",
"preview": "astro preview",
"prebuild": "run-p --silent --continue-on-error create:symlinks create:icons create:redirects move:downloads",
"test:unit": "npm run lint && npm run vitest",
"test:unit": "vitest run --config './test/vitest.config.ts' --coverage",
"test:e2e": "playwright test --config './test/playwright.config.ts'",
"vitest": "vitest run --config './test/vitest.config.ts' --coverage --silent",
"lint": "run-p --silent lint:js lint:css lint:md",
"lint:js": "eslint --ignore-path .gitignore --ext .ts,.tsx,.astro,.mjs,.js,.cjs .",
"lint:css": "stylelint --config '.config/.stylelintrc.json' 'src/**/*.css'",
Expand Down Expand Up @@ -54,6 +53,7 @@
},
"devDependencies": {
"@playwright/test": "^1.37.1",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^14.0.0",
"@types/node": "^20.6.0",
"@types/react": "^18.2.21",
Expand Down
15 changes: 15 additions & 0 deletions src/components/Exif/ExifMap.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, it } from 'vitest'
import { render, screen } from '@testing-library/react'
import ExifMap from './ExifMap'

describe('ExifMap', () => {
it('renders without crashing', async () => {
render(
<ExifMap
gps={{ latitude: 41.89007222222222, longitude: 12.491516666666666 }}
/>
)

await screen.findByText(/wheel to zoom/)
})
})
32 changes: 0 additions & 32 deletions src/components/Transitions.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/components/layouts/Base/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import logo from '@images/kremalicious512.png'
import SchemaOrg, { type Props as SchemaProps } from './SchemaOrg.astro'
import type { CollectionEntry } from 'astro:content'
import { $themeColor } from '@stores/theme'
import { UMAMI_SCRIPT_URL, UMAMI_WEBSITE_ID } from '@lib/umami'
import { getUmamiConfig } from '@lib/umami'
type Props = CollectionEntry<'articles' | 'links' | 'photos'>['data'] & {
pageTitle?: string
Expand Down Expand Up @@ -53,6 +53,7 @@ const schema: SchemaProps = {
const themeColorInitial = $themeColor.get()
const isProduction = import.meta.env.PROD
const typekitID = import.meta.env.PUBLIC_TYPEKIT_ID
const { UMAMI_SCRIPT_URL, UMAMI_WEBSITE_ID } = getUmamiConfig()
---

<html lang="en">
Expand Down
34 changes: 34 additions & 0 deletions src/lib/feed.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { it, describe, expect } from 'vitest'
import { getPostFeedContent } from './feed'

describe('getPostFeedContent Function', () => {
it('should generate post feed content with an image', async () => {
const mockPost = {
body: 'Mock post content in markdown format',
data: { image: { src: 'https://example.com/image.jpg' } }
}

const feedContent = await getPostFeedContent(mockPost as any)

expect(feedContent).toContain('<img src="https://example.com/image.jpg" />')
expect(feedContent).toContain('Mock post content in markdown format')
expect(feedContent).toContain(
'This post was published on <a href="https://kremalicious.com">kremalicious.com</a>'
)
})

it('should generate post feed content without an image', async () => {
const mockPost = {
body: 'Mock post content in markdown format',
data: {}
}

const feedContent = await getPostFeedContent(mockPost as any)

expect(feedContent).not.toContain('<img src="')
expect(feedContent).toContain('Mock post content in markdown format')
expect(feedContent).toContain(
'This post was published on <a href="https://kremalicious.com">kremalicious.com</a>'
)
})
})
Loading

0 comments on commit 0507493

Please sign in to comment.