-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EuiTextTruncate] Fix
testenv
mocks (#7234)
- Loading branch information
Showing
12 changed files
with
174 additions
and
152 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
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
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { CanvasTextUtils } from './canvas_text_utils'; | ||
|
||
let mockCanvasWidth = 0; | ||
Object.defineProperty(HTMLCanvasElement.prototype, 'getContext', { | ||
value: () => ({ measureText: () => ({ width: mockCanvasWidth }), font: '' }), | ||
}); | ||
|
||
describe('CanvasTextUtils', () => { | ||
describe('font calculations', () => { | ||
it('computes the set font if passed a container element', () => { | ||
const container = document.createElement('div'); | ||
container.style.font = '14px Inter'; | ||
|
||
const utils = new CanvasTextUtils({ container }); | ||
expect(utils.context.font).toEqual('14px Inter'); | ||
}); | ||
|
||
it('accepts a static font string', () => { | ||
const utils = new CanvasTextUtils({ font: '14px Inter' }); | ||
expect(utils.context.font).toEqual('14px Inter'); | ||
}); | ||
}); | ||
|
||
describe('text width utils', () => { | ||
const utils = new CanvasTextUtils({ font: '' }); | ||
|
||
describe('textWidth', () => { | ||
it('returns the measured text width from the canvas', () => { | ||
mockCanvasWidth = 200; | ||
expect(utils.textWidth).toEqual(200); | ||
}); | ||
}); | ||
|
||
describe('setTextToCheck', () => { | ||
it('sets the internal currentText variable', () => { | ||
utils.setTextToCheck('hello world'); | ||
expect(utils.currentText).toEqual('hello world'); | ||
}); | ||
}); | ||
}); | ||
}); |
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,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export class CanvasTextUtils { | ||
constructor(_: any) {} | ||
|
||
computeFontFromElement = (_: HTMLElement) => ''; | ||
|
||
textWidth = 0; | ||
|
||
currentText = ''; | ||
setTextToCheck = (text: string) => { | ||
this.currentText = text; | ||
}; | ||
} |
Oops, something went wrong.