summaryrefslogtreecommitdiff
path: root/spec/frontend_integration/diffs/diffs_interopability_api.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend_integration/diffs/diffs_interopability_api.js')
-rw-r--r--spec/frontend_integration/diffs/diffs_interopability_api.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/frontend_integration/diffs/diffs_interopability_api.js b/spec/frontend_integration/diffs/diffs_interopability_api.js
new file mode 100644
index 00000000000..adfb93f27a2
--- /dev/null
+++ b/spec/frontend_integration/diffs/diffs_interopability_api.js
@@ -0,0 +1,25 @@
+/**
+ * This helper module contains the API expectation of the diff output HTML.
+ *
+ * This helps simulate what third-party HTML scrapers, such as Sourcegraph,
+ * should be looking for.
+ */
+export const getDiffCodePart = (codeElement) => {
+ const el = codeElement.closest('[data-interop-type]');
+
+ return el.dataset.interopType === 'old' ? 'base' : 'head';
+};
+
+export const getCodeElementFromLineNumber = (codeView, line, part) => {
+ const type = part === 'base' ? 'old' : 'new';
+
+ const el = codeView.querySelector(`[data-interop-${type}-line="${line}"]`);
+
+ return el ? el.querySelector('span.line') : null;
+};
+
+export const getLineNumberFromCodeElement = (codeElement) => {
+ const el = codeElement.closest('[data-interop-line]');
+
+ return parseInt(el.dataset.interopLine || '', 10);
+};