<commit_before>/* global ImageDetails UI receiveImageId */

describe('Test image details', function () {
    "use strict";

    var respServices = null;
    var respImageList = null;
    var imageDetails;
    


    beforeEach(function () {

        jasmine.getFixtures().fixturesPath = 'base/src/test/fixtures/html';
        loadFixtures('defaultTemplate.html');

        jasmine.getJSONFixtures().fixturesPath = 'base/src/test/fixtures/json';
        jasmine.getJSONFixtures().clearCache();
        respServices = getJSONFixture('respServices.json');
        respImageList = getJSONFixture('respImageList.json');

        imageDetails = new ImageDetails();
        imageDetails.init();

    });

    afterEach(function () {
        MashupPlatform.reset();
        jasmine.resetAll(JSTACK.Keystone);
        jasmine.resetAll(JSTACK.Nova);
        jasmine.resetAll(JSTACK.Comm);
        jasmine.resetAll(JSTACK.Glance);
    });

    function receiveWiringEvent (imageId) {
        
        var access = respServices.access;
        var wiringData = {
            'id': imageId,
            'access': access,
            'region': 'Spain2'
        };

        wiringData = JSON.stringify(wiringData);
        var receiveImageId = MashupPlatform.wiring.registerCallback.calls.mostRecent().args[1];     

        receiveImageId(wiringData);
    }

    function getImageDetailsSuccess (response) {

        var callback = JSTACK.Nova.getimagelist.calls.mostRecent().args[1];
        
        callback(response);
    }

    function getImageDetailsError (errorResponse) {

        var errorCallback = JSTACK.Nova.getimagelist.calls.mostRecent().args[2];

        errorCallback(errorResponse);
    }


    /*********************************************************************************************
    *                           F U N C T I O N A L I T Y   T E S T S                            *
    *********************************************************************************************/

    it('should call JSTACK.Nova.getimagelist when receives a wiring input event', function () {

        var imageId = 'id';
        
        receiveWiringEvent(imageId);

        expect(JSTACK.Nova.getimagelist).toHaveBeenCalled();
    });

    it('should call OpenStack delete image function', function () {

        var imageId = 'id';
        var service = JSTACK.Keystone.getservice(JSTACK.Nova.params.service);
        var deleteURL = JSTACK.Comm.getEndpoint(service, "Spain2", JSTACK.Nova.params.endpointType) + '/images/' + imageId;

        receiveWiringEvent(imageId);
        imageDetails.deleteImage();

        expect(MashupPlatform.http.makeRequest).toHaveBeenCalledWith(deleteURL, jasmine.any(Object));
    });

    it('should call buildDefaultView when an image is deleted', function () {
        var imageId = 'id';
        var service = JSTACK.Keystone.getservice(JSTACK.Nova.params.service);
        var deleteURL = JSTACK.Comm.getEndpoint(service, "Spain2", JSTACK.Nova.params.endpointType) + '/images/' + imageId;
        var deleteCallback;
        var buildDefaultViewSpy = spyOn(UI, 'buildDefaultView');

        receiveWiringEvent(imageId);
        imageDetails.deleteImage();
        deleteCallback = MashupPlatform.http.makeRequest.calls.mostRecent().args[1].onSuccess;
        deleteCallback();

        expect(buildDefaultViewSpy).toHaveBeenCalled();
    });

    it('should call JSTACK.Nova.getimagelist error callback', function () {

        var imageId = 'id';
        
        receiveWiringEvent(imageId);
        getImageDetailsError("Error getimagelist");
        
        expect(MashupPlatform.widget.log).toHaveBeenCalledWith('Error: "Error getimagelist"');

    });

    it('should call JSTACK.Nova.getimagelist success callback', function () {<commit_msg>Add expect when testing the removal of an image<commit_after>/* global ImageDetails UI receiveImageId */

describe('Test image details', function () {
    "use strict";

    var respServices = null;
    var respImageList = null;
    var imageDetails;
    


    beforeEach(function () {

        jasmine.getFixtures().fixturesPath = 'base/src/test/fixtures/html';
        loadFixtures('defaultTemplate.html');

        jasmine.getJSONFixtures().fixturesPath = 'base/src/test/fixtures/json';
        jasmine.getJSONFixtures().clearCache();
        respServices = getJSONFixture('respServices.json');
        respImageList = getJSONFixture('respImageList.json');

        imageDetails = new ImageDetails();
        imageDetails.init();

    });

    afterEach(function () {
        MashupPlatform.reset();
        jasmine.resetAll(JSTACK.Keystone);
        jasmine.resetAll(JSTACK.Nova);
        jasmine.resetAll(JSTACK.Comm);
        jasmine.resetAll(JSTACK.Glance);
    });

    function receiveWiringEvent (imageId) {
        
        var access = respServices.access;
        var wiringData = {
            'id': imageId,
            'access': access,
            'region': 'Spain2'
        };

        wiringData = JSON.stringify(wiringData);
        var receiveImageId = MashupPlatform.wiring.registerCallback.calls.mostRecent().args[1];     

        receiveImageId(wiringData);
    }

    function getImageDetailsSuccess (response) {

        var callback = JSTACK.Nova.getimagelist.calls.mostRecent().args[1];
        
        callback(response);
    }

    function getImageDetailsError (errorResponse) {

        var errorCallback = JSTACK.Nova.getimagelist.calls.mostRecent().args[2];

        errorCallback(errorResponse);
    }


    /*********************************************************************************************
    *                           F U N C T I O N A L I T Y   T E S T S                            *
    *********************************************************************************************/

    it('should call JSTACK.Nova.getimagelist when receives a wiring input event', function () {

        var imageId = 'id';
        
        receiveWiringEvent(imageId);

        expect(JSTACK.Nova.getimagelist).toHaveBeenCalled();
    });

    it('should call OpenStack delete image function', function () {

        var imageId = 'id';
        var service = JSTACK.Keystone.getservice(JSTACK.Nova.params.service);
        var deleteURL = JSTACK.Comm.getEndpoint(service, "Spain2", JSTACK.Nova.params.endpointType) + '/images/' + imageId;

        receiveWiringEvent(imageId);
        imageDetails.deleteImage();

        expect(MashupPlatform.http.makeRequest).toHaveBeenCalledWith(deleteURL, jasmine.any(Object));
    });

    it('should call buildDefaultView when an image is deleted', function () {
        var imageId = 'id';
        var service = JSTACK.Keystone.getservice(JSTACK.Nova.params.service);
        var deleteURL = JSTACK.Comm.getEndpoint(service, "Spain2", JSTACK.Nova.params.endpointType) + '/images/' + imageId;
        var deleteCallback;
        var buildDefaultViewSpy = spyOn(UI, 'buildDefaultView');

        receiveWiringEvent(imageId);
        imageDetails.deleteImage();
        deleteCallback = MashupPlatform.http.makeRequest.calls.mostRecent().args[1].onSuccess;
        deleteCallback();

        expect(buildDefaultViewSpy).toHaveBeenCalled();
        expect(imageDetails.error).toBe(true);
    });

    it('should call JSTACK.Nova.getimagelist error callback', function () {

        var imageId = 'id';
        
        receiveWiringEvent(imageId);
        getImageDetailsError("Error getimagelist");
        
        expect(MashupPlatform.widget.log).toHaveBeenCalledWith('Error: "Error getimagelist"');

    });

    it('should call JSTACK.Nova.getimagelist success callback', function () {
{'fraction_non_alphanumeric': 0.15759237498367934, 'fraction_numerical': 0.0018279148713931323, 'mean_word_length': 2.810945273631841, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2861991', 'n_tokens_mistral': 2216, 'n_tokens_neox': 2097, 'n_words': 381}