Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Tests: Simplify table manual test data and add model output.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Sep 6, 2018
1 parent 843eb92 commit aa398a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 184 deletions.
185 changes: 2 additions & 183 deletions tests/manual/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,199 +6,18 @@
</style>

<div id="editor">
<p>Complex table:</p>

<figure>
<figcaption>Data about the planets of our solar system (Planetary facts taken from <a
href="http://nssdc.gsfc.nasa.gov/planetary/factsheet/">Nasa's Planetary Fact Sheet - Metric</a>.
</figcaption>
<table>
<thead>
<tr>
<td colspan="2">&nbsp;</td>
<th scope="col">Name</th>
<th scope="col">Mass (10<sup>24</sup>kg)</th>
<th scope="col">Diameter (km)</th>
<th scope="col">Density (kg/m<sup>3</sup>)</th>
<th scope="col">Gravity (m/s<sup>2</sup>)</th>
<th scope="col">Length of day (hours)</th>
<th scope="col">Distance from Sun (10<sup>6</sup>km)</th>
<th scope="col">Mean temperature (°C)</th>
<th scope="col">Number of moons</th>
<th scope="col">Notes</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="2" rowspan="4" scope="rowgroup">Terrestrial planets</th>
<th scope="row">Mercury</th>
<td>0.330</td>
<td>4,879</td>
<td>5427</td>
<td>3.7</td>
<td>4222.6</td>
<td>57.9</td>
<td>167</td>
<td>0</td>
<td>Closest to the Sun</td>
</tr>
<tr>
<th scope="row">Venus</th>
<td>4.87</td>
<td>12,104</td>
<td>5243</td>
<td>8.9</td>
<td>2802.0</td>
<td>108.2</td>
<td>464</td>
<td>0</td>
<td>&nbsp;</td>
</tr>
<tr>
<th scope="row">Earth</th>
<td>5.97</td>
<td>12,756</td>
<td>5514</td>
<td>9.8</td>
<td>24.0</td>
<td>149.6</td>
<td>15</td>
<td>1</td>
<td>Our world</td>
</tr>
<tr>
<th scope="row">Mars</th>
<td>0.642</td>
<td>6,792</td>
<td>3933</td>
<td>3.7</td>
<td>24.7</td>
<td>227.9</td>
<td>-65</td>
<td>2</td>
<td>The red planet</td>
</tr>
<tr>
<th scope="rowgroup" rowspan="4">Jovian planets</th>
<th scope="rowgroup" rowspan="2">Gas giants</th>
<th scope="row">Jupiter</th>
<td>1898</td>
<td>142,984</td>
<td>1326</td>
<td>23.1</td>
<td>9.9</td>
<td>778.6</td>
<td>-110</td>
<td>67</td>
<td>The largest planet</td>
</tr>
<tr>
<th scope="row">Saturn</th>
<td>568</td>
<td>120,536</td>
<td>687</td>
<td>9.0</td>
<td>10.7</td>
<td>1433.5</td>
<td>-140</td>
<td>62</td>
<td>&nbsp;</td>
</tr>
<tr>
<th scope="rowgroup" rowspan="2">Ice giants</th>
<th scope="row">Uranus</th>
<td>86.8</td>
<td>51,118</td>
<td>1271</td>
<td>8.7</td>
<td>17.2</td>
<td>2872.5</td>
<td>-195</td>
<td>27</td>
<td>&nbsp;</td>
</tr>
<tr>
<th scope="row">Neptune</th>
<td>102</td>
<td>49,528</td>
<td>1638</td>
<td>11.0</td>
<td>16.1</td>
<td>4495.1</td>
<td>-200</td>
<td>14</td>
<td>&nbsp;</td>
</tr>
<tr>
<th colspan="2" scope="rowgroup">Dwarf planets</th>
<th scope="row">Pluto</th>
<td>0.0146</td>
<td>2,370</td>
<td>2095</td>
<td>0.7</td>
<td>153.3</td>
<td>5906.4</td>
<td>-225</td>
<td>5</td>
<td>Declassified as a planet in 2006, but this <a
href="http://www.usatoday.com/story/tech/2014/10/02/pluto-planet-solar-system/16578959/">remains controversial</a>.
</td>
</tr>
</tbody>
</table>
</figure>

<p>Table with 2 tbody:</p>

<table>
<tbody>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
</tbody>
<tbody>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
</tbody>
</table>

<p>Table with no tbody:</p>

<table>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
</table>

<p>Table with thead section between two tbody sections</p>

<table>
<tbody>
<tr>
<td>2</td>
</tr>
</tbody>
<thead>
<tr>
<td>1</td>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
</tr>
</tbody>
</table>
</div>
<h2>Model contents:</h2>
<div id="model"></div>
28 changes: 27 additions & 1 deletion tests/manual/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
* For licensing, see LICENSE.md.
*/

/* globals console, window, document */
/* globals console, window, document, global */

import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
import Table from '../../src/table';
import TableToolbar from '../../src/tabletoolbar';
import TableSelection from '../../src/tableselection';
import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';

ClassicEditor
.create( document.querySelector( '#editor' ), {
Expand All @@ -23,7 +24,32 @@ ClassicEditor
} )
.then( editor => {
window.editor = editor;
editor.model.document.on( 'change', () => {
printModelContents( editor );
} );

printModelContents( editor );
} )
.catch( err => {
console.error( err.stack );
} );

const modelDiv = global.document.querySelector( '#model' );

function printModelContents( editor ) {
modelDiv.innerText = formatTable( getData( editor.model ) );
}

function formatTable( tableString ) {
return tableString
.replace( /<table>/g, '\n<table>' )
.replace( /<tableRow>/g, '\n<tableRow>\n ' )
.replace( /<thead>/g, '\n<thead>\n ' )
.replace( /<tbody>/g, '\n<tbody>\n ' )
.replace( /<tr>/g, '\n<tr>\n ' )
.replace( /<\/tableRow>/g, '\n</tableRow>' )
.replace( /<\/thead>/g, '\n</thead>' )
.replace( /<\/tbody>/g, '\n</tbody>' )
.replace( /<\/tr>/g, '\n</tr>' )
.replace( /<\/table>/g, '\n</table>' );
}

0 comments on commit aa398a9

Please sign in to comment.