Skip to content

Commit

Permalink
Plagiarsim checks: Fix default value of after due date checks (#7657)
Browse files Browse the repository at this point in the history
  • Loading branch information
Strohgelaender authored Dec 8, 2023
1 parent b9df09c commit c227a8d
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/main/webapp/app/entities/exercise.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export interface PlagiarismDetectionConfig {
minimumSize?: number;
}

export const defaultPlagiarismDetectionConfig: PlagiarismDetectionConfig = {
export const DEFAULT_PLAGIARISM_DETECTION_CONFIG: PlagiarismDetectionConfig = {
continuousPlagiarismControlEnabled: false,
continuousPlagiarismControlPostDueDateChecksEnabled: true,
continuousPlagiarismControlPostDueDateChecksEnabled: false,
similarityThreshold: 90,
minimumSize: 50,
minimumScore: 0,
Expand Down Expand Up @@ -105,7 +105,7 @@ export abstract class Exercise implements BaseEntity {
public exerciseGroup?: ExerciseGroup;
public competencies?: Competency[];

public plagiarismDetectionConfig?: PlagiarismDetectionConfig = defaultPlagiarismDetectionConfig;
public plagiarismDetectionConfig?: PlagiarismDetectionConfig = DEFAULT_PLAGIARISM_DETECTION_CONFIG; // default value

// transient objects which might not be set
public numberOfSubmissions?: DueDateStat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
id="continuous_plagiarism_control_enabled"
class="plagiarism-option-checkbox form-check-input"
name="exercise.plagiarismDetectionConfig.continuousPlagiarismControlEnabled"
#exercise.plagiarismDetectionConfig.continuousPlagiarismControlEnabled="ngModel"
[(ngModel)]="exercise.plagiarismDetectionConfig!.continuousPlagiarismControlEnabled"
[checked]="exercise.plagiarismDetectionConfig!.continuousPlagiarismControlEnabled"
(click)="toggleCPCEnabled()"
/>
<div class="plagiarism-option-label" jhiTranslate="artemisApp.plagiarism.continuousPlagiarismControlEnabled">Enable Continuous Plagiarism Control</div>
</div>
Expand Down Expand Up @@ -78,7 +78,7 @@
<div class="form-group">
<div>
<label class="form-control-label" jhiTranslate="artemisApp.plagiarism.minimumSize">Minimum Size</label>
<fa-icon [icon]="faQuestionCircle" placement="bottom auto" [ngbTooltip]="getMinimumSizeTooltip() | artemisTranslate"></fa-icon>
<fa-icon [icon]="faQuestionCircle" placement="bottom auto" [ngbTooltip]="minimumSizeTooltip | artemisTranslate"></fa-icon>
</div>
<input
type="number"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input, OnInit } from '@angular/core';
import { Exercise, ExerciseType, defaultPlagiarismDetectionConfig } from 'app/entities/exercise.model';
import { DEFAULT_PLAGIARISM_DETECTION_CONFIG, Exercise, ExerciseType } from 'app/entities/exercise.model';
import { faQuestionCircle } from '@fortawesome/free-solid-svg-icons';

@Component({
Expand All @@ -8,19 +8,29 @@ import { faQuestionCircle } from '@fortawesome/free-solid-svg-icons';
})
export class ExerciseUpdatePlagiarismComponent implements OnInit {
@Input() exercise: Exercise;
minimumSizeTooltip?: string;

faQuestionCircle = faQuestionCircle;
readonly faQuestionCircle = faQuestionCircle;

ngOnInit(): void {
this.minimumSizeTooltip = this.getMinimumSizeTooltip();
if (!this.exercise.plagiarismDetectionConfig) {
this.exercise.plagiarismDetectionConfig = defaultPlagiarismDetectionConfig;
// Create the default plagiarism configuration if there is none (e.g. importing an old exercise from a file)
this.exercise.plagiarismDetectionConfig = DEFAULT_PLAGIARISM_DETECTION_CONFIG;
}
}

toggleCPCEnabled() {
const config = this.exercise.plagiarismDetectionConfig!;
const newValue = !config.continuousPlagiarismControlEnabled;
config.continuousPlagiarismControlEnabled = newValue;
config.continuousPlagiarismControlPostDueDateChecksEnabled = newValue;
}

/**
* Return the translation identifier of the minimum size tooltip for the current exercise type.
*/
getMinimumSizeTooltip() {
getMinimumSizeTooltip(): string | undefined {
switch (this.exercise.type) {
case ExerciseType.PROGRAMMING: {
return 'artemisApp.plagiarism.minimumSizeTooltipProgrammingExercise';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultPlagiarismDetectionConfig } from 'app/entities/exercise.model';
import { DEFAULT_PLAGIARISM_DETECTION_CONFIG, Exercise, ExerciseType } from 'app/entities/exercise.model';
import { ExerciseUpdatePlagiarismComponent } from 'app/exercises/shared/plagiarism/exercise-update-plagiarism/exercise-update-plagiarism.component';
import { ProgrammingExercise } from 'app/entities/programming-exercise.model';

Expand Down Expand Up @@ -31,6 +31,51 @@ describe('Exercise Update Plagiarism Component', () => {

comp.ngOnInit();

expect(comp.exercise.plagiarismDetectionConfig).toEqual(defaultPlagiarismDetectionConfig);
expect(comp.exercise.plagiarismDetectionConfig).toEqual(DEFAULT_PLAGIARISM_DETECTION_CONFIG);
});

it('should set minimumSizeTooltip on init', () => {
comp.exercise = { type: ExerciseType.PROGRAMMING } as Exercise;
comp.ngOnInit();
expect(comp.minimumSizeTooltip).toBe('artemisApp.plagiarism.minimumSizeTooltipProgrammingExercise');
});

it('should set default plagiarism detection config on init if not set', () => {
comp.exercise = { type: ExerciseType.PROGRAMMING } as Exercise;
comp.ngOnInit();
expect(comp.exercise.plagiarismDetectionConfig).toEqual(DEFAULT_PLAGIARISM_DETECTION_CONFIG);
});

it('should enable cpc', () => {
comp.exercise = {
plagiarismDetectionConfig: { continuousPlagiarismControlEnabled: false, continuousPlagiarismControlPostDueDateChecksEnabled: false },
} as Exercise;
comp.toggleCPCEnabled();
expect(comp.exercise.plagiarismDetectionConfig!.continuousPlagiarismControlEnabled).toBeTrue();
expect(comp.exercise.plagiarismDetectionConfig!.continuousPlagiarismControlPostDueDateChecksEnabled).toBeTrue();
});

it('should disable cpc', () => {
comp.exercise = {
plagiarismDetectionConfig: { continuousPlagiarismControlEnabled: true, continuousPlagiarismControlPostDueDateChecksEnabled: true },
} as Exercise;
comp.toggleCPCEnabled();
expect(comp.exercise.plagiarismDetectionConfig!.continuousPlagiarismControlEnabled).toBeFalse();
expect(comp.exercise.plagiarismDetectionConfig!.continuousPlagiarismControlPostDueDateChecksEnabled).toBeFalse();
});

it('should get correct minimumSizeTooltip for programming exercises', () => {
comp.exercise = { type: ExerciseType.PROGRAMMING } as Exercise;
expect(comp.getMinimumSizeTooltip()).toBe('artemisApp.plagiarism.minimumSizeTooltipProgrammingExercise');
});

it('should get correct minimumSizeTooltip for text exercises', () => {
comp.exercise = { type: ExerciseType.TEXT } as Exercise;
expect(comp.getMinimumSizeTooltip()).toBe('artemisApp.plagiarism.minimumSizeTooltipTextExercise');
});

it('should get correct minimumSizeTooltip for modeling exercises', () => {
comp.exercise = { type: ExerciseType.MODELING } as Exercise;
expect(comp.getMinimumSizeTooltip()).toBe('artemisApp.plagiarism.minimumSizeTooltipModelingExercise');
});
});

0 comments on commit c227a8d

Please sign in to comment.