From f23737a498e41a9ef2ae84fa45dbbdaaf524a174 Mon Sep 17 00:00:00 2001
From: Winnie Hellmann <winnie@gitlab.com>
Date: Mon, 8 Apr 2019 19:54:15 +0200
Subject: [PATCH] Refactor diff_spec.js to use table-based tests

---
 spec/frontend/ide/lib/diff/diff_spec.js | 93 ++++++++++++-------------
 1 file changed, 45 insertions(+), 48 deletions(-)

diff --git a/spec/frontend/ide/lib/diff/diff_spec.js b/spec/frontend/ide/lib/diff/diff_spec.js
index 57f3ac3d365..d9b088e2c12 100644
--- a/spec/frontend/ide/lib/diff/diff_spec.js
+++ b/spec/frontend/ide/lib/diff/diff_spec.js
@@ -9,60 +9,57 @@ describe('Multi-file editor library diff calculator', () => {
     });
 
     describe('modified', () => {
-      it('', () => {
-        const diff = computeDiff('123', '1234')[0];
-
-        expect(diff.added).toBeTruthy();
-        expect(diff.modified).toBeTruthy();
-        expect(diff.removed).toBeUndefined();
-      });
-
-      it('', () => {
-        const diff = computeDiff('123\n123\n123', '123\n1234\n123')[0];
-
-        expect(diff.added).toBeTruthy();
-        expect(diff.modified).toBeTruthy();
-        expect(diff.removed).toBeUndefined();
-        expect(diff.lineNumber).toBe(2);
-      });
+      it.each`
+        originalContent    | newContent          | lineNumber
+        ${'123'}           | ${'1234'}           | ${1}
+        ${'123\n123\n123'} | ${'123\n1234\n123'} | ${2}
+      `(
+        'marks line $lineNumber as added and modified but not removed',
+        ({ originalContent, newContent, lineNumber }) => {
+          const diff = computeDiff(originalContent, newContent)[0];
+
+          expect(diff.added).toBeTruthy();
+          expect(diff.modified).toBeTruthy();
+          expect(diff.removed).toBeUndefined();
+          expect(diff.lineNumber).toBe(lineNumber);
+        },
+      );
     });
 
     describe('added', () => {
-      it('', () => {
-        const diff = computeDiff('123', '123\n123')[0];
-
-        expect(diff.added).toBeTruthy();
-        expect(diff.modified).toBeUndefined();
-        expect(diff.removed).toBeUndefined();
-      });
-
-      it('', () => {
-        const diff = computeDiff('123\n123\n123', '123\n123\n1234\n123')[0];
-
-        expect(diff.added).toBeTruthy();
-        expect(diff.modified).toBeUndefined();
-        expect(diff.removed).toBeUndefined();
-        expect(diff.lineNumber).toBe(3);
-      });
+      it.each`
+        originalContent    | newContent               | lineNumber
+        ${'123'}           | ${'123\n123'}            | ${1}
+        ${'123\n123\n123'} | ${'123\n123\n1234\n123'} | ${3}
+      `(
+        'marks line $lineNumber as added but not modified and not removed',
+        ({ originalContent, newContent, lineNumber }) => {
+          const diff = computeDiff(originalContent, newContent)[0];
+
+          expect(diff.added).toBeTruthy();
+          expect(diff.modified).toBeUndefined();
+          expect(diff.removed).toBeUndefined();
+          expect(diff.lineNumber).toBe(lineNumber);
+        },
+      );
     });
 
     describe('removed', () => {
-      it('', () => {
-        const diff = computeDiff('123', '')[0];
-
-        expect(diff.added).toBeUndefined();
-        expect(diff.modified).toBeUndefined();
-        expect(diff.removed).toBeTruthy();
-      });
-
-      it('', () => {
-        const diff = computeDiff('123\n123\n123', '123\n123')[0];
-
-        expect(diff.added).toBeUndefined();
-        expect(diff.modified).toBeTruthy();
-        expect(diff.removed).toBeTruthy();
-        expect(diff.lineNumber).toBe(2);
-      });
+      it.each`
+        originalContent    | newContent    | lineNumber | modified
+        ${'123'}           | ${''}         | ${1}       | ${undefined}
+        ${'123\n123\n123'} | ${'123\n123'} | ${2}       | ${true}
+      `(
+        'marks line $lineNumber as removed',
+        ({ originalContent, newContent, lineNumber, modified }) => {
+          const diff = computeDiff(originalContent, newContent)[0];
+
+          expect(diff.added).toBeUndefined();
+          expect(diff.modified).toBe(modified);
+          expect(diff.removed).toBeTruthy();
+          expect(diff.lineNumber).toBe(lineNumber);
+        },
+      );
     });
 
     it('includes line number of change', () => {
-- 
2.30.9