Skip to content

Commit 1274fc3

Browse files
committed
Test merging lines to str in serial monitor utils
Adds a test for merging one or more lines to a single string. It is supposed to just concatenate the content of the lines, without doing anything else. This method is used when copying the serial monitor content to the clipboard.
1 parent 2df3f46 commit 1274fc3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

arduino-ide-extension/src/test/browser/monitor-utils.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect } from 'chai';
22
import {
33
messagesToLines,
44
truncateLines,
5+
linesToMergedStr,
56
} from '../../browser/serial/monitor/monitor-utils';
67
import { Line } from '../../browser/serial/monitor/serial-monitor-send-output';
78
import { set, reset } from 'mockdate';
@@ -15,13 +16,15 @@ type TestLine = {
1516
charCount: number;
1617
maxCharacters?: number;
1718
};
19+
expectedMerged?: string;
1820
};
1921

2022
const date = new Date();
2123
const testLines: TestLine[] = [
2224
{
2325
messages: ['Hello'],
2426
expected: { lines: [{ message: 'Hello', lineLen: 5 }], charCount: 5 },
27+
expectedMerged: 'Hello',
2528
},
2629
{
2730
messages: ['Hello', 'Dog!'],
@@ -36,6 +39,7 @@ const testLines: TestLine[] = [
3639
],
3740
charCount: 10,
3841
},
42+
expectedMerged: 'Hello\nDog!'
3943
},
4044
{
4145
messages: ['Dog!'],
@@ -67,6 +71,7 @@ const testLines: TestLine[] = [
6771
{ message: "You're a good boy!", lineLen: 8 },
6872
],
6973
},
74+
expectedMerged: "Hello Dog!\n Who's a good boy?\nYou're a good boy!",
7075
},
7176
{
7277
messages: ['boy?\n', "You're a good boy!"],
@@ -116,6 +121,7 @@ const testLines: TestLine[] = [
116121
{ message: 'Yo', lineLen: 2 },
117122
],
118123
},
124+
expectedMerged: "Hello Dog!\nWho's a good boy?\nYo",
119125
},
120126
];
121127

@@ -165,6 +171,10 @@ describe('Monitor Utils', () => {
165171
});
166172
expect(totalCharCount).to.equal(charCount);
167173
}
174+
if (testLine.expectedMerged) {
175+
const merged_str = linesToMergedStr(testLine.expected.lines);
176+
expect(merged_str).to.equal(testLine.expectedMerged);
177+
}
168178
});
169179
});
170180
});

0 commit comments

Comments
 (0)