(levels, currentIndex, needsPractice)
| 1015 | } |
| 1016 | |
| 1017 | const findNextLevel = function (levels, currentIndex, needsPractice) { |
| 1018 | let index = currentIndex + 1 |
| 1019 | if (isAnyPrecedingLevelLocked(levels, currentIndex)) { return -1 } |
| 1020 | if (needsPractice) { |
| 1021 | if (isPractice(levels[currentIndex]) || ((index < levels.length) && isPractice(levels[index]))) { |
| 1022 | while ((index < levels.length) && (isCompleteOrAssessmentOrSkipped(levels[index]) || isLocked(levels[index]))) { |
| 1023 | if (isLocked(levels[index])) { return -1 } |
| 1024 | index++ |
| 1025 | } |
| 1026 | } else { |
| 1027 | index = findFirstIncompleteLevelOfPreviousPracticeChain(levels, currentIndex) |
| 1028 | |
| 1029 | if (index === -1) { |
| 1030 | index = currentIndex + 1 |
| 1031 | while ((index < levels.length) && (isCompleteOrAssessmentOrSkipped(levels[index]) || isLocked(levels[index]))) { |
| 1032 | if (isLocked(levels[index])) { return -1 } |
| 1033 | index++ |
| 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | } else { |
| 1038 | while ((index < levels.length) && (isPractice(levels[index]) || isCompleteOrAssessmentOrSkipped(levels[index]) || isLocked(levels[index]))) { |
| 1039 | if (isLocked(levels[index])) { return -1 } |
| 1040 | index++ |
| 1041 | } |
| 1042 | } |
| 1043 | return index |
| 1044 | } |
| 1045 | |
| 1046 | // Practice level slugs are <mainLevelSlug>-[a-z]; the DB only stores locks on the parent level |
| 1047 | // this works on junior only as they have practice levels related to parent level |
no test coverage detected