Skip to content

Commit 021073b

Browse files
committed
fix tests
1 parent a9fffba commit 021073b

14 files changed

Lines changed: 494 additions & 178 deletions

File tree

intellij-plugin/hs-core/src/org/hyperskill/academy/learning/SolutionLoaderBase.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,13 @@ abstract class SolutionLoaderBase(protected val project: Project) : Disposable {
304304
// storeOriginalTemplateFiles uses task.taskFiles which may have stale disk content.
305305
frameworkLessonManager.ensureTemplateFilesCached(task)
306306

307-
val solutionMap = taskSolutions.visibleSolutions()
307+
val solutionMap = taskSolutions.visibleSolutions(task)
308308
frameworkLessonManager.saveExternalChanges(task, solutionMap, taskSolutions.submissionId)
309309

310310
var taskFilesChanged = false
311311
for ((path, solution) in taskSolutions.solutions) {
312+
if (task.isSubmissionTestFile(path)) continue
313+
312314
val taskFile = task.getTaskFile(path)
313315
if (taskFile == null) {
314316
if (!solution.isVisible) continue
@@ -333,6 +335,8 @@ abstract class SolutionLoaderBase(protected val project: Project) : Disposable {
333335
private fun applySolutionToCurrentTask(project: Project, task: Task, taskSolutions: TaskSolutions) {
334336
val taskDir = task.getDir(project.courseDir) ?: error("Directory for task `${task.name}` not found")
335337
for ((path, solution) in taskSolutions.solutions) {
338+
if (task.isSubmissionTestFile(path)) continue
339+
336340
val taskFile = task.getTaskFile(path)
337341

338342
if (taskFile == null) {
@@ -368,15 +372,18 @@ abstract class SolutionLoaderBase(protected val project: Project) : Disposable {
368372
val lesson = task.lesson
369373
if (lesson is FrameworkLesson) {
370374
val frameworkLessonManager = FrameworkLessonManager.getInstance(project)
371-
val solutionMap = taskSolutions.visibleSolutions()
375+
val solutionMap = taskSolutions.visibleSolutions(task)
372376
frameworkLessonManager.saveExternalChanges(task, solutionMap, taskSolutions.submissionId)
373377
}
374378
}
375379

376-
private fun TaskSolutions.visibleSolutions(): Map<String, String> =
380+
private fun TaskSolutions.visibleSolutions(task: Task): Map<String, String> =
377381
solutions
378-
.filter { (_, solution) -> solution.isVisible }
382+
.filter { (path, solution) -> solution.isVisible && !task.isSubmissionTestFile(path) }
379383
.mapValues { (_, solution) -> solution.text }
384+
385+
private fun Task.isSubmissionTestFile(path: String): Boolean =
386+
getTaskFile(path)?.isTestFile ?: EduUtilsKt.isTestsFile(this, path)
380387
}
381388

382389
protected data class Solution(val text: String, val isVisible: Boolean)

intellij-plugin/hs-core/src/org/hyperskill/academy/learning/actions/TaskNavigationAction.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import com.intellij.openapi.actionSystem.AnActionEvent
55
import com.intellij.openapi.project.DumbAwareAction
66
import com.intellij.openapi.project.Project
77
import org.hyperskill.academy.learning.EduUtilsKt.isEduProject
8+
import org.hyperskill.academy.learning.course
9+
import org.hyperskill.academy.learning.courseFormat.FrameworkLesson
10+
import org.hyperskill.academy.learning.courseFormat.ext.allTasks
811
import org.hyperskill.academy.learning.courseFormat.tasks.Task
912
import org.hyperskill.academy.learning.navigation.NavigationUtils
1013
import org.hyperskill.academy.learning.taskToolWindow.ui.TaskToolWindowView
@@ -23,7 +26,7 @@ abstract class TaskNavigationAction : DumbAwareAction() {
2326
e.presentation.isEnabled = false
2427
val project = e.project ?: return
2528
if (!project.isEduProject()) return
26-
val currentTask = TaskToolWindowView.getInstance(project).currentTask ?: return
29+
val currentTask = project.currentNavigationTask() ?: return
2730
if (getTargetTask(currentTask) != null || getCustomAction(currentTask) != null) {
2831
e.presentation.isEnabled = true
2932
}
@@ -32,7 +35,7 @@ abstract class TaskNavigationAction : DumbAwareAction() {
3235
override fun getActionUpdateThread() = ActionUpdateThread.BGT
3336

3437
private fun navigateTask(project: Project, place: String) {
35-
val currentTask = TaskToolWindowView.getInstance(project).currentTask ?: return
38+
val currentTask = project.currentNavigationTask() ?: return
3639
val customAction = getCustomAction(currentTask)
3740
if (customAction != null) {
3841
customAction(project, currentTask)
@@ -43,5 +46,13 @@ abstract class TaskNavigationAction : DumbAwareAction() {
4346
NavigationUtils.navigateToTask(project, targetTask, currentTask)
4447
}
4548

49+
private fun Project.currentNavigationTask(): Task? {
50+
TaskToolWindowView.getInstance(this).currentTask?.let { return it }
51+
return course?.allTasks
52+
?.mapNotNull { it.lesson as? FrameworkLesson }
53+
?.distinct()
54+
?.firstNotNullOfOrNull { it.currentTask() }
55+
}
56+
4657
protected abstract fun getTargetTask(sourceTask: Task): Task?
4758
}

intellij-plugin/hs-core/src/org/hyperskill/academy/learning/framework/FrameworkLessonManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface FrameworkLessonManager : EduTestAware {
1313
fun preparePrevTask(lesson: FrameworkLesson, taskDir: VirtualFile, showDialogIfConflict: Boolean)
1414

1515
fun saveExternalChanges(task: Task, externalState: Map<String, String>, submissionId: Long? = null)
16-
fun updateUserChanges(task: Task, newInitialState: Map<String, String>)
16+
fun updateUserChanges(task: Task, newInitialState: Map<String, String>, newTaskFiles: Map<String, TaskFile> = emptyMap())
1717

1818
/**
1919
* Adds new files to an existing snapshot without overwriting existing files.

0 commit comments

Comments
 (0)