[tests][m]-add-tests-for-all-pages

This commit is contained in:
Gift Egwuenu 2020-06-03 15:53:21 +01:00
parent dab0865368
commit aea6b830e5
12 changed files with 1039 additions and 32 deletions

View File

@ -1,11 +0,0 @@
import React from 'react'
import { render } from '@testing-library/react'
import Index from '../pages/index'
test('renders homepage successfully', () => {
const { getByText } = render(<Index />)
const linkElement = getByText(
/Get started with Next.js/
)
expect(linkElement).toBeInTheDocument()
})

View File

@ -0,0 +1,222 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`showcase page renders a snapshot 1`] = `
<div
className="container mx-auto"
>
<div
className="my-16"
>
<div
className="showcase-page-header"
>
<h1
className="text-4xl"
>
Remuneración octubre 2017
</h1>
<p
className="publisher flex"
>
<img
className="rounded-full w-6 mr-2"
src="https://www.gravatar.com/avatar/none?d=https%3A%2F%2Ftesting.datahub.io%2Fstatic%2Fimg%2Flogo-cube03.png"
/>
<a
className="text-orange-400"
href="#"
>
Datos Abiertos Municipio Loja Ecuador
</a>
</p>
<table
className="table-auto my-6"
>
<thead>
<tr>
<th
className="pr-10 py-2"
>
Files
</th>
<th
className="px-10 py-2"
>
Size
</th>
<th
className="px-10 py-2"
>
Format
</th>
<th
className="px-10 py-2"
>
Created
</th>
<th
className="px-10 py-2"
>
Updated
</th>
<th
className="px-10 py-2"
>
License
</th>
<th
className="px-10 py-2"
>
Source
</th>
</tr>
</thead>
<tbody>
<tr>
<td
className="pr-10 py-2"
>
3
</td>
<td
className="px-10 py-2"
>
N/A
</td>
<td
className="px-10 py-2"
>
text xls
</td>
<td
className="px-10 py-2"
>
2020-05-27
</td>
<td
className="px-10 py-2"
>
a few seconds ago
</td>
<td
className="px-10 py-2 text-orange-500"
>
cc-by
</td>
<td
className="px-10 py-2"
>
Datos Abiertos Municipio Loja Ecuador
</td>
</tr>
</tbody>
</table>
<div
className="mb-10"
>
Contiene información sobre las remuneraciones de los servidores de la institución, correspondiente al mes de octubre del año 2017.
</div>
<a
className="bg-black text-white py-4 px-4 rounded-sm mr-2 hover:border-0 hover:border-black hover:text-black hover:bg-transparent"
href="#data"
>
Download
</a>
<a
className="border border-black text-black py-4 px-4 rounded-sm"
href="#data-cli"
>
Developers
</a>
</div>
<div
className="my-16"
>
<h2
className="text-3xl pb-2"
id="data"
>
Data Files
</h2>
<p>
Download files in this dataset
</p>
<table
className="table-auto"
>
<thead>
<th
className="pr-10 text-left py-4"
>
File
</th>
<th
className="px-10 text-left py-4"
>
Description
</th>
<th
className="px-10 text-left py-4"
>
Size
</th>
<th
className="px-10 text-left py-4"
>
Last changed
</th>
<th
className="px-10 text-left py-4"
>
Download
</th>
</thead>
<tbody>
<tr
className="bg-gray-100 text-sm"
>
<td
className="pr-10 py-4 text-orange-500"
>
<i
className="far fa-file-alt"
/>
<a
className="anchor-link"
href="/@myorg/myDataset/r/myresource"
>
Remuneración octubre 2017
</a>
</td>
<td
className="px-10 py-4"
>
Remuneración octubre 2017
</td>
<td
className="px-10 py-4"
title="{{ item.resource.sizeFormatted }}"
/>
<td
className="px-10 py-4"
title="{{ item.resource.modified }}"
>
Invalid Date
</td>
<td
className="px-10 py-4 text-orange-500"
>
<a
href="#"
>
Text
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
`;

View File

