From aea6b830e59b8c04cbe482b6c6f37ec583ea422b Mon Sep 17 00:00:00 2001 From: Gift Egwuenu Date: Wed, 3 Jun 2020 15:53:21 +0100 Subject: [PATCH] [tests][m]-add-tests-for-all-pages --- __tests__/index.test.tsx | 11 - .../__snapshots__/index.test.tsx.snap | 222 ++++++++ .../pages/@myorg/myDataset/index.test.tsx | 15 + .../r/__snapshots__/myResource.test.tsx.snap | 204 +++++++ .../@myorg/myDataset/r/myResource.test.tsx | 17 + .../pages/__snapshots__/index.test.tsx.snap | 534 ++++++++++++++++++ __tests__/pages/index.test.tsx | 17 + jest.config.js | 31 +- package.json | 5 +- pages/{_app.js => _app.tsx} | 4 +- pages/api/hello.ts | 7 - tailwind.config.js | 4 +- 12 files changed, 1039 insertions(+), 32 deletions(-) delete mode 100644 __tests__/index.test.tsx create mode 100644 __tests__/pages/@myorg/myDataset/__snapshots__/index.test.tsx.snap create mode 100644 __tests__/pages/@myorg/myDataset/index.test.tsx create mode 100644 __tests__/pages/@myorg/myDataset/r/__snapshots__/myResource.test.tsx.snap create mode 100644 __tests__/pages/@myorg/myDataset/r/myResource.test.tsx create mode 100644 __tests__/pages/__snapshots__/index.test.tsx.snap create mode 100644 __tests__/pages/index.test.tsx rename pages/{_app.js => _app.tsx} (80%) delete mode 100644 pages/api/hello.ts diff --git a/__tests__/index.test.tsx b/__tests__/index.test.tsx deleted file mode 100644 index 2e579477..00000000 --- a/__tests__/index.test.tsx +++ /dev/null @@ -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() - const linkElement = getByText( - /Get started with Next.js/ - ) - expect(linkElement).toBeInTheDocument() -}) \ No newline at end of file diff --git a/__tests__/pages/@myorg/myDataset/__snapshots__/index.test.tsx.snap b/__tests__/pages/@myorg/myDataset/__snapshots__/index.test.tsx.snap new file mode 100644 index 00000000..0391eb02 --- /dev/null +++ b/__tests__/pages/@myorg/myDataset/__snapshots__/index.test.tsx.snap @@ -0,0 +1,222 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`showcase page renders a snapshot 1`] = ` +
+
+
+

+ Remuneración octubre 2017 +

+

+ + + Datos Abiertos Municipio Loja Ecuador + +

+ + + + + + + + + + + + + + + + + + + + + + + +
+ Files + + Size + + Format + + Created + + Updated + + License + + Source +
+ 3 + + N/A + + text xls + + 2020-05-27 + + a few seconds ago + + cc-by + + Datos Abiertos Municipio Loja Ecuador +
+
+ Contiene información sobre las remuneraciones de los servidores de la institución, correspondiente al mes de octubre del año 2017. +
+ + Download + + + Developers + +
+
+

+ Data Files +

+

+ Download files in this dataset +

+ + + + + + + + + + + + + + + + +
+ File + + Description + + Size + + Last changed + + Download +
+ + + + Remuneración octubre 2017 + + + Remuneración octubre 2017 + + + Invalid Date + + + Text + +
+
+
+
+`; diff --git a/__tests__/pages/@myorg/myDataset/index.test.tsx b/__tests__/pages/@myorg/myDataset/index.test.tsx new file mode 100644 index 00000000..6d4eaeda --- /dev/null +++ b/__tests__/pages/@myorg/myDataset/index.test.tsx @@ -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().toJSON() + expect(tree).toMatchSnapshot() +}) + +test('render data package page successfully', () => { + const { getByText } = render() + const element = getByText('Download files in this dataset') + expect(element).toBeInTheDocument() +}) diff --git a/__tests__/pages/@myorg/myDataset/r/__snapshots__/myResource.test.tsx.snap b/__tests__/pages/@myorg/myDataset/r/__snapshots__/myResource.test.tsx.snap new file mode 100644 index 00000000..c777063a --- /dev/null +++ b/__tests__/pages/@myorg/myDataset/r/__snapshots__/myResource.test.tsx.snap @@ -0,0 +1,204 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`showcase renders a snapshot 1`] = ` +
+
+
+

+ This is a preview version. There might be more data in the original version. +

+
+

+ Remuneración octubre 2017 +

+

+ Field Information +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Field Name + + Order + + Type(Format) + + Description +
+ No. + + 1 + + any + +
+ Puesto institucional + + 2 + + string + +
+ Régimen laboral al que pertenece + + 3 + + string + +
+ Número de partida presupuestaria + + 4 + + string + +
+ Grado jerárquico o escala al que pertenece el puesto + + 5 + + any + +
+ Remuneración mensual unificacada + + 6 + + any + +
+ + Go back + +
+
+
+`; diff --git a/__tests__/pages/@myorg/myDataset/r/myResource.test.tsx b/__tests__/pages/@myorg/myDataset/r/myResource.test.tsx new file mode 100644 index 00000000..26b036ea --- /dev/null +++ b/__tests__/pages/@myorg/myDataset/r/myResource.test.tsx @@ -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().toJSON() + expect(tree).toMatchSnapshot() +}) + +test('render resource page successfully', () => { + const { getByText } = render() + 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() +}) diff --git a/__tests__/pages/__snapshots__/index.test.tsx.snap b/__tests__/pages/__snapshots__/index.test.tsx.snap new file mode 100644 index 00000000..39eacca8 --- /dev/null +++ b/__tests__/pages/__snapshots__/index.test.tsx.snap @@ -0,0 +1,534 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders snapshot homepage 1`] = ` +
+
+ +
+
+ +
+
+

