]>
Commit | Line | Data |
---|---|---|
5bddb937 DI |
1 | import { assert } from 'chai'; |
2 | import { Viewport } from './Viewport'; | |
7048f6ed | 3 | |
5bddb937 | 4 | describe('Viewport', () => { |
7048f6ed DI |
5 | var terminal; |
6 | var viewportElement; | |
7 | var charMeasureElement; | |
8 | var viewport; | |
ed1a31d1 | 9 | var scrollAreaElement; |
7048f6ed | 10 | |
5bddb937 | 11 | const CHARACTER_HEIGHT = 10; |
7048f6ed | 12 | |
5bddb937 | 13 | beforeEach(() => { |
7048f6ed DI |
14 | terminal = { |
15 | lines: [], | |
16 | rows: 0, | |
17 | ydisp: 0, | |
5bddb937 | 18 | on: () => {}, |
7048f6ed DI |
19 | rowContainer: { |
20 | style: { | |
21 | lineHeight: 0 | |
22 | } | |
23 | } | |
24 | }; | |
25 | viewportElement = { | |
5bddb937 | 26 | addEventListener: () => {}, |
7048f6ed DI |
27 | style: { |
28 | height: 0, | |
29 | lineHeight: 0 | |
30 | } | |
31 | }; | |
32 | scrollAreaElement = { | |
33 | style: { | |
34 | height: 0 | |
35 | } | |
36 | }; | |
37 | charMeasureElement = { | |
5bddb937 | 38 | getBoundingClientRect: () => { |
7048f6ed DI |
39 | return { width: null, height: CHARACTER_HEIGHT }; |
40 | } | |
41 | }; | |
5bddb937 | 42 | viewport = new Viewport(terminal, viewportElement, scrollAreaElement, charMeasureElement); |
7048f6ed DI |
43 | }); |
44 | ||
5bddb937 DI |
45 | describe('refresh', () => { |
46 | it('should set the line-height of the terminal', () => { | |
7048f6ed DI |
47 | assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px'); |
48 | assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px'); | |
5bddb937 | 49 | charMeasureElement.getBoundingClientRect = () => { |
7048f6ed DI |
50 | return { width: null, height: 1 }; |
51 | }; | |
52 | viewport.refresh(); | |
53 | assert.equal(viewportElement.style.lineHeight, '1px'); | |
54 | assert.equal(terminal.rowContainer.style.lineHeight, '1px'); | |
55 | }); | |
5bddb937 | 56 | it('should set the height of the viewport when the line-height changed', () => { |
dcc991bd | 57 | terminal.lines.push(''); |
58 | terminal.lines.push(''); | |
59 | terminal.rows = 1; | |
60 | viewport.refresh(); | |
61 | assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); | |
5bddb937 | 62 | charMeasureElement.getBoundingClientRect = () => { |
dcc991bd | 63 | return { width: null, height: 20 }; |
64 | }; | |
65 | viewport.refresh(); | |
66 | assert.equal(viewportElement.style.height, 20 + 'px'); | |
67 | }); | |
7048f6ed | 68 | }); |
2c9c95f5 | 69 | |
5bddb937 DI |
70 | describe('syncScrollArea', () => { |
71 | it('should sync the scroll area', () => { | |
2c9c95f5 DI |
72 | terminal.lines.push(''); |
73 | terminal.rows = 1; | |
74 | assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px'); | |
75 | viewport.syncScrollArea(); | |
76 | assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); | |
77 | assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); | |
78 | terminal.lines.push(''); | |
79 | viewport.syncScrollArea(); | |
80 | assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); | |
81 | assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px'); | |
82 | }); | |
83 | }); | |
7048f6ed | 84 | }); |