Skip to content

Commit

Permalink
Update JS test dependencies and spec (fixes mozilla#10492) (mozilla#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgibson authored Sep 23, 2021
1 parent 6f93237 commit ad50a98
Show file tree
Hide file tree
Showing 26 changed files with 995 additions and 1,161 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ module.exports = {
}
},
{
// JS files served only to Firefox browsers.
// JS files where we support native modern JS.
files: [
'media/js/firefox/welcome/**/*.js',
'media/js/firefox/whatsnew/**/*.js',
'media/js/firefox/firstrun/**/*.js',
'tests/unit/**/*.js'
],
env: {
'es2017': true
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"browser-sync-webpack-plugin": "^2.2.2",
"concurrently": "^6.0.1",
"eslint-plugin-json": "^2.1.1",
"jasmine-core": "3.4.0",
"jasmine-core": "3.9.0",
"karma": "^6.3.2",
"karma-chrome-launcher": "3.1.0",
"karma-firefox-launcher": "1.2.0",
"karma-jasmine": "2.0.1",
"karma-firefox-launcher": "2.1.1",
"karma-jasmine": "4.0.1",
"karma-sourcemap-loader": "^0.3.8",
"karma-webpack": "^5.0.0",
"sinon": "7.4.1",
"sinon": "11.1.2",
"svgo": "^1.2.2",
"tinypng-cli": "^0.0.7"
},
Expand Down
27 changes: 13 additions & 14 deletions tests/unit/spec/base/core-datalayer-page-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,50 @@ describe('core-datalayer-page-id.js', function() {
window.Mozilla.Cookies.removeItem = sinon.stub();
});

describe('getPageId', function(){
var html = document.documentElement;
describe('getPageId', function() {
const html = document.documentElement;

afterEach(function() {
html.removeAttribute('data-gtm-page-id');
});

it('will grab data-gtm-page-id value if present on <html> element', function(){
it('will grab data-gtm-page-id value if present on <html> element', function() {
html.setAttribute('data-gtm-page-id', 'test');

expect(Mozilla.Analytics.getPageId('/en-US/firefox/new/')).toBe('test');
});

it('will grab the pathname minus the first directory if no data-gtm-page-id value is present on <html> element', function(){
it('will grab the pathname minus the first directory if no data-gtm-page-id value is present on <html> element', function() {
expect(Mozilla.Analytics.getPageId('/en-US/firefox/new/')).toBe('/firefox/new/');
});

it('will return the full page path when no data-gtm-page-id value is present and no locale is in page path', function(){
it('will return the full page path when no data-gtm-page-id value is present and no locale is in page path', function() {
expect(Mozilla.Analytics.getPageId('/firefox/new/')).toBe('/firefox/new/');
});
});

describe('getTrafficCopReferrer', function(){
it('should return null if the referrer does not exist', function(){
describe('getTrafficCopReferrer', function() {
it('should return null if the referrer does not exist', function() {
spyOn(Mozilla.Cookies, 'hasItem').and.returnValue(false);
expect(Mozilla.Analytics.getTrafficCopReferrer()).toBe(undefined);
});

it('should return the referrer if one exists', function(){
it('should return the referrer if one exists', function() {
spyOn(Mozilla.Cookies, 'hasItem').and.returnValue(true);
spyOn(Mozilla.Cookies, 'getItem').and.returnValue('direct');
expect(Mozilla.Analytics.getTrafficCopReferrer()).toBe('direct');
});
});

describe('buildDataObject', function(){
it('should contain customReferrer if found in cookie', function(){
describe('buildDataObject', function() {
it('should contain customReferrer if found in cookie', function() {
spyOn(Mozilla.Analytics, 'getTrafficCopReferrer').and.returnValue('http://www.google.com');
var obj = Mozilla.Analytics.buildDataObject();
const obj = Mozilla.Analytics.buildDataObject();
expect(obj.customReferrer).toBeDefined();
});

it('should not contain customReferrer if not found in cookie', function(){
it('should not contain customReferrer if not found in cookie', function() {
spyOn(Mozilla.Analytics, 'getTrafficCopReferrer').and.returnValue(undefined);
var obj = Mozilla.Analytics.buildDataObject();
const obj = Mozilla.Analytics.buildDataObject();
expect(obj.customReferrer).not.toBeDefined();
});
});
Expand Down
Loading

0 comments on commit ad50a98

Please sign in to comment.