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
|
/*
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { appendContentWarning } from '@/misc/append-content-warning.js';
describe(appendContentWarning, () => {
it('should return additional when original is null', () => {
const result = appendContentWarning(null, 'additional');
expect(result).toBe('additional');
});
it('should return additional when original is undefined', () => {
const result = appendContentWarning(undefined, 'additional');
expect(result).toBe('additional');
});
it('should return additional when original is empty', () => {
const result = appendContentWarning('', 'additional');
expect(result).toBe('additional');
});
it('should return original when additional is empty', () => {
const result = appendContentWarning('original', '');
expect(result).toBe('original');
});
it('should append additional when it does not exist in original', () => {
const result = appendContentWarning('original', 'additional');
expect(result).toBe('original, additional');
});
it('should append additional when it exists in original but has preceeding word', () => {
const result = appendContentWarning('notadditional', 'additional');
expect(result).toBe('notadditional, additional');
});
it('should append additional when it exists in original but has following word', () => {
const result = appendContentWarning('additionalnot', 'additional');
expect(result).toBe('additionalnot, additional');
});
it('should append additional when it exists in original multiple times but has preceeding or following word', () => {
const result = appendContentWarning('notadditional additionalnot', 'additional');
expect(result).toBe('notadditional additionalnot, additional');
});
it('should not append additional when it exists in original', () => {
const result = appendContentWarning('an additional word', 'additional');
expect(result).toBe('an additional word');
});
it('should not append additional when original starts with it', () => {
const result = appendContentWarning('additional word', 'additional');
expect(result).toBe('additional word');
});
it('should not append additional when original ends with it', () => {
const result = appendContentWarning('an additional', 'additional');
expect(result).toBe('an additional');
});
it('should not append additional when it appears multiple times', () => {
const result = appendContentWarning('an additional additional word', 'additional');
expect(result).toBe('an additional additional word');
});
it('should not append additional when it appears multiple times but some have preceeding or following', () => {
const result = appendContentWarning('a notadditional additional additionalnot word', 'additional');
expect(result).toBe('a notadditional additional additionalnot word');
});
it('should prepend additional when reverse is true', () => {
const result = appendContentWarning('original', 'additional', true);
expect(result).toBe('additional, original');
});
});
|