From 94f606da8128bce2192800d31707d9a300e04937 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 14 Feb 2017 11:53:25 -0800 Subject: [PATCH] Make the dedupe tests pass --- test/TOCSpec.hs | 11 ++++-- test/corpus/toc/javascript/dupParent.A.js | 3 ++ test/corpus/toc/javascript/dupParent.B.js | 6 +++ test/corpus/toc/javascript/test.A.js | 38 +++++++++++++++++++ test/corpus/toc/javascript/test.B.js | 45 +++++++++++++++++++++++ 5 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 test/corpus/toc/javascript/dupParent.A.js create mode 100644 test/corpus/toc/javascript/dupParent.B.js create mode 100644 test/corpus/toc/javascript/test.A.js create mode 100644 test/corpus/toc/javascript/test.B.js diff --git a/test/TOCSpec.hs b/test/TOCSpec.hs index 9109259d9..a5614a568 100644 --- a/test/TOCSpec.hs +++ b/test/TOCSpec.hs @@ -29,10 +29,15 @@ spec = parallel $ do it "blank if there are no methods" $ diffTOC blobs blankDiff `shouldBe` [ ] - it "summarizes methods" $ do - sourceBlobs <- blobsForPaths (both "/Users/tclem/github/semantic-diff/test.A.js" "/Users/tclem/github/semantic-diff/test.B.js") + it "dedupes changes in same parent method" $ do + sourceBlobs <- blobsForPaths (both "test/corpus/toc/javascript/dupParent.A.js" "test/corpus/toc/javascript/dupParent.B.js") diff <- testDiff sourceBlobs - diffTOC sourceBlobs diff `shouldBe` [ ] + diffTOC sourceBlobs diff `shouldBe` [ JSONSummary $ InSummarizable Category.Function "myFunction" (sourceSpanBetween (1, 1) (6, 2)) ] + + it "dedupes similar methods" $ do + sourceBlobs <- blobsForPaths (both "test/corpus/toc/javascript/test.A.js" "test/corpus/toc/javascript/test.B.js") + diff <- testDiff sourceBlobs + diffTOC sourceBlobs diff `shouldBe` [ JSONSummary $ Summarizable Category.Function "performHealthCheck" (sourceSpanBetween (8, 1) (29, 2)) "modified" ] testDiff :: Both SourceBlob -> IO (Diff (Syntax Text) (Record '[Cost, Range, Category, SourceSpan])) testDiff sourceBlobs = do diff --git a/test/corpus/toc/javascript/dupParent.A.js b/test/corpus/toc/javascript/dupParent.A.js new file mode 100644 index 000000000..1f3e01f84 --- /dev/null +++ b/test/corpus/toc/javascript/dupParent.A.js @@ -0,0 +1,3 @@ +function myFunction() { + return 0; +} diff --git a/test/corpus/toc/javascript/dupParent.B.js b/test/corpus/toc/javascript/dupParent.B.js new file mode 100644 index 000000000..3145f834f --- /dev/null +++ b/test/corpus/toc/javascript/dupParent.B.js @@ -0,0 +1,6 @@ +function myFunction() { + if (true) { + console.log(); + } + return 1; +} diff --git a/test/corpus/toc/javascript/test.A.js b/test/corpus/toc/javascript/test.A.js new file mode 100644 index 000000000..251e61ef0 --- /dev/null +++ b/test/corpus/toc/javascript/test.A.js @@ -0,0 +1,38 @@ +/* @flow */ + +import $ from '../jquery' +import cast from '../typecast' +import {on} from 'delegated-events' +import {submit} from '../form' + +let allowSubmit = false + +function performHealthcheck() { + const repoName = cast(document.getElementById('showcase_item_name_with_owner'), HTMLInputElement).value + const submitButton = cast(document.getElementById('submit'), HTMLButtonElement) + const hiddenForm = cast(document.getElementsByClassName('js-submit-health-check')[0], HTMLFormElement) + const targetRepoName = cast(document.getElementById('repo_name'), HTMLInputElement) + document.getElementById("js-health").innerHTML = "Performing health check..." + targetRepoName.value = repoName + submitButton.disabled = false + allowSubmit = true + submit(hiddenForm) +} + +on('submit', '#new_showcase_item', function(e) { + if (!allowSubmit) { e.preventDefault() } +}) + +$(document).on('ajaxSuccess', '.js-health', function(event, xhr, settings, data) { + this.innerHTML = data +}) + +on('focusout', '#showcase_item_name_with_owner', function() { + performHealthcheck() +}) + +on('focusin', '#showcase_item_body', function() { + if (cast(document.getElementById('showcase_item_name_with_owner'), HTMLInputElement).type === 'hidden') { + performHealthcheck() + } +}) diff --git a/test/corpus/toc/javascript/test.B.js b/test/corpus/toc/javascript/test.B.js new file mode 100644 index 000000000..b91cdd649 --- /dev/null +++ b/test/corpus/toc/javascript/test.B.js @@ -0,0 +1,45 @@ +/* @flow */ + +import cast from '../typecast' +import {changeValue} from '../form' +import {fetchSafeDocumentFragment} from '../fetch' +import {observe} from '../observe' + +function performHealthCheck(container, repoName) { + const formCheck = cast(document.querySelector('.js-repo-health-check'), HTMLFormElement) + const nameToCheck = cast(formCheck.querySelector('.js-repo-health-name'), HTMLInputElement) + nameToCheck.value = repoName + + const completedIndicator = cast(container.querySelector('.js-repo-health-check-completed'), HTMLInputElement) + changeValue(completedIndicator, '') + container.classList.remove('d-none') + container.classList.add('is-loading') + + return fetchSafeDocumentFragment(document, formCheck.action, { + method: 'POST', + body: new FormData(formCheck), + }).then(html => { + const results = cast(container.querySelector('.js-repo-health-results'), HTMLElement) + results.innerHTML = '' + results.appendChild(html) + + container.classList.remove('is-loading') + changeValue(completedIndicator, '1') + }) +} + +observe('.js-repo-health', function(container: HTMLElement) { + const form = cast(container.closest('form'), HTMLFormElement) + const repoInput = cast(form.querySelector('.js-repo-name'), HTMLInputElement) + + if (repoInput.type === 'hidden') { + const description = cast(form.querySelector('.js-comment-field'), HTMLTextAreaElement) + description.addEventListener('focus', () => { + performHealthCheck(container, repoInput.value) + }) + } else { + repoInput.addEventListener('change', () => { + performHealthCheck(container, repoInput.value) + }) + } +})