From bcbe889ce6f8018351fb1743d4d80be6fd005787 Mon Sep 17 00:00:00 2001 From: Zita Nemeckova Date: Mon, 5 Nov 2018 14:32:10 +0100 Subject: [PATCH] From Jasmine to Jest conversion Converts fileds_spec and mioq_api_spec from Jasmine to Jest old_js_file_require_helper - sets function from file(s) to global so they can be accessed in Jest specs, requires files --- app/assets/javascripts/miq_application.js | 4 ++-- app/javascript/spec/helpers/old_js_file_require_helper.js | 2 ++ .../javascript/spec/old_js/fields.spec.js | 6 ++++-- .../javascript/spec/old_js/miq_api.spec.js | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 app/javascript/spec/helpers/old_js_file_require_helper.js rename spec/javascripts/fields_spec.js => app/javascript/spec/old_js/fields.spec.js (54%) rename spec/javascripts/miq_api_spec.js => app/javascript/spec/old_js/miq_api.spec.js (69%) diff --git a/app/assets/javascripts/miq_application.js b/app/assets/javascripts/miq_application.js index 2af47478ed27..688234cac93d 100644 --- a/app/assets/javascripts/miq_application.js +++ b/app/assets/javascripts/miq_application.js @@ -449,9 +449,9 @@ function miqResetSizeTimer() { } // Pass fields to server given a URL and fields in name/value pairs -function miqPassFields(url, args) { +window.miqPassFields = function (url, args) { return url + '?' + $.param(args); -} +}; function miqChartLinkData(col, row, value, category, series, id, message) { // Create the context menu diff --git a/app/javascript/spec/helpers/old_js_file_require_helper.js b/app/javascript/spec/helpers/old_js_file_require_helper.js new file mode 100644 index 000000000000..a0968c3a7d2f --- /dev/null +++ b/app/javascript/spec/helpers/old_js_file_require_helper.js @@ -0,0 +1,2 @@ +global.window = global; +require('../../../assets/javascripts/miq_application.js'); diff --git a/spec/javascripts/fields_spec.js b/app/javascript/spec/old_js/fields.spec.js similarity index 54% rename from spec/javascripts/fields_spec.js rename to app/javascript/spec/old_js/fields.spec.js index 89be1af4beaa..d583bc953a48 100644 --- a/spec/javascripts/fields_spec.js +++ b/app/javascript/spec/old_js/fields.spec.js @@ -1,5 +1,7 @@ -describe('Pass fields to server', function() { - it('returns url fields in name/value pairs', function() { +require('../helpers/old_js_file_require_helper.js'); + +describe('Pass fields to server', () => { + it('returns url fields in name/value pairs', () => { var url = '/path/to/infinity'; var args = {'foo': 'bar', 'lorem': 'ipsum'}; expect(miqPassFields(url, args)).toEqual('/path/to/infinity?foo=bar&lorem=ipsum'); diff --git a/spec/javascripts/miq_api_spec.js b/app/javascript/spec/old_js/miq_api.spec.js similarity index 69% rename from spec/javascripts/miq_api_spec.js rename to app/javascript/spec/old_js/miq_api.spec.js index bee95828425a..af25cf336c7c 100644 --- a/spec/javascripts/miq_api_spec.js +++ b/app/javascript/spec/old_js/miq_api.spec.js @@ -1,8 +1,8 @@ -describe('miq_api.js', function() { - it("can base64 encode utf8 passwords", function(done) { +describe('miq_api.js', () => { + it("can base64 encode utf8 passwords", done => { var getArgs; - spyOn(vanillaJsAPI, 'get').and.callFake(function(_url, args) { + jest.spyOn(vanillaJsAPI, 'get').mockImplementation(function(_url, args) { getArgs = args; return Promise.resolve({}); });