Skip to content

Commit 5c89af0

Browse files
author
rmmayo
committed
trying to get cypress to not crash browser during quiz generation
1 parent 7fa40e1 commit 5c89af0

File tree

10 files changed

+113
-9
lines changed

10 files changed

+113
-9
lines changed

dashboard/src/common-components/utilities/learning-conent-gen/GenerateQuizDialog2.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616
<script setup>
17-
import { computed, ref } from 'vue'
17+
import { computed, watch, ref } from 'vue'
1818
import { useRoute } from 'vue-router'
1919
import { useLog } from '@/components/utils/misc/useLog.js'
2020
import { useImgHandler } from '@/common-components/utilities/learning-conent-gen/UseImgHandler.js'
@@ -24,8 +24,7 @@ import AiPromptDialog from '@/common-components/utilities/learning-conent-gen/Ai
2424
import SkillsSpinner from '@/components/utils/SkillsSpinner.vue'
2525
import { useAppConfig } from '@/common-components/stores/UseAppConfig.js'
2626
import { useDescriptionValidatorService } from '@/common-components/validators/UseDescriptionValidatorService.js'
27-
import { array, number, object, string } from 'yup'
28-
import QuestionType from '@/skills-display/components/quiz/QuestionType.js'
27+
import { object, string } from 'yup'
2928
import { useForm } from 'vee-validate'
3029
3130
const model = defineModel()
@@ -59,6 +58,9 @@ const dynamicSchema = computed(() => {
5958
}
6059
return object(validationObj)
6160
})
61+
watch(dynamicSchema, () => {
62+
validate()
63+
})
6264
const { values, meta, handleSubmit, isSubmitting, resetForm, setFieldValue, validate, validateField, errors, errorBag, setErrors } = useForm({
6365
validationSchema: dynamicSchema,
6466
})
@@ -215,6 +217,7 @@ const ensureValidQuestionType = (question) => {
215217
const handleGenerationCompleted = (generated) => {
216218
currentJsonString.value = ''
217219
isGenerating.value = false
220+
// console.log(generated.generatedValue)
218221
currentQuestions.value = generated.generatedInfo.generatedQuiz
219222
validate()
220223
return generated
@@ -275,7 +278,7 @@ const createPromptInstructions = (userEnterInstructions) => {
275278
<div v-if="historyItem.generatedInfo" class="px-5 border rounded-lg bg-blue-50 ml-4">
276279
<div v-for="(q, index) in getQuizDataForDisplay(historyItem.generatedInfo, historyItem.id)" :key="q.id">
277280
<div class="my-4">
278-
<QuestionCard :question="q" :question-num="index+1" quiz-type="Quiz" :show-edit-controls="false" :edit-question-inline="true"/>
281+
<QuestionCard data-cy="generatedQuestion" :question="q" :question-num="index+1" quiz-type="Quiz" :show-edit-controls="false" :edit-question-inline="true"/>
279282
</div>
280283
</div>
281284
</div>

dashboard/src/components/quiz/testCreation/QuestionCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const moveQuestion = (changeIndexBy) => {
114114
:allow-insert-images="false"
115115
label="Question"
116116
markdownHeight="150px"
117-
data-cy="questionDisplayTextEditor"
117+
:data-cy="`questionDisplayTextEditor-${questionNum}`"
118118
:name="`question${props.questionNum}`"/>
119119
120120
<markdown-text v-else

dashboard/src/components/skills/ChildRowSkillsDisplay.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ const onDialogShow = () => {
286286
<SkillsButton icon="fa-solid fa-wand-magic-sparkles"
287287
label="AI"
288288
size="small"
289+
data-cy="generateQuizBtn"
289290
@click="showGenerateQuizDialog = true"/>
290291
</div>
291292
</div>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2025 SkillTree
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {
18+
newDescWelcomeMsg,
19+
chessGenValue,
20+
existingDescWelcomeMsg,
21+
completedMsg,
22+
gotStartedMsg,
23+
newQuizGeneratingMsg
24+
}
25+
from './openai_helper_commands'
26+
27+
describe('Generate Quiz Tests', () => {
28+
29+
it('generate a new quiz for a skill', () => {
30+
cy.on('uncaught:exception', (err, runnable) => {
31+
return false
32+
})
33+
cy.intercept('GET', '/public/config', (req) => {
34+
req.reply((res) => {
35+
const conf = res.body;
36+
conf.enableOpenAIIntegration = true;
37+
res.send(conf);
38+
});
39+
}).as('getConfig');
40+
cy.createProject(1);
41+
cy.createSubject(1, 1);
42+
cy.createSkill(1, 1, 1, { description: chessGenValue, numPerformToCompletion: 1 })
43+
44+
cy.visit('/administrator/projects/proj1/subjects/subj1/skills/skill1')
45+
cy.get('@getConfig')
46+
47+
cy.get('[data-cy="skillOverviewDescription"]').contains(chessGenValue)
48+
49+
cy.get('[data-cy="generateQuizBtn"]').click()
50+
51+
cy.get('[data-cy="instructionsInput"]').should('have.focus')
52+
cy.get('[data-cy="useGenValueBtn-1"]').click()
53+
cy.get('[data-cy="useGenValueBtn-1"]').should('not.exist')
54+
55+
cy.get('[data-cy="selfReportMediaCard"]').contains('Self Report: Quiz')
56+
cy.get('[data-cy="selfReportMediaCard"]').contains('Users can self report this skill and points will be awarded after the Very Great Skill 1 Quiz Quiz is passed!')
57+
cy.get('[data-cy="linkToQuiz"]')
58+
.should('have.attr', 'href')
59+
.and('include', '/administrator/quizzes/skill1Quiz');
60+
cy.get('[data-cy="buttonToQuiz"]')
61+
.should('have.attr', 'href')
62+
.and('include', '/administrator/quizzes/skill1Quiz');
63+
cy.get('[data-cy="buttonToQuiz"]').contains('View Quiz')
64+
});
65+
66+
});
67+
68+

e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"cy:run:oauth": "TZ=UTC cypress run --browser chrome --env oauthMode=true --config video=true",
2626
"cy:run:accessibility": "TZ=UTC cypress run --browser chrome --env enableLighthouse=true,enableAvgLighthouseScore=true --browser chrome --headless --spec \"cypress/e2e/accessibility/*.js\" --config video=true",
2727
"cy:run:dev": "TZ=UTC cypress run --browser chrome --config baseUrl=http://localhost:5173 --env visualRegressionType=base",
28-
"cy:run:dev:specificTest": "TZ=UTC cypress run --browser chrome --config baseUrl=http://localhost:5173 --spec \"cypress/e2e/metrics/projectMetrics_achievements_spec.js\" --env visualRegressionType=base",
28+
"cy:run:dev:specificTest": "TZ=UTC cypress run --browser chrome --config baseUrl=http://localhost:5173 --spec \"cypress/e2e/openai/opeanai_quiz_gen_spec.js\" --env visualRegressionType=base",
2929
"cy:run:dev:updateSnapshotForSpecificTests": "TZ=UTC cypress run --browser chrome --env visualRegressionType=base --config baseUrl=http://localhost:5173 --spec \"cypress/e2e/metrics/skillMetrics_spec.js\"",
3030
"cy:run:dev:metrics": "TZ=UTC cypress run --browser chrome --config baseUrl=http://localhost:5173 --spec \"cypress/e2e/metrics/projectMetrics_projects_spec.js,cypress/e2e/metrics/projectMetrics_subjects_spec.js,cypress/e2e/metrics/skillMetrics_spec.js,cypress/e2e/metrics/subjectMetrics_spec.js\"",
3131
"cy:run:dev:updateAdminSnapshots": "TZ=UTC cypress run --browser chrome --config baseUrl=http://localhost:5173 --env visualRegressionType=base --spec \"cypress/e2e/markdown_spec.js\"",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
data: {"id":"chat-1","object":"chat.completion.chunk","created":1700608923,"model":"model1","choices":[{"index":0,"delta":{"content":"{\n \"numQuestions\": 10,\n \"questions\": [\n {\n \"question\": \"Which piece can move diagonally in any direction?\",\n \"questionType\": \"SingleChoice\",\n \"answers\": [\n {\"answer\": \"Pawn\", \"isCorrect\": false},\n {\"answer\": \"Rook\", \"isCorrect\": false},\n {\"answer\": \"Knight\", \"isCorrect\": false},\n {\"answer\": \"Bishop\", \"isCorrect\": true}\n ]\n },"},"finish_reason":null}]}
2+
3+
data: {"id":"chat-1","object":"chat.completion.chunk","created":1700608923,"model":"model1","choices":[{"index":0,"delta":{"content":" {\n \"question\": \"Which chess piece can be placed in the center of the board on the starting move?\",\n \"questionType\": \"SingleChoice\",\n \"answers\": [\n {\"answer\": \"Rook\", \"isCorrect\": false},\n {\"answer\": \"Queen\", \"isCorrect\": false},\n {\"answer\": \"Bishop\", \"isCorrect\": false},\n {\"answer\": \"Knight\", \"isCorrect\": false},\n {\"answer\": \"King\", \"isCorrect\": false},\n {\"answer\": \"Pawn\", \"isCorrect\": true}\n ]\n }\n ]\n}"},"finish_reason":"stop"}]}
4+
5+
data: [DONE]

e2e-tests/serverConfigs/wiremock/mappings/openai-chess-edit.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"urlPath": "/v1/chat/completions",
66
"bodyPatterns": [
77
{ "contains": "chess" },
8-
{ "contains": "current description" }
8+
{ "contains": "current description" },
9+
{ "doesNotContain": "Quiz Generation" }
910
]
1011
},
1112
"response": {

e2e-tests/serverConfigs/wiremock/mappings/openai-chess.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"urlPath": "/v1/chat/completions",
66
"bodyPatterns": [
77
{ "contains": "chess" },
8-
{ "doesNotContain": "current description" }
8+
{ "doesNotContain": "current description" },
9+
{ "doesNotContain": "Quiz Generation" }
910
]
1011
},
1112
"response": {

e2e-tests/serverConfigs/wiremock/mappings/openai-jabberwocky.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"urlPath": "/v1/chat/completions",
66
"bodyPatterns": [
77
{
8-
"contains": "jabberwocky"
8+
"contains": "jabberwocky",
9+
"doesNotContain": "Quiz Generation"
910
}
1011
]
1112
},
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"priority": 1,
3+
"request": {
4+
"method": "POST",
5+
"urlPath": "/v1/chat/completions",
6+
"bodyPatterns": [
7+
{ "contains": "chess" },
8+
{ "doesNotContain": "Modify an existing quiz" },
9+
{ "contains": "Quiz Generation Task" }
10+
]
11+
},
12+
"response": {
13+
"status": 200,
14+
"headers": {
15+
"Content-Type": "text/event-stream"
16+
},
17+
"bodyFileName": "response-body-quiz-chess.txt",
18+
"transformers": ["response-template"],
19+
"chunkedDribbleDelay": {
20+
"numberOfChunks": 20,
21+
"totalDuration": 1500
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)