Skip to content

Commit

Permalink
added tests and more workflows config
Browse files Browse the repository at this point in the history
  • Loading branch information
jlinco committed Nov 8, 2023
1 parent 7d505c5 commit 4e47e7f
Show file tree
Hide file tree
Showing 16 changed files with 774 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "next/core-web-vitals"
"extends": ["next/core-web-vitals", "eslint:recommended", "prettier"]
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint && npx lint-staged --concurrent false
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged && npm run test:e2e
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.prettierignore
public/
.gitignore
.husky/
.next/
.vercel/
node_modules/
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"trailingComma": "none",
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"printWidth": 80,
"bracketSpacing": true,
"bracketSameLine": true
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnPaste": true
}
20 changes: 20 additions & 0 deletions __tests__/dashboard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { test, expect } from '@playwright/test'

test('Should get dashboard items from API', async ({ request, page }) => {
// console.log(apiContext.)
await page.goto('/')
const allDashboards = await request.fetch(
'https://gist.githubusercontent.com/kabaros/da79636249e10a7c991a4638205b1726/raw/fa044f54e7a5493b06bb51da40ecc3a9cb4cd3a5/dashboards.json'
)
expect(allDashboards.ok()).toBeTruthy()
const { dashboards } = await allDashboards.json()
expect(dashboards).toContainEqual({
displayName: 'Antenatal Care',
id: 'nghVC4wtyzi',
starred: true
})

await expect(
page.getByRole('button', { name: 'Antenatal Care' })
).toBeVisible()
})
13 changes: 13 additions & 0 deletions __tests__/home.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { test, expect } from '@playwright/test'

test('Homepage should render properly', async ({ page }) => {
await page.goto('/')

// expect Dashboards title to exist
await expect(page.getByRole('heading', { name: 'Dashboards' })).toBeVisible()

// expect filter item to exist
await expect(
page.getByRole('button', { name: 'Filter Items...' })
).toBeVisible()
})
1 change: 1 addition & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import './globals.css'
Expand Down
7 changes: 4 additions & 3 deletions components/DashboardWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react'
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
import { Toggle } from './ui/toggle';
import { Dashboard } from '@/lib/data';
import { BarChart2, BarChartBig, BarChartHorizontalBig, CandlestickChart, FileType, Gauge, LineChart, Mails, PieChart, Star, Map } from 'lucide-react';
import { FileType, Mails, Star, Map } from 'lucide-react';
import { renderVizTypeIcons } from '@/lib/helperWidgets';
// import { renderContent } from '@/lib/helperWidgets';

Expand All @@ -20,17 +20,18 @@ const DashboardWidget = ({ allDashboards }: {
return <li key={nodeId} className='flex flex-row items-center justify-start w-full space-x-2 text-xs py-2 leading-normal text-gray-600 '><Map size={16} color="#615c5c" /> <span>{content.map.name}</span></li>;
case 'MESSAGES':
return <li key={nodeId} className='flex flex-row items-center justify-start w-full space-x-2 text-xs py-2 leading-normal text-gray-600 '><Mails size={16} color="#615c5c" strokeWidth={1} /> <span>{'Messages'}</span></li>;
case 'TEXT':
case 'TEXT': {
const title = content.text.includes('\n') ? content.text.split('\n')[0] : content.text
return <li key={nodeId} className=' flex flex-row items-start justify-start w-full space-x-2 text-xs py-2 leading-normal text-gray-600 '><FileType size={16} color="#615c5c" /> <span>{title}</span></li>;
}
default:
return 'N/A'
}
}

return (
<Accordion type="single" collapsible className="w-full space-y-4" defaultValue={allDashboards[0].id}>
{allDashboards.map((item, _) => (
{allDashboards.map((item) => (
<AccordionItem key={item.id} value={item.id} className="bg-white rounded-lg shadow-sm my-4 px-4 py-0 relative">
<AccordionTrigger className='flex flex-row items-center w-full'>
<p className='text-base font-semibold justify-self-start mr-auto'>{item.displayName}</p>
Expand Down
2 changes: 1 addition & 1 deletion components/FilterWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const FilterWidget = () => {
}
return (
<Select onValueChange={handleFilterSearch} defaultValue={searchParams.get('query')?.toString()}>
<SelectTrigger className="w-[180px]">
<SelectTrigger className="w-[180px]" role='button'>
<SelectValue placeholder='Filter Items...' aria-placeholder="Select Type" />
</SelectTrigger>
<SelectContent>
Expand Down
Loading

0 comments on commit 4e47e7f

Please sign in to comment.