-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from alphagov/add-linter
Add linter to govuk browser extension
- Loading branch information
Showing
26 changed files
with
3,773 additions
and
1,149 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
{ | ||
"devDependencies": { | ||
"jasmine-browser-runner": "^2.3.0", | ||
"jasmine-core": "^5.1.1" | ||
"jasmine-core": "^5.1.1", | ||
"standardx": "^7.0.0" | ||
}, | ||
"scripts": { | ||
"lint:js": "standardx 'spec/javascripts/**/*.js' 'src/**/*.js'", | ||
"lint:js:fix": "npm run lint:js --fix", | ||
"test": "jasmine-browser-runner runSpecs", | ||
"build": "bash build.sh" | ||
}, | ||
"eslintConfig": { | ||
"env": { | ||
"browser": true, | ||
"jasmine": true | ||
}, | ||
"rules":{ | ||
"no-var": 0, | ||
"no-unused-vars": 0, | ||
"no-use-before-define": 0 | ||
} | ||
}, | ||
"standardx": { | ||
"global": [ | ||
"chrome", | ||
"Mustache", | ||
"fetch", | ||
"Popup", | ||
"pluck" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
function pluck(array, key) { | ||
function pluck (array, key) { | ||
return array.map(function (object) { | ||
return object[key]; | ||
return object[key] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
if (!String.prototype.startsWith) { | ||
String.prototype.startsWith = function(searchString, position){ | ||
return this.substr(position || 0, searchString.length) === searchString; | ||
}; | ||
String.prototype.startsWith = function (searchString, position) { | ||
return this.substr(position || 0, searchString.length) === searchString | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,73 @@ | ||
describe("Popup.findActiveAbTests", function () { | ||
it("returns no A/B tests if none are active", function () { | ||
var abTests = Popup.findActiveAbTests({}); | ||
describe('Popup.findActiveAbTests', function () { | ||
it('returns no A/B tests if none are active', function () { | ||
var abTests = Popup.findActiveAbTests({}) | ||
|
||
expect(abTests).toEqual([]); | ||
}); | ||
expect(abTests).toEqual([]) | ||
}) | ||
|
||
it("finds all A/B tests", function () { | ||
it('finds all A/B tests', function () { | ||
var abTests = Popup.findActiveAbTests({ | ||
"first-AB-test-name": { | ||
currentBucket: "some-value", | ||
allowedBuckets: ["some-value", "B"] | ||
'first-AB-test-name': { | ||
currentBucket: 'some-value', | ||
allowedBuckets: ['some-value', 'B'] | ||
}, | ||
"second-AB-test-name": { | ||
currentBucket: "other-value", | ||
allowedBuckets: ["other-value", "B"] | ||
'second-AB-test-name': { | ||
currentBucket: 'other-value', | ||
allowedBuckets: ['other-value', 'B'] | ||
}, | ||
"third-AB-test-name": { | ||
currentBucket: "yet-another-value", | ||
allowedBuckets: ["A", "yet-another-value"] | ||
'third-AB-test-name': { | ||
currentBucket: 'yet-another-value', | ||
allowedBuckets: ['A', 'yet-another-value'] | ||
} | ||
}); | ||
}) | ||
|
||
expect(abTests.length).toEqual(3); | ||
expect(abTests[0].testName).toEqual("first-AB-test-name"); | ||
expect(abTests[1].testName).toEqual("second-AB-test-name"); | ||
expect(abTests[2].testName).toEqual("third-AB-test-name"); | ||
}); | ||
expect(abTests.length).toEqual(3) | ||
expect(abTests[0].testName).toEqual('first-AB-test-name') | ||
expect(abTests[1].testName).toEqual('second-AB-test-name') | ||
expect(abTests[2].testName).toEqual('third-AB-test-name') | ||
}) | ||
|
||
it("returns A and B buckets", function () { | ||
it('returns A and B buckets', function () { | ||
var abTests = Popup.findActiveAbTests({ | ||
"some-AB-test-name": { | ||
currentBucket: "A", | ||
allowedBuckets: ["A", "B"] | ||
'some-AB-test-name': { | ||
currentBucket: 'A', | ||
allowedBuckets: ['A', 'B'] | ||
} | ||
}); | ||
}) | ||
|
||
expect(abTests[0].buckets.length).toEqual(2); | ||
expect(abTests[0].buckets[0].bucketName).toEqual("A"); | ||
expect(abTests[0].buckets[1].bucketName).toEqual("B"); | ||
expect(abTests[0].buckets.length).toEqual(2) | ||
expect(abTests[0].buckets[0].bucketName).toEqual('A') | ||
expect(abTests[0].buckets[1].bucketName).toEqual('B') | ||
}) | ||
|
||
it("highlights 'A' bucket if user is in 'A' group", function () { | ||
var abTests = Popup.findActiveAbTests({ | ||
"some-AB-test-name": { | ||
currentBucket: "B", | ||
allowedBuckets: ["A", "B"] | ||
'some-AB-test-name': { | ||
currentBucket: 'B', | ||
allowedBuckets: ['A', 'B'] | ||
}, | ||
"other-AB-test-name": { | ||
currentBucket: "A", | ||
allowedBuckets: ["A", "B"] | ||
'other-AB-test-name': { | ||
currentBucket: 'A', | ||
allowedBuckets: ['A', 'B'] | ||
} | ||
}); | ||
}) | ||
|
||
expect(abTests[0].buckets[0].class).toEqual(""); | ||
expect(abTests[0].buckets[1].class).toEqual("ab-bucket-selected"); | ||
expect(abTests[0].buckets[0].class).toEqual('') | ||
expect(abTests[0].buckets[1].class).toEqual('ab-bucket-selected') | ||
|
||
expect(abTests[1].buckets[0].class).toEqual("ab-bucket-selected"); | ||
expect(abTests[1].buckets[1].class).toEqual(""); | ||
}); | ||
expect(abTests[1].buckets[0].class).toEqual('ab-bucket-selected') | ||
expect(abTests[1].buckets[1].class).toEqual('') | ||
}) | ||
|
||
it("doesn't highlight any buckets if variant is unknown", function () { | ||
var abTests = Popup.findActiveAbTests({ | ||
"some-AB-test-name": { | ||
currentBucket: "Unknown", | ||
allowedBuckets: ["A", "B"] | ||
'some-AB-test-name': { | ||
currentBucket: 'Unknown', | ||
allowedBuckets: ['A', 'B'] | ||
} | ||
}); | ||
}) | ||
|
||
expect(abTests[0].buckets[0].class).toEqual(""); | ||
expect(abTests[0].buckets[1].class).toEqual(""); | ||
}); | ||
}); | ||
expect(abTests[0].buckets[0].class).toEqual('') | ||
expect(abTests[0].buckets[1].class).toEqual('') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,43 @@ | ||
"use strict"; | ||
describe("Toggling design mode", function () { | ||
var designModeBannerId = "govuk-chrome-toolkit-design-mode-banner"; | ||
var designModeBannerElement; | ||
var designModeComponent; | ||
'use strict' | ||
/* global DesignModeComponent */ | ||
|
||
describe('Toggling design mode', function () { | ||
var designModeBannerId = 'govuk-chrome-toolkit-design-mode-banner' | ||
var designModeBannerElement | ||
var designModeComponent | ||
|
||
beforeEach(function () { | ||
// Mock addListener function to call toggleDesignMode trigger when initialized | ||
window.chrome = { | ||
runtime: { | ||
onMessage: { | ||
addListener: function(callback) { | ||
addListener: function (callback) { | ||
/* eslint-disable-next-line */ | ||
callback({ trigger: 'toggleDesignMode' }) | ||
} | ||
}, | ||
sendMessage: function(){} | ||
sendMessage: function () {} | ||
} | ||
}; | ||
designModeComponent = new DesignModeComponent; | ||
} | ||
designModeComponent = new DesignModeComponent() | ||
designModeBannerElement = document.querySelector(`#${designModeBannerId}`) | ||
}); | ||
}) | ||
|
||
it("shows design mode banner", function () { | ||
expect(designModeBannerElement.textContent).toMatch(/You are in design mode./); | ||
}); | ||
it('shows design mode banner', function () { | ||
expect(designModeBannerElement.textContent).toMatch(/You are in design mode./) | ||
}) | ||
|
||
it("removes the banner when toggled off", function () { | ||
designModeComponent.toggleDesignMode(); | ||
expect(designModeBannerElement).not.toBeVisible(); | ||
}); | ||
it('removes the banner when toggled off', function () { | ||
designModeComponent.toggleDesignMode() | ||
expect(designModeBannerElement).not.toBeVisible() | ||
}) | ||
|
||
it("design mode is on when toggled on", function () { | ||
expect(window.document.designMode).toEqual("on"); | ||
}); | ||
it('design mode is on when toggled on', function () { | ||
expect(window.document.designMode).toEqual('on') | ||
}) | ||
|
||
it("design mode is off when toggled off", function () { | ||
designModeComponent.toggleDesignMode(); | ||
expect(window.document.designMode).toEqual("off"); | ||
}); | ||
}); | ||
it('design mode is off when toggled off', function () { | ||
designModeComponent.toggleDesignMode() | ||
expect(window.document.designMode).toEqual('off') | ||
}) | ||
}) |
Oops, something went wrong.