Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do not merge] Standard JS linting with automatic fixes #371

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
@@ -1 +1 @@
//= require_tree ./modules
// = require_tree ./modules
26 changes: 13 additions & 13 deletions app/assets/javascripts/modules/ukvi_ab_test.js
@@ -1,4 +1,4 @@
//= require govuk/multivariate-test
// = require govuk/multivariate-test
window.GOVUK = window.GOVUK || {}
window.GOVUK.Modules = window.GOVUK.Modules || {};

Expand All @@ -8,31 +8,31 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
GOVUK.Modules.UkviAbTest = function () {
this.start = function ($el) {
var testType = $el.data('test-type'),
testLabel = $el.data('test-label'),
newContent = $el.html(),
testCallback = testType === "overview" ? updateOverviewSection : UpdateKnowledgeOfEnglishSection;
testLabel = $el.data('test-label'),
newContent = $el.html(),
testCallback = testType === 'overview' ? updateOverviewSection : UpdateKnowledgeOfEnglishSection

new GOVUK.MultivariateTest({
name: testLabel,
cookieDuration: 30, // set cookie expiry to 30 days
customDimensionIndex: [13, 14],
cohorts: {
original: { callback: function() {}, weight: 50},
original: { callback: function () {}, weight: 50},
spouseProminent: {
callback: testCallback,
weight: 50
}
}
});
})

function updateOverviewSection() {
$("#exceptions").prevAll().hide();
$("#exceptions").before(newContent);
function updateOverviewSection () {
$('#exceptions').prevAll().hide()
$('#exceptions').before(newContent)
}

function UpdateKnowledgeOfEnglishSection() {
$("#exemptions").prevAll().hide();
$("#exemptions").before(newContent);
function UpdateKnowledgeOfEnglishSection () {
$('#exemptions').prevAll().hide()
$('#exemptions').before(newContent)
}
}
}
Expand Down
17 changes: 8 additions & 9 deletions app/assets/javascripts/webchat.js
Expand Up @@ -4,27 +4,26 @@

var $ = window.$


EGAIN_NORMALISATION = {
0: "AVAILABLE",
1: "UNAVAILABLE",
2: "BUSY"
0: 'AVAILABLE',
1: 'UNAVAILABLE',
2: 'BUSY'
}

