Skip to content

Commit c14d936

Browse files
committed
refactor(tests): naturalEditorLine to accept the line number as arg
1 parent d89c152 commit c14d936

File tree

11 files changed

+55
-111
lines changed

11 files changed

+55
-111
lines changed
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
export const naturalEditorLine = ({
2-
visualLine,
3-
}: {
4-
visualLine: number;
5-
}): number => {
6-
return visualLine - 1;
1+
export const naturalEditorLine = (visualEditorLine: number): number => {
2+
return visualEditorLine - 1;
73
};

src/test/integration/helpers/zeroBasedLine.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/test/integration/js/log-feature/class/classConstructor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
openDocument,
66
expectActiveTextEditorWithFile,
77
documentLinesChanged,
8+
NaturalEditorPosition,
89
} from '../../../helpers';
910
import { ProgrammingLanguage } from '../../../../../entities';
1011

@@ -27,8 +28,8 @@ export default (): void => {
2728
if (activeTextEditor) {
2829
activeTextEditor.selections = [
2930
new vscode.Selection(
30-
new vscode.Position(1, 14),
31-
new vscode.Position(1, 22),
31+
new NaturalEditorPosition(2, 15),
32+
new NaturalEditorPosition(2, 23),
3233
),
3334
];
3435
await vscode.commands.executeCommand(

src/test/integration/js/log-feature/class/classFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default (): void => {
2828
it('Should insert a log message related to parameter of a function inside a class', async () => {
2929
const { activeTextEditor } = vscode.window;
3030
expectActiveTextEditorWithFile(activeTextEditor, 'classFunction.js');
31-
const expectedLogMessageLine = naturalEditorLine({ visualLine: 3 });
31+
const expectedLogMessageLine = naturalEditorLine(3);
3232
if (activeTextEditor) {
3333
activeTextEditor.selections = [
3434
new vscode.Selection(

src/test/integration/js/log-feature/class/classNestedFunctions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default (): void => {
3131
activeTextEditor,
3232
'classNestedFunctions.js',
3333
);
34-
const expectedLogMessageLine = naturalEditorLine({ visualLine: 4 });
34+
const expectedLogMessageLine = naturalEditorLine(4);
3535
if (activeTextEditor) {
3636
activeTextEditor.selections = [
3737
new vscode.Selection(

src/test/integration/js/log-feature/function/anonymousFunctions.ts

Lines changed: 27 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,15 @@ export default (): void => {
4949
);
5050
const textDocument = activeTextEditor.document;
5151
expect(
52-
/\{\s*$/.test(
53-
textDocument.lineAt(naturalEditorLine({ visualLine: 3 })).text,
54-
),
52+
/\{\s*$/.test(textDocument.lineAt(naturalEditorLine(3)).text),
5553
).to.equal(true);
5654
expect(
5755
/console\.log\(.*/.test(
58-
textDocument.lineAt(naturalEditorLine({ visualLine: 4 })).text,
56+
textDocument.lineAt(naturalEditorLine(4)).text,
5957
),
6058
).to.equal(true);
6159
expect(
62-
/return /.test(
63-
textDocument.lineAt(naturalEditorLine({ visualLine: 5 })).text,
64-
),
60+
/return /.test(textDocument.lineAt(naturalEditorLine(5)).text),
6561
).to.equal(true);
6662
}
6763
});
@@ -87,24 +83,20 @@ export default (): void => {
8783
);
8884
const textDocument = activeTextEditor.document;
8985
expect(
90-
/\{\s*$/.test(
91-
textDocument.lineAt(naturalEditorLine({ visualLine: 5 })).text,
92-
),
86+
/\{\s*$/.test(textDocument.lineAt(naturalEditorLine(5)).text),
9387
).to.equal(true);
9488
expect(
9589
/console\.log\(.*/.test(
96-
textDocument.lineAt(naturalEditorLine({ visualLine: 6 })).text,
90+
textDocument.lineAt(naturalEditorLine(6)).text,
9791
),
9892
).to.equal(true);
9993
expect(
10094
/return member.include\('S'\)/.test(
101-
textDocument.lineAt(naturalEditorLine({ visualLine: 7 })).text,
95+
textDocument.lineAt(naturalEditorLine(7)).text,
10296
),
10397
).to.equal(true);
10498
expect(
105-
/}\)/.test(
106-
textDocument.lineAt(naturalEditorLine({ visualLine: 8 })).text,
107-
),
99+
/}\)/.test(textDocument.lineAt(naturalEditorLine(8)).text),
108100
).to.equal(true);
109101
}
110102
});
@@ -130,24 +122,20 @@ export default (): void => {
130122
);
131123
const textDocument = activeTextEditor.document;
132124
expect(
133-
/\{\s*$/.test(
134-
textDocument.lineAt(naturalEditorLine({ visualLine: 8 })).text,
135-
),
125+
/\{\s*$/.test(textDocument.lineAt(naturalEditorLine(8)).text),
136126
).to.equal(true);
137127
expect(
138128
/console\.log\(.*/.test(
139-
textDocument.lineAt(naturalEditorLine({ visualLine: 9 })).text,
129+
textDocument.lineAt(naturalEditorLine(9)).text,
140130
),
141131
).to.equal(true);
142132
expect(
143133
/return item.index !== original.index/.test(
144-
textDocument.lineAt(naturalEditorLine({ visualLine: 10 })).text,
134+
textDocument.lineAt(naturalEditorLine(10)).text,
145135
),
146136
).to.equal(true);
147137
expect(
148-
/}\)/.test(
149-
textDocument.lineAt(naturalEditorLine({ visualLine: 11 })).text,
150-
),
138+
/}\)/.test(textDocument.lineAt(naturalEditorLine(11)).text),
151139
).to.equal(true);
152140
}
153141
});
@@ -176,24 +164,20 @@ export default (): void => {
176164
);
177165
const textDocument = activeTextEditor.document;
178166
expect(
179-
/\{\s*$/.test(
180-
textDocument.lineAt(naturalEditorLine({ visualLine: 12 })).text,
181-
),
167+
/\{\s*$/.test(textDocument.lineAt(naturalEditorLine(12)).text),
182168
).to.equal(true);
183169
expect(
184170
/console\.log\(.*/.test(
185-
textDocument.lineAt(naturalEditorLine({ visualLine: 13 })).text,
171+
textDocument.lineAt(naturalEditorLine(13)).text,
186172
),
187173
).to.equal(true);
188174
expect(
189175
/return checkAccountingPeriodDivide\(budget._id, accountingPeriodId\)/.test(
190-
textDocument.lineAt(naturalEditorLine({ visualLine: 14 })).text,
176+
textDocument.lineAt(naturalEditorLine(14)).text,
191177
),
192178
).to.equal(true);
193179
expect(
194-
/}\)/.test(
195-
textDocument.lineAt(naturalEditorLine({ visualLine: 15 })).text,
196-
),
180+
/}\)/.test(textDocument.lineAt(naturalEditorLine(15)).text),
197181
).to.equal(true);
198182
}
199183
});
@@ -219,24 +203,20 @@ export default (): void => {
219203
);
220204
const textDocument = activeTextEditor.document;
221205
expect(
222-
/\{\s*$/.test(
223-
textDocument.lineAt(naturalEditorLine({ visualLine: 19 })).text,
224-
),
206+
/\{\s*$/.test(textDocument.lineAt(naturalEditorLine(19)).text),
225207
).to.equal(true);
226208
expect(
227209
/console\.log\(.*/.test(
228-
textDocument.lineAt(naturalEditorLine({ visualLine: 20 })).text,
210+
textDocument.lineAt(naturalEditorLine(20)).text,
229211
),
230212
).to.equal(true);
231213
expect(
232214
/return checkAccountingPeriodDivide\(budget._id\)/.test(
233-
textDocument.lineAt(naturalEditorLine({ visualLine: 21 })).text,
215+
textDocument.lineAt(naturalEditorLine(21)).text,
234216
),
235217
).to.equal(true);
236218
expect(
237-
/}\)/.test(
238-
textDocument.lineAt(naturalEditorLine({ visualLine: 23 })).text,
239-
),
219+
/}\)/.test(textDocument.lineAt(naturalEditorLine(23)).text),
240220
).to.equal(true);
241221
}
242222
});
@@ -262,24 +242,20 @@ export default (): void => {
262242
);
263243
const textDocument = activeTextEditor.document;
264244
expect(
265-
/\{\s*$/.test(
266-
textDocument.lineAt(naturalEditorLine({ visualLine: 27 })).text,
267-
),
245+
/\{\s*$/.test(textDocument.lineAt(naturalEditorLine(27)).text),
268246
).to.equal(true);
269247
expect(
270248
/console\.log\(.*/.test(
271-
textDocument.lineAt(naturalEditorLine({ visualLine: 28 })).text,
249+
textDocument.lineAt(naturalEditorLine(28)).text,
272250
),
273251
).to.equal(true);
274252
expect(
275253
/return checkAccountingPeriodDivide\(budget._id, accountingPeriodId\)/.test(
276-
textDocument.lineAt(naturalEditorLine({ visualLine: 29 })).text,
254+
textDocument.lineAt(naturalEditorLine(29)).text,
277255
),
278256
).to.equal(true);
279257
expect(
280-
/}\)/.test(
281-
textDocument.lineAt(naturalEditorLine({ visualLine: 30 })).text,
282-
),
258+
/}\)/.test(textDocument.lineAt(naturalEditorLine(30)).text),
283259
).to.equal(true);
284260
}
285261
});
@@ -305,24 +281,20 @@ export default (): void => {
305281
);
306282
const textDocument = activeTextEditor.document;
307283
expect(
308-
/\{\s*$/.test(
309-
textDocument.lineAt(naturalEditorLine({ visualLine: 35 })).text,
310-
),
284+
/\{\s*$/.test(textDocument.lineAt(naturalEditorLine(35)).text),
311285
).to.equal(true);
312286
expect(
313287
/console\.log\(.*/.test(
314-
textDocument.lineAt(naturalEditorLine({ visualLine: 36 })).text,
288+
textDocument.lineAt(naturalEditorLine(36)).text,
315289
),
316290
).to.equal(true);
317291
expect(
318292
/return checkAccountingPeriodDivide\(budget._id\)/.test(
319-
textDocument.lineAt(naturalEditorLine({ visualLine: 37 })).text,
293+
textDocument.lineAt(naturalEditorLine(37)).text,
320294
),
321295
).to.equal(true);
322296
expect(
323-
/}\)/.test(
324-
textDocument.lineAt(naturalEditorLine({ visualLine: 39 })).text,
325-
),
297+
/}\)/.test(textDocument.lineAt(naturalEditorLine(39)).text),
326298
).to.equal(true);
327299
}
328300
});

