-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Seed tests for datagrid, test
TextRenderer/drawText
(#585)
* Seed datagrid tests, test `TextRenderer.drawText` * Fix font to make tests pass on CI * Add leeway to pass on Firefox & Chrome + wrap test
- Loading branch information
1 parent
613dc9d
commit f904a6b
Showing
7 changed files
with
201 additions
and
0 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
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,24 @@ | ||
/* | ||
* Copyright (c) Jupyter Development Team. | ||
* Distributed under the terms of the Modified BSD License. | ||
*/ | ||
|
||
process.env.FIREFOX_BIN = require('playwright').firefox.executablePath(); | ||
process.env.FIREFOX_HEADLESS_BIN = process.env.FIREFOX_BIN; | ||
process.env.WEBKIT_BIN = require('playwright').webkit.executablePath(); | ||
process.env.WEBKIT_HEADLESS_BIN = process.env.WEBKIT_BIN; | ||
|
||
module.exports = function (config) { | ||
config.set({ | ||
basePath: '.', | ||
frameworks: ['mocha'], | ||
reporters: ['mocha'], | ||
files: ['lib/bundle.test.js'], | ||
port: 9876, | ||
colors: true, | ||
singleRun: true, | ||
browserNoActivityTimeout: 30000, | ||
failOnEmptyTestSuite: false, | ||
logLevel: config.LOG_INFO | ||
}); | ||
}; |
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,8 @@ | ||
/* | ||
* Copyright (c) Jupyter Development Team. | ||
* Distributed under the terms of the Modified BSD License. | ||
*/ | ||
|
||
import { createRollupTestConfig } from '@lumino/buildutils'; | ||
const rollupConfig = createRollupTestConfig(); | ||
export default rollupConfig; |
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,4 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
import './textrenderer.spec'; |
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,117 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
import { expect } from 'chai'; | ||
|
||
import { CellRenderer, GraphicsContext, TextRenderer } from '@lumino/datagrid'; | ||
|
||
class LoggingGraphicsContext extends GraphicsContext { | ||
fillText(text: string, x: number, y: number, maxWidth?: number): void { | ||
super.fillText(text, x, y, maxWidth); | ||
this.texts.push(text); | ||
} | ||
|
||
texts: string[] = []; | ||
} | ||
|
||
describe('@lumino/datagrid', () => { | ||
let gc: LoggingGraphicsContext; | ||
const defaultCellConfig: CellRenderer.CellConfig = { | ||
x: 0, | ||
y: 0, | ||
width: 100, | ||
height: 20, | ||
row: 0, | ||
column: 0, | ||
region: 'body', | ||
value: '', | ||
metadata: {} | ||
}; | ||
beforeEach(() => { | ||
const canvas = document.createElement('canvas'); | ||
const context = canvas.getContext('2d')!; | ||
gc = new LoggingGraphicsContext(context); | ||
}); | ||
describe('TextRenderer', () => { | ||
describe('drawText()', () => { | ||
it('should right-elide long strings', () => { | ||
const renderer = new TextRenderer({ | ||
elideDirection: 'right', | ||
font: '12px Arial' | ||
}); | ||
renderer.drawText(gc, { | ||
...defaultCellConfig, | ||
width: 100, | ||
value: 'this text exceeds 100px' | ||
}); | ||
expect(gc.texts.pop()).to.eq('this text exce…'); | ||
}); | ||
|
||
it('should left-elide long strings', () => { | ||
const renderer = new TextRenderer({ | ||
elideDirection: 'left', | ||
font: '12px Arial' | ||
}); | ||
renderer.drawText(gc, { | ||
...defaultCellConfig, | ||
width: 100, | ||
value: 'this text exceeds 100px' | ||
}); | ||
// Pixel calculations differ between Firefox and Chrome, either is good. | ||
expect(gc.texts.pop()).to.be.oneOf(['…xceeds 100px', '…ceeds 100px']); | ||
}); | ||
|
||
it('should not elide if eliding is disabled', () => { | ||
const renderer = new TextRenderer({ | ||
elideDirection: 'none', | ||
font: '12px Arial' | ||
}); | ||
renderer.drawText(gc, { | ||
...defaultCellConfig, | ||
width: 100, | ||
value: 'this text exceeds 100px' | ||
}); | ||
expect(gc.texts.pop()).to.eq('this text exceeds 100px'); | ||
}); | ||
|
||
it('should wrap text', () => { | ||
const renderer = new TextRenderer({ | ||
elideDirection: 'none', | ||
wrapText: true, | ||
font: '12px Arial' | ||
}); | ||
renderer.drawText(gc, { | ||
...defaultCellConfig, | ||
width: 100, | ||
value: 'this text exceeds 100px' | ||
}); | ||
expect(gc.texts.pop()).to.eq('exceeds 100px'); | ||
expect(gc.texts.pop()).to.eq('this text'); | ||
}); | ||
|
||
it('should not break up Unicode surrogate characters (left)', () => { | ||
const renderer = new TextRenderer({ | ||
elideDirection: 'left', | ||
font: '12px Arial' | ||
}); | ||
renderer.drawText(gc, { | ||
...defaultCellConfig, | ||
width: 45, | ||
value: '📦📦📦' | ||
}); | ||
expect(gc.texts.pop()).to.eq('…📦'); | ||
}); | ||
it('should not break up Unicode surrogate characters (right)', () => { | ||
const renderer = new TextRenderer({ | ||
elideDirection: 'right', | ||
font: '12px Arial' | ||
}); | ||
renderer.drawText(gc, { | ||
...defaultCellConfig, | ||
width: 45, | ||
value: '📦📦📦' | ||
}); | ||
expect(gc.texts.pop()).to.eq('📦…'); | ||
}); | ||
}); | ||
}); | ||
}); |
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,10 @@ | ||
{ | ||
"extends": "../../../tsconfigbase", | ||
"compilerOptions": { | ||
"lib": ["DOM", "ES2018"], | ||
"outDir": "lib", | ||
"rootDir": "src", | ||
"types": ["chai", "mocha"] | ||
}, | ||
"include": ["src/*"] | ||
} |
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