<commit_before>import { SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateService } from '@ngx-translate/core';
import { LocalStorageService, SessionStorageService } from 'ngx-webstorage';
import { of } from 'rxjs';
import { ArtemisTestModule } from '../../test.module';
import { MockTranslateService, TranslateTestingModule } from '../../helpers/mocks/service/mock-translate.service';
import { ArtemisPlagiarismModule } from 'app/exercises/shared/plagiarism/plagiarism.module';
import { TextSubmissionViewerComponent } from 'app/exercises/shared/plagiarism/plagiarism-split-view/text-submission-viewer/text-submission-viewer.component';
import { CodeEditorRepositoryFileService } from 'app/exercises/programming/shared/code-editor/service/code-editor-repository.service';
import { TextSubmissionService } from 'app/exercises/text/participate/text-submission.service';
import { ExerciseType } from 'app/entities/exercise.model';
import { TextExercise } from 'app/entities/text-exercise.model';
import { MockSyncStorage } from '../../helpers/mocks/service/mock-sync-storage.service';
import { ProgrammingExercise } from 'app/entities/programming-exercise.model';
import { FileType } from 'app/exercises/programming/shared/code-editor/model/code-editor.model';

describe('Text Submission Viewer Component', () => {
    let comp: TextSubmissionViewerComponent;
    let fixture: ComponentFixture<TextSubmissionViewerComponent>;
    let repositoryService: CodeEditorRepositoryFileService;
    let textSubmissionService: TextSubmissionService;

    const files = {
        'src/': FileType.FOLDER,
        'src/Main.java': FileType.FILE,
        'src/Utils.java': FileType.FILE,
        'src/Helper.java': FileType.FILE,
    };

    beforeEach(() => {
        TestBed.configureTestingModule({
            imports: [ArtemisTestModule, ArtemisPlagiarismModule, TranslateTestingModule],
            providers: [
                { provide: TranslateService, useClass: MockTranslateService },
                { provide: LocalStorageService, useClass: MockSyncStorage },
                { provide: SessionStorageService, useClass: MockSyncStorage },
            ],
        }).compileComponents();

        fixture = TestBed.createComponent(TextSubmissionViewerComponent);
        comp = fixture.componentInstance;
        repositoryService = fixture.debugElement.injector.get(CodeEditorRepositoryFileService);
        textSubmissionService = fixture.debugElement.injector.get(TextSubmissionService);
    });

    it('fetches a text submission', () => {
        comp.exercise = { type: ExerciseType.TEXT } as TextExercise;
        spyOn(textSubmissionService, 'getTextSubmission').and.returnValue(of({ text: 'Test' }));

        comp.ngOnChanges({
            plagiarismSubmission: { currentValue: { submissionId: 2 } } as SimpleChange,
        });

        expect(textSubmissionService.getTextSubmission).toHaveBeenCalledWith(2);
        expect(comp.isProgrammingExercise).toBe(false);
    });

    it('fetches a programming submission', () => {
        comp.exercise = { type: ExerciseType.PROGRAMMING } as ProgrammingExercise;
        spyOn(repositoryService, 'getRepositoryContent').and.returnValue(of([]));

        comp.ngOnChanges({
            plagiarismSubmission: { currentValue: { submissionId: 2 } } as SimpleChange,
        });

        expect(repositoryService.getRepositoryContent).toHaveBeenCalled();
        expect(comp.isProgrammingExercise).toBe(true);
    });

    it('filters files of type FILE', () => {
        const filtered = comp.filterFiles(files);

        expect(filtered).toHaveLength(3);
    });

    it('handles file selection', () => {
        const fileName = Object.keys(files)[1];
        spyOn(repositoryService, 'getFile').and.returnValue(of({ fileContent: 'Test' }));
<commit_msg>Fix the failing client test for the TextSubmissionViewerComponent (#2850)<commit_after>import { SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateService } from '@ngx-translate/core';
import { LocalStorageService, SessionStorageService } from 'ngx-webstorage';
import { of } from 'rxjs';
import { ArtemisTestModule } from '../../test.module';
import { MockTranslateService, TranslateTestingModule } from '../../helpers/mocks/service/mock-translate.service';
import { ArtemisPlagiarismModule } from 'app/exercises/shared/plagiarism/plagiarism.module';
import { TextSubmissionViewerComponent } from 'app/exercises/shared/plagiarism/plagiarism-split-view/text-submission-viewer/text-submission-viewer.component';
import { CodeEditorRepositoryFileService } from 'app/exercises/programming/shared/code-editor/service/code-editor-repository.service';
import { TextSubmissionService } from 'app/exercises/text/participate/text-submission.service';
import { ExerciseType } from 'app/entities/exercise.model';
import { TextExercise } from 'app/entities/text-exercise.model';
import { MockSyncStorage } from '../../helpers/mocks/service/mock-sync-storage.service';
import { ProgrammingExercise } from 'app/entities/programming-exercise.model';
import { FileType } from 'app/exercises/programming/shared/code-editor/model/code-editor.model';
import { PlagiarismSubmission } from 'app/exercises/shared/plagiarism/types/PlagiarismSubmission';
import { TextSubmissionElement } from 'app/exercises/shared/plagiarism/types/text/TextSubmissionElement';

describe('Text Submission Viewer Component', () => {
    let comp: TextSubmissionViewerComponent;
    let fixture: ComponentFixture<TextSubmissionViewerComponent>;
    let repositoryService: CodeEditorRepositoryFileService;
    let textSubmissionService: TextSubmissionService;

    const files = {
        'src/': FileType.FOLDER,
        'src/Main.java': FileType.FILE,
        'src/Utils.java': FileType.FILE,
        'src/Helper.java': FileType.FILE,
    };

    beforeEach(() => {
        TestBed.configureTestingModule({
            imports: [ArtemisTestModule, ArtemisPlagiarismModule, TranslateTestingModule],
            providers: [
                { provide: TranslateService, useClass: MockTranslateService },
                { provide: LocalStorageService, useClass: MockSyncStorage },
                { provide: SessionStorageService, useClass: MockSyncStorage },
            ],
        }).compileComponents();

        fixture = TestBed.createComponent(TextSubmissionViewerComponent);
        comp = fixture.componentInstance;
        repositoryService = fixture.debugElement.injector.get(CodeEditorRepositoryFileService);
        textSubmissionService = fixture.debugElement.injector.get(TextSubmissionService);
    });

    it('fetches a text submission', () => {
        comp.exercise = { type: ExerciseType.TEXT } as TextExercise;
        spyOn(textSubmissionService, 'getTextSubmission').and.returnValue(of({ text: 'Test' }));

        comp.ngOnChanges({
            plagiarismSubmission: { currentValue: { submissionId: 2 } } as SimpleChange,
        });

        expect(textSubmissionService.getTextSubmission).toHaveBeenCalledWith(2);
        expect(comp.isProgrammingExercise).toBe(false);
    });

    it('fetches a programming submission', () => {
        comp.exercise = { type: ExerciseType.PROGRAMMING } as ProgrammingExercise;
        spyOn(repositoryService, 'getRepositoryContent').and.returnValue(of([]));

        comp.ngOnChanges({
            plagiarismSubmission: { currentValue: { submissionId: 2 } } as SimpleChange,
        });

        expect(repositoryService.getRepositoryContent).toHaveBeenCalled();
        expect(comp.isProgrammingExercise).toBe(true);
    });

    it('filters files of type FILE', () => {
        const filtered = comp.filterFiles(files);

        expect(filtered).toHaveLength(3);
    });

    it('handles file selection', () => {
        comp.plagiarismSubmission = { submissionId: 1 } as PlagiarismSubmission<TextSubmissionElement>;

        const fileName = Object.keys(files)[1];
        spyOn(repositoryService, 'getFile').and.returnValue(of({ fileContent: 'Test' }));

{'fraction_non_alphanumeric': 0.12158503568791533, 'fraction_numerical': 0.0018459266551809008, 'mean_word_length': 3.96760391198044, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 18, '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': '2774148', 'n_tokens_mistral': 2280, 'n_tokens_neox': 2225, 'n_words': 385}