src/test/integration/js/log-feature/function/emptyFunc.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,14 @@ export default (): void => {
4141
);
4242
await Promise.all(
4343
documentLinesChanged(activeTextEditor.document, [
44-
naturalEditorLine({ visualLine: 7 }),
44+
naturalEditorLine(7),
4545
]),
4646
);
4747
const textDocument = activeTextEditor.document;
4848
expect(
49-
/\{\s*$/.test(
50-
textDocument.lineAt(naturalEditorLine({ visualLine: 7 })).text,
51-
),
49+
/\{\s*$/.test(textDocument.lineAt(naturalEditorLine(7)).text),
5250
).to.equal(true);
53-
const logMessage = textDocument.lineAt(
54-
naturalEditorLine({ visualLine: 8 }),
55-
).text;
51+
const logMessage = textDocument.lineAt(naturalEditorLine(8)).text;
5652
expect(/console\.log\(.*/.test(logMessage)).to.equal(true);
5753
}
5854
});
@@ -72,18 +68,14 @@ export default (): void => {
7268
);
7369
await Promise.all(
7470
documentLinesChanged(activeTextEditor.document, [
75-
naturalEditorLine({ visualLine: 15 }),
71+
naturalEditorLine(15),
7672
]),
7773
);
7874
const textDocument = activeTextEditor.document;
7975
expect(
80-
/\{\s*$/.test(
81-
textDocument.lineAt(naturalEditorLine({ visualLine: 14 })).text,
82-
),
76+
/\{\s*$/.test(textDocument.lineAt(naturalEditorLine(14)).text),
8377
).to.equal(true);
84-
const logMessage = textDocument.lineAt(
85-
naturalEditorLine({ visualLine: 15 }),
86-
).text;
78+
const logMessage = textDocument.lineAt(naturalEditorLine(15)).text;
8779
expect(/console\.log\(.*/.test(logMessage)).to.equal(true);
8880
}
8981
});

