[packages/portal][l]: Moved portal folder to root dir

This commit is contained in:
Rising Odegua
2021-03-08 11:33:21 +01:00
parent 6aec97a728
commit c905b59f3e
41 changed files with 502 additions and 4002 deletions

View File

@@ -0,0 +1,26 @@
import React from 'react'
import {render } from '@testing-library/react';
import path from 'path'
import Chart from '../../components/Chart';
import { getDataset } from "../../lib/dataset"
import { addView } from '../../lib/utils'
let dataset
let datasetWithView
beforeAll(async () => {
const datasetsDirectory = path.join(process.cwd(), 'fixtures', 'datasetsPlotlyView')
dataset = await getDataset(datasetsDirectory)
datasetWithView = addView(dataset)
});
/** @test {Chart Component} */
describe('Chart Component', () => {
it('should render without crashing', async () => {
const spec = JSON.parse(datasetWithView.props.specs)[0]
const { findByTestId } = render(<Chart spec={spec} />)
expect(await findByTestId("plotlyChart"))
});
});

View File

@@ -0,0 +1,27 @@
import React from 'react'
import { render } from '@testing-library/react';
import path from 'path'
import Table from '../../components/Table';
import { getDataset } from "../../lib/dataset"
let dataset
beforeAll(async () => {
const datasetsDirectory = path.join(process.cwd(), 'fixtures', 'datasetsPlotlyView')
dataset = await getDataset(datasetsDirectory)
});
/** @test {Table Component} */
describe('Table Component', () => {
it('should render without crashing', async () => {
const resource = dataset.resources[0]
render(<Table data={resource.sample} schema={resource.schema} />)
});
it('tableGrid div is found', async () => {
const resource = dataset.resources[0]
const { findByTestId } = render(<Table data={resource.sample} schema={resource.schema} />)
expect(await findByTestId('tableGrid'))
});
});

33
tests/lib/dataset.test.js Normal file
View File

@@ -0,0 +1,33 @@
import { getDataset } from "../../lib/dataset"
import path from 'path'
let directory
let dataset
beforeAll(async () => {
directory = path.join(process.cwd(), 'fixtures', 'datasetsDoubleView')
dataset = await getDataset(directory)
})
describe("Dataset", () => {
it("loads a dataset from a local folder", async () => {
expect(dataset).toStrictEqual(
expect.objectContaining({
readme: expect.any(String),
readmeHtml: expect.any(String),
descriptor: expect.any(Object),
resources: expect.any(Object),
})
)
})
it("returns a resource with required fields", () => {
const resource = dataset.resources[0]
const expectedFields = ["path", "pathType", "name", "format", "mediatype",
"schema", "encoding", "sample", "size"]
expect(expectedFields).toStrictEqual(
Object.keys(resource)
)
})
});

78
tests/lib/utils.test.js Normal file
View File

@@ -0,0 +1,78 @@
import path from 'path'
import { getDataset } from "../../lib/dataset"
import { addView, getDataForViewSpec } from '../../lib/utils'
const plotlyDatasetsDirectory = path.join(process.cwd(), 'fixtures', 'datasetsPlotlyView')
const vegaDatasetsDirectory = path.join(process.cwd(), 'fixtures', 'datasetsVegaView')
const doubleDatasetsDirectory = path.join(process.cwd(), 'fixtures', 'datasetsDoubleView')
let plotlyDataset
let vegaDataset
let doubleDataset
let plotlyDatasetWithView
let vegaDatasetWithView
let doubleDatasetWithView
beforeAll(async () => {
plotlyDataset = await getDataset(plotlyDatasetsDirectory)
vegaDataset = await getDataset(vegaDatasetsDirectory)
doubleDataset = await getDataset(doubleDatasetsDirectory)
plotlyDatasetWithView = addView(plotlyDataset)
vegaDatasetWithView = addView(vegaDataset)
doubleDatasetWithView = addView(doubleDataset)
});
describe("AddView", () => {
it("_value field is added to Plotly datapackage", () => {
const resource = plotlyDatasetWithView.props.dataset.resources[0]
expect("_values" in resource).toBe(true)
expect(resource["_values"].length > 0).toBe(true)
});
it("Plotly spec is added to datapackage", () => {
const spec = JSON.parse(plotlyDatasetWithView.props.specs)[0]
expect(spec.specType).toBe("plotly")
expect(spec.layout.title).toBe("Plotly Layout Title")
expect(spec.data[0].x.length).toBeGreaterThan(0)
expect(spec.data[0].y.length).toBeGreaterThan(0)
});
it("_value field is added to datapackage with double views", () => {
const resources = doubleDatasetWithView.props.dataset.resources
resources.map((resource) => {
expect("_values" in resource).toBe(true)
expect(resource["_values"].length > 0).toBe(true)
})
});
it("view spec is created for each view in a datapackage", () => {
const specs = JSON.parse(doubleDatasetWithView.props.specs)
const simpleSpec = specs[0]
const plotlySpec = specs[1]
expect(simpleSpec.specType).toBe("simple")
expect(simpleSpec.layout.title).toBe("title1")
expect(simpleSpec.data[0].x.length).toBeGreaterThan(0)
expect(simpleSpec.data[0].y.length).toBeGreaterThan(0)
expect(plotlySpec.specType).toBe("plotly")
expect(plotlySpec.layout.title).toBe("Plotly Layout Title")
expect(plotlySpec.data[0].x.length).toBeGreaterThan(0)
expect(plotlySpec.data[0].y.length).toBeGreaterThan(0)
});
});
describe("getDataForViewSpec", () => {
it("Generates right data for vega spec", ()=>{
const resource = vegaDataset.resources[0]
const data = getDataForViewSpec(resource, "vega")
expect(data).toStrictEqual(resource.sample)
})
it("Generates right data for plotly spec", ()=>{
const resource = plotlyDataset.resources[0]
const data = getDataForViewSpec(resource, "plotly")
expect(data).not.toStrictEqual(resource.sample[0])
expect(data[0]).toStrictEqual(Object.keys(resource.sample[0]))
})
})

39
tests/pages/index.test.js Normal file
View File

@@ -0,0 +1,39 @@
import React from 'react'
import { render } from '@testing-library/react';
import path from 'path'
import Home from '../../pages/index';
import { getDataset } from "../../lib/dataset"
import { addView } from '../../lib/utils'
let plotlyDatasetWithView
beforeAll(async () => {
const plotlyDatasetsDirectory = path.join(process.cwd(), 'fixtures', 'datasetsPlotlyView')
const plotlyDataset = await getDataset(plotlyDatasetsDirectory)
plotlyDatasetWithView = addView(plotlyDataset)
});
/** @test {Home Component} */
describe('Home Component', () => {
it('should render without crashing', async () => {
const dataset = plotlyDatasetWithView.props.dataset
const specs = plotlyDatasetWithView.props.specs
const { findAllByText } = render(<Home dataset={dataset} specs={specs} />)
expect(await findAllByText('README'))
});
it('Sections are found in home page', async () => {
const dataset = plotlyDatasetWithView.props.dataset
const specs = plotlyDatasetWithView.props.specs
const { findByTestId, findAllByText } = render(<Home dataset={dataset} specs={specs} />)
expect(await findAllByText('Key info'))
expect(await findAllByText('Data Files'))
expect(await findAllByText('Graph'))
expect(await findAllByText('Data Preview'))
expect(await findByTestId('datasetTitle'))
});
});

2
tests/setupTests.js Normal file
View File

@@ -0,0 +1,2 @@
import 'jest-canvas-mock';
import "@testing-library/jest-dom/extend-expect";