]>
Commit | Line | Data |
---|---|---|
1 | import { assert } from 'chai'; | |
2 | import { Viewport } from './Viewport'; | |
3 | import {BufferSet} from './BufferSet'; | |
4 | ||
5 | describe('Viewport', () => { | |
6 | let terminal; | |
7 | let viewportElement; | |
8 | let charMeasure; | |
9 | let viewport; | |
10 | let scrollAreaElement; | |
11 | ||
12 | const CHARACTER_HEIGHT = 10; | |
13 | ||
14 | beforeEach(() => { | |
15 | terminal = { | |
16 | rows: 0, | |
17 | ydisp: 0, | |
18 | on: () => {}, | |
19 | rowContainer: { | |
20 | style: { | |
21 | lineHeight: 0 | |
22 | } | |
23 | }, | |
24 | selectionContainer: { | |
25 | style: { | |
26 | height: 0 | |
27 | } | |
28 | }, | |
29 | scrollback: 10 | |
30 | }; | |
31 | terminal.buffers = new BufferSet(terminal); | |
32 | terminal.buffer = terminal.buffers.active; | |
33 | viewportElement = { | |
34 | addEventListener: () => {}, | |
35 | style: { | |
36 | height: 0, | |
37 | lineHeight: 0 | |
38 | } | |
39 | }; | |
40 | scrollAreaElement = { | |
41 | style: { | |
42 | height: 0 | |
43 | } | |
44 | }; | |
45 | charMeasure = { | |
46 | height: CHARACTER_HEIGHT | |
47 | }; | |
48 | viewport = new Viewport(terminal, viewportElement, scrollAreaElement, charMeasure); | |
49 | }); | |
50 | ||
51 | describe('refresh', () => { | |
52 | it('should set the line-height of the terminal', done => { | |
53 | // Allow CharMeasure to be initialized | |
54 | setTimeout(() => { | |
55 | assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px'); | |
56 | assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px'); | |
57 | charMeasure.height = 1; | |
58 | viewport.refresh(); | |
59 | assert.equal(viewportElement.style.lineHeight, '1px'); | |
60 | assert.equal(terminal.rowContainer.style.lineHeight, '1px'); | |
61 | done(); | |
62 | }, 0); | |
63 | }); | |
64 | it('should set the height of the viewport when the line-height changed', () => { | |
65 | terminal.buffer.lines.push(''); | |
66 | terminal.buffer.lines.push(''); | |
67 | terminal.rows = 1; | |
68 | viewport.refresh(); | |
69 | assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); | |
70 | charMeasure.height = 2 * CHARACTER_HEIGHT; | |
71 | viewport.refresh(); | |
72 | assert.equal(viewportElement.style.height, 2 * CHARACTER_HEIGHT + 'px'); | |
73 | }); | |
74 | }); | |
75 | ||
76 | describe('syncScrollArea', () => { | |
77 | it('should sync the scroll area', done => { | |
78 | // Allow CharMeasure to be initialized | |
79 | setTimeout(() => { | |
80 | terminal.buffer.lines.push(''); | |
81 | terminal.rows = 1; | |
82 | assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px'); | |
83 | viewport.syncScrollArea(); | |
84 | assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); | |
85 | assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); | |
86 | terminal.buffer.lines.push(''); | |
87 | viewport.syncScrollArea(); | |
88 | assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px'); | |
89 | assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px'); | |
90 | done(); | |
91 | }, 0); | |
92 | }); | |
93 | }); | |
94 | }); |