<commit_before>import "../state.module"
import { SettingsService } from "./settings.service"
import { IRootScopeService, ITimeoutService } from "angular"
import { LoadingGifService } from "../../ui/loadingGif/loadingGif.service"
import { AttributeTypeValue, FileSelectionState, FileState, RecursivePartial, Settings } from "../../codeCharta.model"
import { getService, instantiateModule } from "../../../../mocks/ng.mockhelper"
import { DEFAULT_SETTINGS, TEST_DELTA_MAP_A, TEST_DELTA_MAP_B } from "../../util/dataMocks"
import { FileStateService } from "../fileState.service"
import { FileStateHelper } from "../../util/fileStateHelper"
import { SettingsMerger } from "../../util/settingsMerger"

describe("settingService", () => {
	let settingsService: SettingsService
	let $rootScope: IRootScopeService
	let $timeout: ITimeoutService
	let loadingGifService: LoadingGifService

	let settings: Settings
	let fileStates: FileState[]
	const SOME_EXTRA_TIME = 400

	beforeEach(() => {
		restartSystem()
		rebuildService()
		withMockedEventMethods()
		withMockedLoadingGifService()
	})

	function restartSystem() {
		instantiateModule("app.codeCharta.state")

		$rootScope = getService<IRootScopeService>("$rootScope")
		$timeout = getService<ITimeoutService>("$timeout")
		loadingGifService = getService<LoadingGifService>("loadingGifService")

		settings = JSON.parse(JSON.stringify(DEFAULT_SETTINGS))
		fileStates = [
			{ file: JSON.parse(JSON.stringify(TEST_DELTA_MAP_A)), selectedAs: FileSelectionState.Comparison },
			{ file: JSON.parse(JSON.stringify(TEST_DELTA_MAP_B)), selectedAs: FileSelectionState.Reference }
		]
	}

	function rebuildService() {
		settingsService = new SettingsService($rootScope, $timeout, loadingGifService)
	}

	function withMockedEventMethods() {
		$rootScope.$on = settingsService["$rootScope"].$on = jest.fn()
		$rootScope.$broadcast = settingsService["$rootScope"].$on = jest.fn()
	}

	function withMockedLoadingGifService() {
		loadingGifService = settingsService["loadingGifService"] = jest.fn().mockReturnValue({
			updateLoadingMapFlag: jest.fn()
		})()
	}

	describe("constructor", () => {
		it("should set settings to default settings", () => {
			settingsService["getDefaultSettings"] = jest.fn()

			rebuildService()

			expect(settingsService["getDefaultSettings"]).toBeCalled()
		})

		it("should subscribe to FileStateService", () => {
			FileStateService.subscribe = jest.fn()

			rebuildService()

			expect(FileStateService.subscribe).toHaveBeenCalledWith($rootScope, settingsService)
		})<commit_msg>Fix settingsService test #529<commit_after>import "../state.module"
import { SettingsService } from "./settings.service"
import { IRootScopeService, ITimeoutService } from "angular"
import { LoadingGifService } from "../../ui/loadingGif/loadingGif.service"
import { AttributeTypeValue, FileSelectionState, FileState, RecursivePartial, Settings } from "../../codeCharta.model"
import { getService, instantiateModule } from "../../../../mocks/ng.mockhelper"
import { DEFAULT_SETTINGS, TEST_DELTA_MAP_A, TEST_DELTA_MAP_B } from "../../util/dataMocks"
import { FileStateService } from "../fileState.service"
import { FileStateHelper } from "../../util/fileStateHelper"
import { SettingsMerger } from "../../util/settingsMerger"

describe("settingService", () => {
	let settingsService: SettingsService
	let $rootScope: IRootScopeService
	let $timeout: ITimeoutService
	let loadingGifService: LoadingGifService

	let settings: Settings
	let fileStates: FileState[]
	const SOME_EXTRA_TIME = 400

	beforeEach(() => {
		restartSystem()
		rebuildService()
		withMockedEventMethods()
		withMockedLoadingGifService()
	})

	function restartSystem() {
		instantiateModule("app.codeCharta.state")

		$rootScope = getService<IRootScopeService>("$rootScope")
		$timeout = getService<ITimeoutService>("$timeout")
		loadingGifService = getService<LoadingGifService>("loadingGifService")

		settings = JSON.parse(JSON.stringify(DEFAULT_SETTINGS))
		fileStates = [
			{ file: JSON.parse(JSON.stringify(TEST_DELTA_MAP_A)), selectedAs: FileSelectionState.Comparison },
			{ file: JSON.parse(JSON.stringify(TEST_DELTA_MAP_B)), selectedAs: FileSelectionState.Reference }
		]
	}

	function rebuildService() {
		settingsService = new SettingsService($rootScope, $timeout, loadingGifService)
	}

	function withMockedEventMethods() {
		$rootScope.$on = settingsService["$rootScope"].$on = jest.fn()
		$rootScope.$broadcast = settingsService["$rootScope"].$on = jest.fn()
	}

	function withMockedLoadingGifService() {
		loadingGifService = settingsService["loadingGifService"] = jest.fn().mockReturnValue({
			updateLoadingMapFlag: jest.fn()
		})()
	}

	describe("constructor", () => {
		it("should set settings to default settings", () => {
			rebuildService()

			expect(settingsService.getSettings()).toEqual(settings)
		})

		it("should subscribe to FileStateService", () => {
			FileStateService.subscribe = jest.fn()

			rebuildService()

			expect(FileStateService.subscribe).toHaveBeenCalledWith($rootScope, settingsService)
		})
{'fraction_non_alphanumeric': 0.13723551512754598, 'fraction_numerical': 0.0017797112912794147, 'mean_word_length': 5.5773732119635895, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '4826152', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1484, 'n_words': 271}