@ -0,0 +1,15 @@
import React from 'react'
import { render } from '@testing-library/react'
import renderer from 'react-test-renderer'
import Index from '../../../../pages/@myorg/myDataset/index'
test('showcase page renders a snapshot', () => {
const tree = renderer.create(<Index />).toJSON()
expect(tree).toMatchSnapshot()
})
test('render data package page successfully', () => {
const { getByText } = render(<Index />)
const element = getByText('Download files in this dataset')
expect(element).toBeInTheDocument()
})

View File

@ -0,0 +1,204 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`showcase renders a snapshot 1`] = `
<div
className="container mx-auto"
>
<div
className="my-16"
>
<div
className="react-me tables"
id="datapackage-view-{{view.id}}"
/>
<p
className="notice"
>
This is a preview version. There might be more data in the original version.
</p>
<div
className="my-16"
>
<h2
className="text-3xl pb-2"
id="data"
>
Remuneración octubre 2017
</h2>
<p
className="text-2xl my-4 font-light"
>
Field Information
</p>
<table
className="table-auto border text-sm mb-2"
>
<thead>
<tr>
<th
className="px-5 w-2/5 text-left py-4 border"
>
Field Name
</th>
<th
className="px-5 w-1/5 text-left py-4 border"
>
Order
</th>
<th
className="px-5 w-1/6 text-left py-4 border"
>
Type(Format)
</th>
<th
className="px-5 w-1/5 text-left py-4 border"
>
Description
</th>
</tr>
</thead>
<tbody>
<tr
className="bg-gray-200 text-sm border"
>
<td
className="px-5 py-4 border font-bold"
>
No.
</td>
<td
className="px-5 py-4 border"
>
1
</td>
<td
className="px-5 py-4 border"
>
any
</td>
<td
className="px-5 py-4 border"
/>
</tr>
<tr
className="text-sm border"
>
<td
className="px-5 py-4 border font-bold"
>
Puesto institucional
</td>
<td
className="px-5 py-4 border"
>
2
</td>
<td
className="px-5 py-4 border"
>
string
</td>
<td
className="px-5 py-4 border"
/>
</tr>
<tr
className="bg-gray-200 text-sm border"
>
<td
className="px-5 py-4 border font-bold"
>
Régimen laboral al que pertenece
</td>
<td
className="px-5 py-4 border"
>
3
</td>
<td
className="px-5 py-4 border"
>
string
</td>
<td
className="px-5 py-4 border"
/>
</tr>
<tr
className="text-sm border"
>
<td
className="px-5 py-4 border font-bold"
>
Número de partida presupuestaria
</td>
<td
className="px-5 py-4 border"
>
4
</td>
<td
className="px-5 py-4 border"
>
string
</td>
<td
className="px-5 py-4 border"
/>
</tr>
<tr
className="bg-gray-200 text-sm border"
>
<td
className="px-5 py-4 border font-bold"
>
Grado jerárquico o escala al que pertenece el puesto
</td>
<td
className="px-5 py-4 border"
>
5
</td>
<td
className="px-5 py-4 border"
>
any
</td>
<td
className="px-5 py-4 border"
/>
</tr>
<tr
className="text-sm border"
>
<td
className="px-5 py-4 border font-bold"
>
Remuneración mensual unificacada
</td>
<td
className="px-5 py-4 border"
>
6
</td>
<td
className="px-5 py-4 border"
>
any
</td>
<td
className="px-5 py-4 border"
/>
</tr>
</tbody>
</table>
<a
className="text-orange-600 underline"
href="/@myorg/myDataset"
>
Go back
</a>
</div>
</div>
</div>
`;

View File

@ -0,0 +1,17 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import renderer from 'react-test-renderer'
import Resource from '../../../../../pages/@myorg/myDataset/r/myresource'
test('showcase renders a snapshot', () => {
const tree = renderer.create(<Resource />).toJSON()
expect(tree).toMatchSnapshot()
})
test('render resource page successfully', () => {
const { getByText } = render(<Resource />)
const element = getByText('This is a preview version. There might be more data in the original version.')
const message = 'this is not a preview version'
expect(element).toBeInTheDocument()
expect(screen.queryByText(message)).toBeNull()
})

View File