var webChatNormalise = function(res){
var webChatNormalise = function (res) {
var $xml = $(res)
var proxyResponse = parseInt($xml.find('checkEligibility').attr('responseType'), 10)
var response = EGAIN_NORMALISATION[proxyResponse]
if (!response) {
return {
status: "failure",
response: "unknown"
status: 'failure',
response: 'unknown'
}
}

return {
status: "success",
response: response
status: 'success',
response: response
}
}

Expand Down
33 changes: 16 additions & 17 deletions app/assets/javascripts/webchat/library.js
Expand Up @@ -5,24 +5,23 @@
if (typeof global.GOVUK === 'undefined') { global.GOVUK = {} }
var GOVUK = global.GOVUK


function Webchat (options) {
var POLL_INTERVAL = 15 * 1000
var AJAX_TIMEOUT = 5 * 1000
var AJAX_TIMEOUT = 5 * 1000
var API_STATES = [
"BUSY",
"UNAVAILABLE",
"AVAILABLE",
"ERROR"
'BUSY',
'UNAVAILABLE',
'AVAILABLE',
'ERROR'
]
var $el = $(options.$el)
var openUrl = $el.attr('data-open-url')
var availabilityUrl = $el.attr('data-availability-url')
var $openButton = $el.find('.js-webchat-open-button')
var webchatStateClass = 'js-webchat-advisers-'
var responseNormaliser = options.responseNormaliser
var intervalID = null
var lastRecordedState = null
var $el = $(options.$el)
var openUrl = $el.attr('data-open-url')
var availabilityUrl = $el.attr('data-availability-url')
var $openButton = $el.find('.js-webchat-open-button')
var webchatStateClass = 'js-webchat-advisers-'
var responseNormaliser = options.responseNormaliser
var intervalID = null
var lastRecordedState = null

function init () {
if (!availabilityUrl || !openUrl) throw 'urls for webchat not defined'
Expand Down Expand Up @@ -51,8 +50,8 @@
function apiSuccess (result) {
if (responseNormaliser) result = responseNormaliser(result)

var validState = API_STATES.indexOf(result.response) != -1
var state = validState ? result.response : "ERROR"
var validState = API_STATES.indexOf(result.response) != -1
var state = validState ? result.response : 'ERROR'
advisorStateChange(state)
}

Expand All @@ -63,7 +62,7 @@

function advisorStateChange (state) {
state = state.toLowerCase()
var currentState = $el.find("." + webchatStateClass + state)
var currentState = $el.find('.' + webchatStateClass + state)
$el.find('[class^="' + webchatStateClass + '"]').addClass('hidden')
currentState.removeClass('hidden')
trackEvent(state)
Expand Down
37 changes: 17 additions & 20 deletions spec/javascripts/webchat.spec.js
Expand Up @@ -30,15 +30,14 @@ describe('Webchat', function () {
}
}


var jsonNormalisedAvailable = jsonNormalised("success","AVAILABLE")
var jsonNormalisedUnavailable = jsonNormalised("success","UNAVAILABLE")
var jsonNormalisedBusy = jsonNormalised("success","BUSY")
var jsonNormalisedAvailable = jsonNormalised('success', 'AVAILABLE')
var jsonNormalisedUnavailable = jsonNormalised('success', 'UNAVAILABLE')
var jsonNormalisedBusy = jsonNormalised('success', 'BUSY')
var jsonNormalisedError = '404 not found'

var jsonMangledAvailable = jsonNormalised("success","FOOAVAILABLE")
var jsonMangledUnavailable = jsonNormalised("success","FOOUNAVAILABLE")
var jsonMangledBusy = jsonNormalised("success","FOOBUSY")
var jsonMangledAvailable = jsonNormalised('success', 'FOOAVAILABLE')
var jsonMangledUnavailable = jsonNormalised('success', 'FOOUNAVAILABLE')
var jsonMangledBusy = jsonNormalised('success', 'FOOBUSY')
var jsonMangledError = 'FOO404 not found'

beforeEach(function () {
Expand All @@ -50,7 +49,6 @@ describe('Webchat', function () {
$advisersError = $webchat.find('.js-webchat-advisers-error')
})


describe('on valid application locations that are pre normalised', function () {
function mount () {
$webchat.map(function () {
Expand Down Expand Up @@ -126,11 +124,11 @@ describe('Webchat', function () {
jsonNormalisedError,
jsonNormalisedError
]
var analyticsExpects = ['available','error']
var analyticsExpects = ['available', 'error']
var analyticsReceived = []
returnsNumber = 0
analyticsCalled = 0
var clock = lolex.install();
var clock = lolex.install()
spyOn($, 'ajax').and.callFake(function (options) {
options.success(returns[returnsNumber])
returnsNumber++
Expand All @@ -148,18 +146,18 @@ describe('Webchat', function () {
expect($advisersError.hasClass('hidden')).toBe(true)
expect($advisersUnavailable.hasClass('hidden')).toBe(true)

clock.tick("31");
clock.tick('31')

expect($advisersError.hasClass('hidden')).toBe(false)
expect($advisersAvailable.hasClass('hidden')).toBe(true)
expect($advisersBusy.hasClass('hidden')).toBe(true)
expect($advisersUnavailable.hasClass('hidden')).toBe(true)
expect(analyticsCalled).toBe(2)
expect(analyticsReceived).toEqual(analyticsExpects)
clock.tick("31");
clock.tick('31')
expect(analyticsCalled).toBe(2)
expect(analyticsReceived).toEqual(analyticsExpects)
clock.uninstall();
clock.uninstall()
})
})

Expand All @@ -172,11 +170,11 @@ describe('Webchat', function () {
pollingEnabled: true,
endPoints: {
openUrl: CHILD_BENEFIT_API_URL,
proxyUrl: CHILD_BENEFIT_API_URL,
proxyUrl: CHILD_BENEFIT_API_URL
},
responseNormaliser: function(res){
res.response = (res.response) ? res.response.replace("FOO", "") : ""
return res;
responseNormaliser: function (res) {
res.response = (res.response) ? res.response.replace('FOO', '') : ''
return res
}
})
})
Expand Down Expand Up @@ -240,7 +238,6 @@ describe('Webchat', function () {
})

describe('egain normalisaton', function () {

var egainResponse = function (responseType) {
return $.parseXML(
'<checkEligibility ' +
Expand All @@ -259,8 +256,8 @@ describe('Webchat', function () {
expect(webChatNormalise(egainResponse(1))).toEqual(jsonNormalisedUnavailable)
expect(webChatNormalise(egainResponse(2))).toEqual(jsonNormalisedBusy)
expect(webChatNormalise(egainResponse(3))).toEqual({
status: "failure",
response: "unknown"
status: 'failure',
response: 'unknown'
})
})
})
Expand Down