<commit_before>import {expectSaga, testSaga} from 'redux-saga-test-plan'
import {channel} from 'redux-saga'
import {call, spawn, select} from 'redux-saga/effects'

import notifier from '../../../notifier'
import * as legacyAction from './legacyAction'
import rest from '../../../rest'

describe('app-extensions', () => {
  describe('actions', () => {
    describe('modules', () => {
      describe('actionHandler', () => {
        describe('legacyAction', () => {
          describe('initLegacyActionsEnv', () => {
            test('should init if not initialized', () => {
              window.legacyActionsEnvInitialized = undefined
              window.setUpLegacyActionsEnv = () => {}

              testSaga(legacyAction.initLegacyActionsEnv).next()
                .call(legacyAction.loadSequentially, legacyAction.sources).next()
                .call(window.setUpLegacyActionsEnv).next()
                .call(legacyAction.registerRemoteEventsListener).next()
                .call(legacyAction.registerNotificationsListener).next()
                .isDone()
            })

            test('should not init if already initialized', () => {
              window.legacyActionsEnvInitialized = true

              testSaga(legacyAction.initLegacyActionsEnv).next()
                .call(legacyAction.registerRemoteEventsListener).next()
                .call(legacyAction.registerNotificationsListener).next()
                .isDone()
            })
          })

          describe('loadSequentially', () => {
            test('should load the required sources for the new client sequentially', () => {
              window.legacyActionEnv = undefined
              const revision = 'abcdef1234567890'

              expectSaga(legacyAction.loadSequentially, legacyAction.sources)
                .provide([
                  [call(rest.fetchServerSettings), {niceRevision: revision}]
                ])
                .call(legacyAction.loadScript,
                  `/nice2/javascript/nice2-newclient-actions-setup.release.js?v=${revision}`)
                .call(legacyAction.loadScript, `/nice2/javascript/lang.release.js?v=${revision}`)
                .call(legacyAction.loadScript, `/nice2/javascript/nice2-ext-newclient-actions.release.js?v=${revision}`)
                .call(legacyAction.loadScript, `/nice2/javascript/nice2-admin.release.js?v=${revision}`)
                .call(legacyAction.loadScript,
                  `/nice2/javascript/nice2-newclient-actions-setup.release.js?v=${revision}`)
                .call(legacyAction.loadScript, `/nice2/dwr-all.js?v=${revision}`)
                .call(legacyAction.loadScript, `/js/ext-extensions/ckeditor/ckeditor/ckeditor.js?v=${revision}`)
                .call(legacyAction.loadCss, `/css/themes/blue-medium.css?v=${revision}`)
                .call(legacyAction.loadCss, `/css/nice2-admin.css?v=${revision}`)
                .call(legacyAction.loadCss, `/css/nice2-new-client-legacy-actions.css?v=${revision}`)
                .run()
            })

            test('should load the required sources for the legacy admin client sequentially', () => {
              window.legacyActionEnv = 'legacy-admin'
              const revision = 'abcdef1234567890'

              expectSaga(legacyAction.loadSequentially, legacyAction.sources)
                .provide([
                  [call(rest.fetchServerSettings), {niceRevision: revision}]
                ])
                .call(legacyAction.loadScript,
                  `/nice2/javascript/nice2-newclient-actions-setup.release.js?v=${revision}`)
                .run()
            })

            test('should load the required sources for public flows sequentially', () => {
              window.legacyActionEnv = 'legacy-public'
              const revision = 'abcdef1234567890'

              expectSaga(legacyAction.loadSequentially, legacyAction.sources)
                .provide([
                  [call(rest.fetchServerSettings), {niceRevision: revision}]
                ])
                .call(legacyAction.loadScript,
                  `/nice2/javascript/nice2-newclient-actions-public.release.js?v=${revision}`)<commit_msg>test(app-extensions): fix return and mock<commit_after>import {expectSaga, testSaga} from 'redux-saga-test-plan'
import {channel} from 'redux-saga'
import {call, spawn, select} from 'redux-saga/effects'
import * as matchers from 'redux-saga-test-plan/matchers'

import notifier from '../../../notifier'
import * as legacyAction from './legacyAction'
import rest from '../../../rest'

describe('app-extensions', () => {
  describe('actions', () => {
    describe('modules', () => {
      describe('actionHandler', () => {
        describe('legacyAction', () => {
          describe('initLegacyActionsEnv', () => {
            test('should init if not initialized', () => {
              window.legacyActionsEnvInitialized = undefined
              window.setUpLegacyActionsEnv = () => {}

              testSaga(legacyAction.initLegacyActionsEnv).next()
                .call(legacyAction.loadSequentially, legacyAction.sources).next()
                .call(window.setUpLegacyActionsEnv).next()
                .call(legacyAction.registerRemoteEventsListener).next()
                .call(legacyAction.registerNotificationsListener).next()
                .isDone()
            })

            test('should not init if already initialized', () => {
              window.legacyActionsEnvInitialized = true

              testSaga(legacyAction.initLegacyActionsEnv).next()
                .call(legacyAction.registerRemoteEventsListener).next()
                .call(legacyAction.registerNotificationsListener).next()
                .isDone()
            })
          })

          describe('loadSequentially', () => {
            test('should load the required sources for the new client sequentially', () => {
              window.legacyActionEnv = undefined
              const revision = 'abcdef1234567890'

              return expectSaga(legacyAction.loadSequentially, legacyAction.sources)
                .provide([
                  [call(rest.fetchServerSettings), {niceRevision: revision}],
                  [matchers.call.fn(legacyAction.loadScript)],
                  [matchers.call.fn(legacyAction.loadCss)]
                ])
                .call(legacyAction.loadScript,
                  `/nice2/javascript/nice2-newclient-actions-setup.release.js?v=${revision}`)
                .call(legacyAction.loadScript, `/nice2/javascript/lang.release.js?v=${revision}`)
                .call(legacyAction.loadScript, `/nice2/javascript/nice2-ext-newclient-actions.release.js?v=${revision}`)
                .call(legacyAction.loadScript, `/nice2/javascript/nice2-admin.release.js?v=${revision}`)
                .call(legacyAction.loadScript, `/nice2/dwr-all.js?v=${revision}`)
                .call(legacyAction.loadScript, `/js/ext-extensions/ckeditor/ckeditor/ckeditor.js?v=${revision}`)
                .call(legacyAction.loadCss, `/css/themes/blue-medium.css?v=${revision}`)
                .call(legacyAction.loadCss, `/css/nice2-admin.css?v=${revision}`)
                .call(legacyAction.loadCss, `/css/nice2-new-client-legacy-actions.css?v=${revision}`)
                .run({timeout: 10000})
            })

            test('should load the required sources for the legacy admin client sequentially', () => {
              window.legacyActionEnv = 'legacy-admin'
              const revision = 'abcdef1234567890'

              return expectSaga(legacyAction.loadSequentially, legacyAction.sources)
                .provide([
                  [call(rest.fetchServerSettings), {niceRevision: revision}],
                  [matchers.call.fn(legacyAction.loadScript)],
                  [matchers.call.fn(legacyAction.loadCss)]
                ])
                .call(legacyAction.loadScript,
                  `/nice2/javascript/nice2-newclient-actions-setup.release.js?v=${revision}`)
                .run()
            })

            test('should load the required sources for public flows sequentially', () => {
              window.legacyActionEnv = 'legacy-public'
              const revision = 'abcdef1234567890'

              return expectSaga(legacyAction.loadSequentially, legacyAction.sources)
                .provide([
                  [call(rest.fetchServerSettings), {niceRevision: revision}],
                  [matchers.call.fn(legacyAction.loadScript)],
                  [matchers.call.fn(legacyAction.loadCss)]
                ])
                .call(legacyAction.loadScript,
                  `/nice2/javascript/nice2-newclient-actions-public.release.js?v=${revision}`)
{'fraction_non_alphanumeric': 0.1315516645547748, 'fraction_numerical': 0.01094343969588757, 'mean_word_length': 2.157090909090909, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '1222528', 'n_tokens_mistral': 2461, 'n_tokens_neox': 2308, 'n_words': 318}