@ -0,0 +1,534 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders snapshot homepage 1`] = `
<div
className="jsx-2293288804 container mx-auto"
>
<main
className="jsx-2293288804"
>
<nav
className="flex justify-between"
>
<div>
<button
className="navbar-toggle"
data-target="#myNavbar"
data-toggle="collapse"
type="button"
>
<span
className="icon-bar"
/>
<span
className="icon-bar"
/>
<span
className="icon-bar"
/>
</button>
<a
className="main-logo pull-left"
href="/"
>
<img
className="img-responsive"
src="/datahub-cube.svg"
width="50"
/>
</a>
</div>
<div
className="collapse navbar-collapse"
id="myNavbar"
>
<ul
className="flex uppercase text-sm pt-10"
>
<li
className="pr-12"
>
<a
href="/about"
>
About
</a>
</li>
<li
className="pr-12"
>
<a
href="/news"
>
News
</a>
</li>
<li
className="pr-12"
>
<a
className="text-orange-500 join-link"
href="/search"
>
Find data
</a>
</li>
<li
className="pr-12"
>
<a
href="/collections"
>
Collections
</a>
</li>
<li
className="pr-12"
>
<a
href="/requests"
>
Requests
</a>
</li>
<li
className="pr-12"
>
<a
href="/docs"
>
Docs
</a>
</li>
<li
className="pr-12"
>
<a
href="/pricing"
>
Pricing
</a>
</li>
<li
className="pr-12"
>
<a
href="/download"
>
Tools
</a>
</li>
<li
className="pr-12"
>
<a
className="chat"
href="https://gitter.im/datahubio/chat"
target="_blank"
>
Chat
</a>
</li>
</ul>
</div>
</nav>
<section
className="jsx-2293288804 flex mt-10 ml-40 justify-center"
>
<div
className="jsx-2293288804"
>
<img
className="jsx-2293288804"
src="/banner.png"
width="500"
/>
</div>
<div
className="jsx-2293288804 mx-32"
>
<h1
className="jsx-2293288804 text-4xl font-thin"
>
Find, Share and Publish
<br
className="jsx-2293288804"
/>
Quality Data with
<span
className="jsx-2293288804 text-orange-500"
>
Datahub
</span>
</h1>
<p
className="jsx-2293288804 text-md font-light w-4/5"
>
At Datahub, we have over thousands of datasets for free and a Premium Data Service for additional or customised data with guaranteed updates.
</p>
<form
action="/search"
className="jsx-2293288804 py-4 flex"
method="GET"
>
<div
className="jsx-2293288804 border-2"
>
<input
className="jsx-2293288804 pr-24 pl-4 py-2"
name="q"
placeholder="Search ..."
required={true}
type="text"
/>
</div>
<div
className="jsx-2293288804 mx-3"
>
<button
className="jsx-2293288804 bg-black text-white rounded-sm px-4 py-3 font-thin"
type="submit"
>
Search Datasets
</button>
</div>
</form>
</div>
</section>
<section
className="jsx-2293288804 flex mt-6"
>
<div
className="jsx-2293288804 bg-gray-100 px-4 flex items-start py-5 mx-3"
>
<div
className="jsx-2293288804 px-5 pt-4"
>
<img
alt="core icon"
className="jsx-2293288804"
src="/core.png"
width="100"
/>
</div>
<div
className="jsx-2293288804"
>
<h2
className="jsx-2293288804 text-2xl font-thin"
>
Core Datasets
</h2>
<p
className="jsx-2293288804 pb-3 sub"
>
Datahub provides important, commonly-used data as high quality, easy-to-use and open data packages.
</p>
<a
className="jsx-2293288804 text-orange-500"
href="#"
onClick={[Function]}
onMouseEnter={[Function]}
>
View Collections
</a>
</div>
</div>
<div
className="jsx-2293288804 bg-gray-100 px-4 flex items-start py-5 mx-3"
>
<div
className="jsx-2293288804 px-5 pt-4"
>
<img
alt="core icon"
className="jsx-2293288804"
src="/request.png"
width="100"
/>
</div>
<div
className="jsx-2293288804"
>
<h2
className="jsx-2293288804 text-2xl font-thin"
>
Request Data
</h2>
<p
className="jsx-2293288804 pb-3 sub"
>
A service to locate and/or prepare data. There is no cost for making a request and all requests are completely confidential.
</p>
<a
className="jsx-2293288804 text-orange-500"
href="#"
onClick={[Function]}
onMouseEnter={[Function]}
>
Request Now
</a>
</div>
</div>
<div
className="jsx-2293288804 bg-gray-100 px-4 flex items-start py-5 mx-3"
>
<div
className="jsx-2293288804 px-5 pt-4"
>
<img
alt="core icon"
className="jsx-2293288804"
src="/earth-globe.png"
width="100"
/>
</div>
<div
className="jsx-2293288804"
>
<h2
className="jsx-2293288804 text-2xl font-thin"
>
Publish Data
</h2>
<p
className="jsx-2293288804 pb-3 sub"
>
Securely share and elegantly put data online with quality checks, versioning, data APIs, notifications & integrations.
</p>
<a
className="jsx-2293288804 text-orange-500"
href="#"
onClick={[Function]}
onMouseEnter={[Function]}
>
Start Publishing
</a>
</div>
</div>
</section>
<section
className="jsx-2293288804 core-datasets mt-20 flex justify-center"
id="core-datasets"
>
<div
className="jsx-2293288804 grid grid-cols-3 grid-rows-2 w-3/6"
>
<div
className="jsx-2293288804 bg-gray-100 px-3 m-1"
>
<div
className="jsx-2293288804 py-2"
>
<h4
className="jsx-2293288804 title font-thin"
>
S&P 500 Companies
</h4>
<p
className="jsx-2293288804 sub mb-4"
>
S&P 500 Companies with Financial Information
</p>
<a
className="jsx-2293288804 text-orange-500 text-base"
href="/core/s-and-p-500-companies"
>
View
</a>
</div>
</div>
<div
className="jsx-2293288804 bg-gray-100 px-3 m-1"
>
<div
className="jsx-2293288804 py-2"
>
<h4
className="jsx-2293288804 title font-thin"
>
Major cities of the world
</h4>
<p
className="jsx-2293288804 sub mb-4"
>
List of all the major cities in the world
</p>
<a
className="jsx-2293288804 text-orange-500 text-base"
href="/core/world-cities"
>
View
</a>
</div>
</div>
<div
className="jsx-2293288804 bg-gray-100 row-span-2 px-3 m-1"
>
<div
className="jsx-2293288804 py-2"
>
<img
className="jsx-2293288804"
src="/co2.png"
width="70"
/>
<h4
className="jsx-2293288804 title font-thin"
>
CO2 PPM
</h4>
<p
className="jsx-2293288804 sub mb-4"
>
CO2 PPM - Trends in Atmospheric Carbon Dioxide
<br
className="jsx-2293288804"
/>
co2-ppm | files 7 | 300kB
</p>
<a
className="jsx-2293288804 text-orange-500 text-base"
href="/core/co2-ppm"
>
View Dataset
</a>
</div>
</div>
<div
className="jsx-2293288804 bg-gray-100 row-span-2 px-3 m-1"
>
<div
className="jsx-2293288804 py-2"
>
<img
className="jsx-2293288804"
src="/worldwide.png"
width="70"
/>
<h4
className="jsx-2293288804 title font-thin"
>
Country List
</h4>
<p
className="jsx-2293288804 sub mb-4"
>
List of all countries with their 2 digit codes (ISO 3166-1)
<br
className="jsx-2293288804"
/>
country-list | files 2 | 27kB
</p>
<a
className="jsx-2293288804 text-orange-500 text-base"
href="/core/country-list"
>
View Dataset
</a>
</div>
</div>
<div
className="jsx-2293288804 bg-gray-100 px-3 m-1"
>
<div
className="jsx-2293288804 py-2"
>
<h4
className="jsx-2293288804 title font-thin"
>
ISO Language Codes
</h4>
<p
className="jsx-2293288804 sub mb-4"
>
ISO Language Codes (639-1 and 693-2) and IETF Language Types
</p>
<a
className="jsx-2293288804 text-orange-500 text-base"
href="/core/language-codes"
>
View
</a>
</div>
</div>
<div
className="jsx-2293288804 bg-gray-100 px-3 m-1"
>
<div
className="jsx-2293288804 py-2"
>
<h4
className="jsx-2293288804 title font-thin"
>
Global Temperature
</h4>
<p
className="jsx-2293288804 sub mb-4"
>
Data are included from the GISS Surface Temperature
</p>
<a
className="jsx-2293288804 text-orange-500 text-base"
href="/core/global-temp"
>
View
</a>
</div>
</div>
</div>
<div
className="jsx-2293288804 ml-10"
>
<h3
className="jsx-2293288804 text-2xl font-thin"
>
Core Datasets, data as youd want to use it
</h3>
<h1
className="jsx-2293288804 text-4xl py-3 font-thin"
>
Quality Data ready to Integrate
</h1>
<ul
className="jsx-2293288804 list-disc mb-10"
>
<li
className="jsx-2293288804 py-3"
>
High quality data ready to inspect, download and use.
<a
className="jsx-2293288804 text-orange-500"
href="/docs/core-data"
>
Read more
</a>
</li>
<li
className="jsx-2293288804 py-3"
>
Bulk and API access ready for automated integration with SDKs in Python, JS and many more.
<a
className="jsx-2293288804 text-orange-500"
href="/docs/getting-started/getting-data"
>
Read more
</a>
</li>
<li
className="jsx-2293288804 py-3"
>
Send a request if you need a help to find some good, quality dataset.
</li>
</ul>
<a
className="jsx-2293288804 bg-black text-white px-5 py-4 rounded-sm"
href="/core"
>
Discover Datasets
</a>
</div>
</section>
</main>
</div>
`;

View File

@ -0,0 +1,17 @@
import React from 'react'
import { render } from '@testing-library/react'
import renderer from 'react-test-renderer'
import Index from '../../pages/index'
test('renders snapshot homepage', () => {
const tree = renderer.create(<Index />).toJSON()
expect(tree).toMatchSnapshot()
})
test('renders text from hero section', () => {
const { getByText } = render(<Index />)
const linkElement = getByText(
/Find, Share and Publish/
)
expect(linkElement).toBeInTheDocument()
})

View File

@ -1,20 +1,29 @@
module.exports = {
collectCoverageFrom: [
'**/*.{js,jsx,ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
"**/*.{js,jsx,ts,tsx}",
"!**/*.d.ts",
"!**/node_modules/**",
"!**/config/**",
"!**/coverage/**",
"!**/**.config.js**",
],
setupFilesAfterEnv: ["<rootDir>/setupTests.js"],
testPathIgnorePatterns: [
"/node_modules/",
"/.next/",
"/jest.config.js/",
"/tailwind.config.js/",
"<rootDir>/postcss.config.js",
],
setupFilesAfterEnv: ['<rootDir>/setupTests.js'],
testPathIgnorePatterns: ['/node_modules/', '/.next/'],
transform: {
'^.+\\.(js|jsx|ts|tsx)$': '<rootDir>/node_modules/babel-jest',
'^.+\\.css$': '<rootDir>/config/jest/cssTransform.js',
"^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
},
transformIgnorePatterns: [
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
"/node_modules/",
"^.+\\.module\\.(css|sass|scss)$",
],
moduleNameMapper: {
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
"^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy",
},
}
};

View File

@ -6,7 +6,9 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"test": "jest --watch"
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
},
"dependencies": {
"next": "9.4.2",
@ -16,6 +18,7 @@
"devDependencies": {
"@testing-library/jest-dom": "^5.8.0",
"@testing-library/react": "^10.0.4",
"@types/jest": "^25.2.3",
"@types/react": "^16.9.35",
"babel-jest": "^26.0.1",
"jest": "^26.0.1",

View File

@ -1,5 +1,7 @@
/* istanbul ignore file */
import '../styles/index.css'
export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
}

View File

@ -1,7 +0,0 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { NextApiRequest, NextApiResponse } from 'next';
export default (req: NextApiRequest, res: NextApiResponse) => {
res.statusCode = 200
res.json({ name: 'John Doe' })
}

View File

@ -1,5 +1,7 @@
module.exports = {
purge: [],
purge: [
'./**/*.tsx'
],
theme: {
extend: {},
},