-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextTyper.test.js
More file actions
114 lines (108 loc) · 3.88 KB
/
TextTyper.test.js
File metadata and controls
114 lines (108 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { checkResult } from "./TextTyper";
import TextTyper from "./TextTyper.js";
const typer = new TextTyper();
/**
* Test Strategy for getTextInputComparison(origin, target)
* - partitions of input:
* 1. origin.len = 0, 1, n
* 2. target.len = 0, 1, n
* 3. origin.len >, =, < than target.len
* 4. when target is completely same with origin
* 5. when target is partially same with origin
* 6. when target is completely different from origin
*
* - test cases
* 1. (origin.len = 0, target.len = 0) => []
* 2. (origin.len = 1, target.len = n) and when target === origin => [SAME]
* 3. (origin.len = n, target.len = 1) and when target !== origin => [DIFF, NONE, NONE...]
* 4. (origin.len = n, target.len = n) and when target is partially diff from origin => [variant checkResults]
*/
describe("getTextInputComparisonTest", () => {
test("test case (origin.len, target.len) = (0, 0)", () => {
const result = typer.getTextInputComparison("", "");
expect(result.length).toBe(0);
});
test(`test case (origin.len, target.len) = (1, more) and when target === origin`, () => {
const result = typer.getTextInputComparison("a", "abbb");
expect(result).toMatchObject([checkResult.SAME]);
});
test(`test case (origin.len = n, target.len = 1) and when target !== origin`, () => {
const result = typer.getTextInputComparison("abcde", "b");
const expected = [
checkResult.DIFF,
checkResult.NONE,
checkResult.NONE,
checkResult.NONE,
checkResult.NONE,
];
expect(result).toMatchObject(expected);
});
test(`test case (origin.len = n, target.len = n) and when target is partially diff from origin`, () => {
const result = typer.getTextInputComparison(
"abcd123asdf999 ",
"aecdkk3asdfew"
);
const expected = [
checkResult.SAME,
checkResult.DIFF,
checkResult.SAME,
checkResult.SAME,
checkResult.DIFF,
checkResult.DIFF,
checkResult.SAME,
checkResult.SAME,
checkResult.SAME,
checkResult.SAME,
checkResult.SAME,
checkResult.DIFF,
checkResult.DIFF,
checkResult.NONE,
checkResult.NONE,
];
expect(result).toMatchObject(expected);
});
});
/**
* Test Strategy for getStyledTyperText(plainText, textInputComparison)
* - partitions of input:
* 1. plainText.len = 0, 1, n
* 2. plainText.len ==, != textInputComparison.len
* 3. when textInputComparison contains checkResult.SAME
* 4. when textInputComparison contains checkResult.DIFF
* 5. when textInputComparison contains checkResult.NONE
*
* - test cases
* 1. (plainText.len = 0, checkResult.len = 0) => ""
* 2. (plainText.len = 1, checkResult.len = 2) => Err: "ComparisonLengthUnmatch"
* 3. plainText.len = n and when textInputComparison contains checkResult.SAME .DIFF .NONE => styledText
*/
describe("getStyledTyperTextTest", () => {
test("test case length 0", () => {
const emptyComparison = new Array();
const result = typer.getStyledTyperText("", emptyComparison);
expect(result.length).toBe(0);
});
test("test case length unmatch", () => {
try {
const result = typer.getStyledTyperText("a", [
checkResult.SAME,
checkResult.DIFF,
]);
} catch (e) {
expect(e.message).toBe("ComparisonLengthUnmatch");
}
});
test("plainText.len = n and when textInputComparison contains checkResult.SAME .DIFF .NONE", () => {
const result = typer.getStyledTyperText("abcdef", [
checkResult.SAME,
checkResult.DIFF,
checkResult.DIFF,
checkResult.SAME,
checkResult.SAME,
checkResult.NONE,
]);
expect(result).toBe(
`<span style="color: green;">a</span><span style="color: red;">b</span><span style="color: red;">c</span><span style="color: green;">d</span><span style="color: green;">e</span>f`
);
});
});