+ Find, Share and Publish +
+ Quality Data with + + Datahub + +

+

+ At Datahub, we have over thousands of datasets for free and a Premium Data Service for additional or customised data with guaranteed updates. +

+
+
+ +
+
+ +
+
+
+
+
+
+
+ core icon +
+
+

+ Core Datasets +

+

+ Datahub provides important, commonly-used data as high quality, easy-to-use and open data packages. +

+ + View Collections › + +
+
+
+
+ core icon +
+
+

+ Request Data +

+

+ A service to locate and/or prepare data. There is no cost for making a request and all requests are completely confidential. +

+ + Request Now › + +
+
+
+
+ core icon +
+
+

+ Publish Data +

+

+ Securely share and elegantly put data online with quality checks, versioning, data APIs, notifications & integrations. +

+ + Start Publishing › + +
+
+
+
+
+
+
+

+ S&P 500 Companies +

+

+ S&P 500 Companies with Financial Information +

+ + View + +
+
+
+
+

+ Major cities of the world +

+

+ List of all the major cities in the world +

+ + View + +
+
+
+
+ +

+ CO2 PPM +

+

+ CO2 PPM - Trends in Atmospheric Carbon Dioxide +
+ co2-ppm | files 7 | 300kB +

+ + View Dataset + +
+
+
+
+ +

+ Country List +

+

+ List of all countries with their 2 digit codes (ISO 3166-1) +
+ country-list | files 2 | 27kB +

+ + View Dataset + +
+
+
+
+

+ ISO Language Codes +

+

+ ISO Language Codes (639-1 and 693-2) and IETF Language Types +

+ + View + +
+
+
+
+

+ Global Temperature +

+

+ Data are included from the GISS Surface Temperature +

+ + View + +
+
+
+
+

+ Core Datasets, data as you’d want to use it +

+

+ Quality Data ready to Integrate +

+
    +
  • + High quality data ready to inspect, download and use. + + Read more › + +
  • +
  • + Bulk and API access ready for automated integration with SDKs in Python, JS and many more. + + Read more › + +
  • +
  • + Send a request if you need a help to find some good, quality dataset. +
  • +
+ + Discover Datasets + +
+
+
+
+`; diff --git a/__tests__/pages/index.test.tsx b/__tests__/pages/index.test.tsx new file mode 100644 index 00000000..be4442be --- /dev/null +++ b/__tests__/pages/index.test.tsx @@ -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().toJSON() + expect(tree).toMatchSnapshot() +}) + +test('renders text from hero section', () => { + const { getByText } = render() + const linkElement = getByText( + /Find, Share and Publish/ + ) + expect(linkElement).toBeInTheDocument() +}) diff --git a/jest.config.js b/jest.config.js index e90fad6d..b639f1ef 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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: ["/setupTests.js"], + testPathIgnorePatterns: [ + "/node_modules/", + "/.next/", + "/jest.config.js/", + "/tailwind.config.js/", + "/postcss.config.js", ], - setupFilesAfterEnv: ['/setupTests.js'], - testPathIgnorePatterns: ['/node_modules/', '/.next/'], transform: { - '^.+\\.(js|jsx|ts|tsx)$': '/node_modules/babel-jest', - '^.+\\.css$': '/config/jest/cssTransform.js', + "^.+\\.(js|jsx|ts|tsx)$": "/node_modules/babel-jest", + "^.+\\.css$": "/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", }, -} \ No newline at end of file +}; diff --git a/package.json b/package.json index 14f7403c..2ecf7102 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pages/_app.js b/pages/_app.tsx similarity index 80% rename from pages/_app.js rename to pages/_app.tsx index a9aac206..2417cc04 100644 --- a/pages/_app.js +++ b/pages/_app.tsx @@ -1,5 +1,7 @@ +/* istanbul ignore file */ import '../styles/index.css' export default function MyApp({ Component, pageProps }) { return -} \ No newline at end of file +} + diff --git a/pages/api/hello.ts b/pages/api/hello.ts deleted file mode 100644 index 1bc2bffd..00000000 --- a/pages/api/hello.ts +++ /dev/null @@ -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' }) -} diff --git a/tailwind.config.js b/tailwind.config.js index 138dac7d..c464410d 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,5 +1,7 @@ module.exports = { - purge: [], + purge: [ + './**/*.tsx' + ], theme: { extend: {}, },