<commit_before>describe('Onboarding service', function() {
    'use strict';

    var TOUR_OPTIONS_KEY = 'org.talend.dataprep.tour_options';

    var introJsMock = {
        setOptions: function() {return this;},
        oncomplete: function() {return this;},
        onexit: function() {return this;},
        start: function() {}
    };

    beforeEach(module('data-prep.services.onboarding'));

    beforeEach(inject(function($window) {
        $window.introJs = function() {
            return introJsMock;
        };

        spyOn(introJsMock, 'setOptions').and.callThrough();
        spyOn(introJsMock, 'oncomplete').and.callThrough();
        spyOn(introJsMock, 'onexit').and.callThrough();
        spyOn(introJsMock, 'start').and.callThrough();
    }));

    afterEach(inject(function($window) {
        $window.localStorage.removeItem(TOUR_OPTIONS_KEY);
    }));

    it('should return true when tour has not been completed yet', inject(function($window, OnboardingService) {
        //given
        $window.localStorage.removeItem(TOUR_OPTIONS_KEY);

        //when
        var result = OnboardingService.shouldStartTour('dataset');

        //then
        expect(result).toBe(true);
    }));

    it('should return false when tour has already been completed', inject(function($window, OnboardingService) {
        //given
        $window.localStorage.setItem(TOUR_OPTIONS_KEY, JSON.stringify({dataset: true}));

        //when
        var result = OnboardingService.shouldStartTour('dataset');

        //then
        expect(result).toBe(false);
    }));

    it('should configure intro.js options', inject(function(OnboardingService) {
        //given

        //when
        OnboardingService.startTour('dataset');

        //then
        expect(introJsMock.setOptions).toHaveBeenCalled();
        var options = introJsMock.setOptions.calls.argsFor(0)[0];
        expect(options.nextLabel).toBe('NEXT');
        expect(options.prevLabel).toBe('BACK');
        expect(options.skipLabel).toBe('SKIP');
        expect(options.doneLabel).toBe('LET ME TRY');
    }));

    it('should create/adapt dataset tour step', inject(function(OnboardingService) {
        //when
        OnboardingService.startTour('dataset');

        //then
        expect(introJsMock.setOptions).toHaveBeenCalled();
        var options = introJsMock.setOptions.calls.argsFor(0)[0];
        expect(options.steps[0]).toEqual({
            element: '.no-js',
            position: 'right',
            intro: '<div class="introjs-tooltiptitle"><center>Welcome to</br>Talend Data Preparation</center></div><div class="introjs-tooltipcontent">To quickly learn how to use it, click <b>Next</b>.</div>'
        });
    }));

    it('should create/adapt playground step', inject(function(OnboardingService) {
        //when
        OnboardingService.startTour('playground');

        //then
        expect(introJsMock.setOptions).toHaveBeenCalled();
        var options = introJsMock.setOptions.calls.argsFor(0)[0];
        expect(options.steps[0]).toEqual({
            element: '.no-js',
            position: 'right',
            intro: '<div class="introjs-tooltiptitle"><center>Welcome to the dataset view</center></div><div class="introjs-tooltipcontent">This grid corresponds to a sample extracted from your data.</br>From this view you can prepare the transformations to apply to your data.</div>'
        });
    }));

    it('should create/adapt column selection', inject(function(OnboardingService) {
        //when
        OnboardingService.startTour('playground');

        //then
        expect(introJsMock.setOptions).toHaveBeenCalled();
        var options = introJsMock.setOptions.calls.argsFor(0)[0];
        expect(options.steps[1]).toEqual({
            element: '#datagrid .slick-header-columns-right > .slick-header-column',
            position: 'right',
            intro: '<div class="introjs-tooltiptitle"></div><div class="introjs-tooltipcontent">Select a column to discover the transformation actions you can apply to the data.</div>'
        });
    }));

    it('should create/adapt recipe tour step', inject(function(OnboardingService) {
        //when
        OnboardingService.startTour('recipe');

        //then
        expect(introJsMock.setOptions).toHaveBeenCalled();
        var options = introJsMock.setOptions.calls.argsFor(0)[0];
        expect(options.steps[0]).toEqual({
            element: '#help-preparation-name',
            position: 'right',
            intro: '<div class="introjs-tooltiptitle"></div><div class="introjs-tooltipcontent">You can give a name to your brand new preparation.</br>It will be listed in the <b>All preparations</b> view.</div>'
        });
    }));

    it('should save "dataset" state in localstorage on tour complete', inject(function($window, OnboardingService) {<commit_msg>TDP-1314 : fix unit tests<commit_after>describe('Onboarding service', function() {
    'use strict';

    var TOUR_OPTIONS_KEY = 'org.talend.dataprep.tour_options';

    var introJsMock = {
        setOptions: function() {return this;},
        oncomplete: function() {return this;},
        onexit: function() {return this;},
        start: function() {}
    };

    beforeEach(module('data-prep.services.onboarding'));

    beforeEach(inject(function($window) {
        $window.introJs = function() {
            return introJsMock;
        };

        spyOn(introJsMock, 'setOptions').and.callThrough();
        spyOn(introJsMock, 'oncomplete').and.callThrough();
        spyOn(introJsMock, 'onexit').and.callThrough();
        spyOn(introJsMock, 'start').and.callThrough();
    }));

    afterEach(inject(function($window) {
        $window.localStorage.removeItem(TOUR_OPTIONS_KEY);
    }));

    it('should return true when tour has not been completed yet', inject(function($window, OnboardingService) {
        //given
        $window.localStorage.removeItem(TOUR_OPTIONS_KEY);

        //when
        var result = OnboardingService.shouldStartTour('dataset');

        //then
        expect(result).toBe(true);
    }));

    it('should return false when tour has already been completed', inject(function($window, OnboardingService) {
        //given
        $window.localStorage.setItem(TOUR_OPTIONS_KEY, JSON.stringify({dataset: true}));

        //when
        var result = OnboardingService.shouldStartTour('dataset');

        //then
        expect(result).toBe(false);
    }));

    it('should configure intro.js options', inject(function(OnboardingService) {
        //given

        //when
        OnboardingService.startTour('dataset');

        //then
        expect(introJsMock.setOptions).toHaveBeenCalled();
        var options = introJsMock.setOptions.calls.argsFor(0)[0];
        expect(options.nextLabel).toBe('NEXT');
        expect(options.prevLabel).toBe('BACK');
        expect(options.skipLabel).toBe('SKIP');
        expect(options.doneLabel).toBe('LET ME TRY');
    }));

    it('should create/adapt dataset tour step', inject(function(OnboardingService) {
        //when
        OnboardingService.startTour('dataset');

        //then
        expect(introJsMock.setOptions).toHaveBeenCalled();
        var options = introJsMock.setOptions.calls.argsFor(0)[0];
        expect(options.steps[0]).toEqual({
            element: '.no-js',
            position: 'right',
            intro: '<div class="introjs-tooltiptitle"><center>Welcome to</br>Talend Data Preparation</center></div><div class="introjs-tooltipcontent">To quickly learn how to use it, click <b>Next</b>.</div>'
        });
    }));

    it('should create/adapt playground step', inject(function(OnboardingService) {
        //when
        OnboardingService.startTour('playground');

        //then
        expect(introJsMock.setOptions).toHaveBeenCalled();
        var options = introJsMock.setOptions.calls.argsFor(0)[0];
        expect(options.steps[0]).toEqual({
            element: '.no-js',
            position: 'right',
            intro: '<div class="introjs-tooltiptitle"><center>Welcome to the dataset view</center></div><div class="introjs-tooltipcontent">This table represents the raw data contained in your dataset.</br>From this view, you can prepare the modifications to apply on your dataset.</div>'
        });
    }));

    it('should create/adapt column selection', inject(function(OnboardingService) {
        //when
        OnboardingService.startTour('playground');

        //then
        expect(introJsMock.setOptions).toHaveBeenCalled();
        var options = introJsMock.setOptions.calls.argsFor(0)[0];
        expect(options.steps[1]).toEqual({
            element: '#datagrid .slick-header-columns-right > .slick-header-column',
            position: 'right',
            intro: '<div class="introjs-tooltiptitle"></div><div class="introjs-tooltipcontent">Select a column to discover the transformation functions you can apply to your data.</div>'
        });
    }));

    it('should create/adapt recipe tour step', inject(function(OnboardingService) {
        //when
        OnboardingService.startTour('recipe');

        //then
        expect(introJsMock.setOptions).toHaveBeenCalled();
        var options = introJsMock.setOptions.calls.argsFor(0)[0];
        expect(options.steps[0]).toEqual({
            element: '#help-preparation-name',
            position: 'right',
            intro: '<div class="introjs-tooltiptitle"></div><div class="introjs-tooltipcontent">You can give a name to your brand new preparation.</br>It will be listed in the <b>All Preparations</b> view.</div>'
        });
    }));

    it('should save "dataset" state in localstorage on tour complete', inject(function($window, OnboardingService) {
{'fraction_non_alphanumeric': 0.14011357769747032, 'fraction_numerical': 0.0033040784718637068, 'mean_word_length': 2.956699346405229, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7487645', 'n_tokens_mistral': 2784, 'n_tokens_neox': 2659, 'n_words': 533}