src/test/integration/js/log-feature/function/functionAssignedToVariable.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default (): void => {
3131
activeTextEditor,
3232
'functionAssignedToVariable.ts',
3333
);
34-
const expectedLogMessageLine = naturalEditorLine({ visualLine: 6 });
34+
const expectedLogMessageLine = naturalEditorLine(6);
3535
if (activeTextEditor) {
3636
const textDocument = activeTextEditor.document;
3737
activeTextEditor.selection = new vscode.Selection(
@@ -60,7 +60,7 @@ export default (): void => {
6060
activeTextEditor,
6161
'functionAssignedToVariable.ts',
6262
);
63-
const expectedLogMessageLine = naturalEditorLine({ visualLine: 10 });
63+
const expectedLogMessageLine = naturalEditorLine(10);
6464
if (activeTextEditor) {
6565
const textDocument = activeTextEditor.document;
6666
activeTextEditor.selection = new vscode.Selection(
@@ -89,7 +89,7 @@ export default (): void => {
8989
activeTextEditor,
9090
'functionAssignedToVariable.ts',
9191
);
92-
const expectedLogMessageLine = naturalEditorLine({ visualLine: 17 });
92+
const expectedLogMessageLine = naturalEditorLine(17);
9393
if (activeTextEditor) {
9494
const textDocument = activeTextEditor.document;
9595
activeTextEditor.selection = new vscode.Selection(
@@ -118,7 +118,7 @@ export default (): void => {
118118
activeTextEditor,
119119
'functionAssignedToVariable.ts',
120120
);
121-
const expectedLogMessageLine = naturalEditorLine({ visualLine: 19 });
121+
const expectedLogMessageLine = naturalEditorLine(19);
122122
if (activeTextEditor) {
123123
const textDocument = activeTextEditor.document;
124124
activeTextEditor.selection = new vscode.Selection(

src/test/integration/js/log-feature/function/functionWithDecorators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default (): void => {
3131
activeTextEditor,
3232
'functionWithDecorators.ts',
3333
);
34-
const expectedLogMessageLine = naturalEditorLine({ visualLine: 14 });
34+
const expectedLogMessageLine = naturalEditorLine(14);
3535
if (activeTextEditor) {
3636
activeTextEditor.selections = [
3737
new vscode.Selection(

src/test/integration/js/log-feature/function/promiseAnonymousFunction.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ export default (): void => {
4444
);
4545
await Promise.all(
4646
documentLinesChanged(activeTextEditor.document, [
47-
naturalEditorLine({ visualLine: 7 }),
47+
naturalEditorLine(7),
4848
]),
4949
);
5050
expect(
5151
/console\.log\(.*/.test(
52-
activeTextEditor.document.lineAt(
53-
naturalEditorLine({ visualLine: 7 }),
54-
).text,
52+
activeTextEditor.document.lineAt(naturalEditorLine(7)).text,
5553
),
5654
).to.equal(true);
5755
activeTextEditor.selections = [
@@ -66,14 +64,12 @@ export default (): void => {
6664
);
6765
await Promise.all(
6866
documentLinesChanged(activeTextEditor.document, [
69-
naturalEditorLine({ visualLine: 9 }),
67+
naturalEditorLine(9),
7068
]),
7169
);
7270
expect(
7371
/console\.log\(.*/.test(
74-
activeTextEditor.document.lineAt(
75-
naturalEditorLine({ visualLine: 9 }),
76-
).text,
72+
activeTextEditor.document.lineAt(naturalEditorLine(9)).text,
7773
),
7874
).to.equal(true);
7975
}

0 commit comments

Comments
 (0)