This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
7,963 additions
and
942 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ dist/ | |
lib/ | ||
es/ | ||
src/**/*.js | ||
npm-debug.log | ||
|
||
# Generated by rollup | ||
.rpt2_cache/ | ||
.rpt2_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: node_js | ||
node_js: | ||
- "8" | ||
before_install: | ||
- npm i -g [email protected] | ||
install: | ||
- npm ci | ||
script: | ||
- npm run ci | ||
# keep the npm cache around to speed up installs | ||
cache: | ||
directories: | ||
- "$HOME/.npm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"editor.tabSize": 2, | ||
"eslint.enable": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Change Log | ||
========== | ||
|
||
This project adheres to [Semantic Versioning](https://semver.org/). | ||
|
||
Every release is documented on the Github [Releases](https://github.com/tiagovtristao/react-table-container/releases) page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import * as React from "react"; | ||
import * as ReactDOMServer from 'react-dom/server'; | ||
import ReactTableContainer from "../src/index"; | ||
|
||
const containerHTML = (dimensions) => ( | ||
ReactDOMServer.renderToString( | ||
<ReactTableContainer width={dimensions.width} height={dimensions.height}> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Header cell</th> | ||
<th>Header cell</th> | ||
<th>Header cell</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>Body cell</td> | ||
<td>Body cell</td> | ||
<td>Body cell</td> | ||
</tr> | ||
<tr> | ||
<td>Body cell</td> | ||
<td>Body cell</td> | ||
<td>Body cell</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</ReactTableContainer> | ||
) | ||
); | ||
|
||
describe('container', () => { | ||
let page; | ||
|
||
beforeAll(async () => { | ||
page = await (global as any).__BROWSER__.newPage(); | ||
|
||
await page.setContent(` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<style> | ||
#app { | ||
width: 1000px; | ||
height: 1000px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> | ||
`); | ||
}); | ||
|
||
afterAll(async () => { | ||
await page.close(); | ||
}); | ||
|
||
const attachTable = async (dimensions) => { | ||
await page.evaluate(html => { | ||
document.querySelector('#app').innerHTML = html; | ||
}, containerHTML(dimensions)); | ||
}; | ||
|
||
const getComputedDimensions = async (selector) => { | ||
let computedDimensions = await page.evaluate(s => { | ||
let el = document.querySelector(s); | ||
|
||
return { | ||
width: window.getComputedStyle(el).width, | ||
height: window.getComputedStyle(el).height, | ||
} | ||
}, selector); | ||
|
||
return computedDimensions; | ||
}; | ||
|
||
it('renders \'100px\' by \'100px\'', async () => { | ||
expect.assertions(2); | ||
|
||
await attachTable({ width: '100px', height: '100px' }); | ||
|
||
let { width, height } = await getComputedDimensions('#app > div'); | ||
|
||
expect(width).toBe('100px'); | ||
expect(height).toBe('100px'); | ||
}); | ||
|
||
it('renders \'100%\' by \'100%\' (ie. the dimensions of the parent component)', async () => { | ||
expect.assertions(2); | ||
|
||
await attachTable({ width: '100%', height: '100%' }); | ||
|
||
let parentContainerDimensions = await getComputedDimensions('#app'); | ||
let containerDimensions = await getComputedDimensions('#app > div'); | ||
|
||
expect(containerDimensions.width).toBe(parentContainerDimensions.width); | ||
expect(containerDimensions.height).toBe(parentContainerDimensions.height); | ||
}); | ||
|
||
it('renders \'auto\' by \'auto\' (ie. the dimensions of the table itself)', async () => { | ||
expect.assertions(2); | ||
|
||
await attachTable({ width: 'auto', height: 'auto' }); | ||
|
||
let containerDimensions = await getComputedDimensions('#app > div'); | ||
let tableDimensions = await getComputedDimensions('#app table[data-rtc-id="main-table"]'); | ||
|
||
expect(containerDimensions.width).toBe(tableDimensions.width); | ||
expect(containerDimensions.height).toBe(tableDimensions.height); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const chalk = require("chalk"); | ||
const puppeteer = require("puppeteer"); | ||
const fs = require("fs"); | ||
const mkdirp = require("mkdirp"); | ||
const os = require("os"); | ||
const path = require("path"); | ||
|
||
const DIR = path.join(os.tmpdir(), "jest_puppeteer_global_setup"); | ||
|
||
module.exports = async function() { | ||
console.log(chalk.green("Setup Puppeteer")); | ||
const browser = await puppeteer.launch({ args: ["--no-sandbox"] }); | ||
// This global is not available inside tests but only in global teardown | ||
global.__BROWSER_GLOBAL__ = browser; | ||
// Instead, we expose the connection details via file system to be used in tests | ||
mkdirp.sync(DIR); | ||
fs.writeFileSync(path.join(DIR, "wsEndpoint"), browser.wsEndpoint()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const chalk = require("chalk"); | ||
const rimraf = require("rimraf"); | ||
const os = require("os"); | ||
const path = require("path"); | ||
|
||
const DIR = path.join(os.tmpdir(), "jest_puppeteer_global_setup"); | ||
|
||
module.exports = async function() { | ||
console.log(chalk.green("Teardown Puppeteer")); | ||
await global.__BROWSER_GLOBAL__.close(); | ||
rimraf.sync(DIR); | ||
}; |
Oops, something went wrong.