1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 01:47:01 +03:00

Make the dedupe tests pass

This commit is contained in:
Timothy Clem 2017-02-14 11:53:25 -08:00
parent 1facca0b50
commit 94f606da81
5 changed files with 100 additions and 3 deletions

View File

@ -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

View File

@ -0,0 +1,3 @@
function myFunction() {
return 0;
}

View File

@ -0,0 +1,6 @@
function myFunction() {
if (true) {
console.log();
}
return 1;
}

View File

@ -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()
}
})

View File

@ -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)
})
}
})