Skip to content

Example Questions Technology #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
.idea
folder
__pycache__
results
results

.vscode
.devcontainer

website/robotframework-RFCP-syllabus/
17 changes: 17 additions & 0 deletions website/docs/chapter-02/03_executing.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,21 @@ Which levels are written to the log can be controlled by the log level of an exe



## Quiz
<Quiz name="Executing RF"
question="
# What command is used to start a testsuite?

- [ ] rf /path/to/testsuite
- [X] robot /path/to/testsuite
- [ ] robotframework /path/to/testsuite

# Which HTML-files are generated?

- [x] log.html
- [ ] result.html
- [ ] executionReport.html
- [X] report.html

">
</Quiz>
35 changes: 35 additions & 0 deletions website/docs/example-exam/Example-exam.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Example exam

<Quiz name="example1"
question="
# Is this formatted as sourcecode?

```python
answer = 42
if answer == 42:
print('hello world')
```

- [x] Yes
- [ ] No

# Is the syntaxhighlighting correct?

```robot
VAR ${answer} = ${42}
```

- [x] Yes
- [ ] No

# What is the capital of France?
- [ ] Berlin
- [x] Paris
- [ ] Rome

# Is the sky blue?
- [x] Yes
- [ ] No

">
</Quiz>
3 changes: 3 additions & 0 deletions website/docs/example-exam/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"label": "Example Exam"
}
7,380 changes: 3,336 additions & 4,044 deletions website/package-lock.json

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
"version": "0.0.0",
"private": true,
"scripts": {
"prebuild": "npm run generate:createQuizList",
"docusaurus": "docusaurus",
"start": "docusaurus start",
"start-public": "docusaurus start --host 0.0.0.0",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"typecheck": "tsc"
"typecheck": "tsc",
"generate:createQuizList": "node src/components/Quiz/quizPrebuild.js"
},
"dependencies": {
"@docusaurus/core": "3.7.0",
Expand All @@ -21,8 +24,10 @@
"clsx": "^2.0.0",
"docusaurus-lunr-search": "^3.6.0",
"prism-react-renderer": "^2.3.0",
"quizdown-extended": "0.6.5",
"react": "^19.0.0",
"react-dom": "^19.0.0"
"react-dom": "^19.0.0",
"zustand": "^5.0.5"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "3.7.0",
Expand Down
3 changes: 3 additions & 0 deletions website/src/components/Quiz/Quiz.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#resultLink {
text-align: center;
}
108 changes: 108 additions & 0 deletions website/src/components/Quiz/Quiz.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// @ts-ignore
// eslint-disable @typescript-eslint/eslint/no-var-requires

import React from 'react';
import { useEffect } from 'react';
import 'quizdown-extended'
import useBaseUrl from '@docusaurus/useBaseUrl';
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';

import useQuizStore from './QuizStore';
import hljsDefineRobot from '../../robot';
import 'quizdown-extended/public/build/extensions/quizdownHighlight';
import './Quiz.css'


export default function Quiz(props) {

const quiz = useQuizStore((state) => state.quiz);
const addQuizResult = useQuizStore((state) => state.addQuizResult);
const resultBaseUrl = useBaseUrl('/quizResults');

const startQuiz = () => {
let node = document.querySelector('#quizDownContainer');

const config = {
startOnLoad: true, // detect and convert all div html elements with class quizdown
shuffleAnswers: true, // shuffle answers for each question
shuffleQuestions: true, // shuffle questions for each quiz
nQuestions: undefined, // display n questions at random, if shuffleQuestions is true
primaryColor: 'var(--quizdownPrimaryColor)', // primary CSS color
secondaryColor: 'var(--quizdownSecondaryColor)', // secondary CSS color
textColor: 'var(--quizdownTextColor)', // text color of some elements
buttonColor: 'var(--quizdownSecondaryColor)', // The background color of the buttons
locale: null, // language of the user interface (auto-detect per default)
enableRetry: true // allow the user to resubmit answers
};


quizdownHighlight.registerHljsLanguage("robot", hljsDefineRobot);
let quizDown = quizdown.register(quizdownHighlight)
quizDown.createApp(props.question, node, config);

quizDown.listenForStats(node, (event) => {
addQuizResult(generateQuizId(props.name), event.numberOfQuestions, event.solved, event.right, event.wrong);
});

return quizDown;
};


const setColorsDependingOnTheme = () => {
const theme = document.documentElement.getAttribute('data-theme');
if (theme === 'light') {
document.documentElement.style.setProperty('--quizdownSecondaryColor', "var(--ifm-color-emphasis-200)");
document.documentElement.style.setProperty('--quizdownTextColor', "black");
quizdownHighlight.setTheme("https://cdn.jsdelivr.net/npm/[email protected]/styles/stackoverflow-light.min.css");
} else {
document.documentElement.style.setProperty('--quizdownSecondaryColor', "var(--ifm-background-surface-color)");
document.documentElement.style.setProperty('--quizdownTextColor', "var(--ifm-color-primary)");
quizdownHighlight.setTheme("https://cdn.jsdelivr.net/npm/[email protected]/styles/androidstudio.min.css");
}
}

const generateQuizId = (name: string) => {

let page = window.location.pathname;
page = page.replace("/robotframework-RFCP-syllabus/", ""); // Remove beginning of the url

let id = page.replace("docs/", "") + "#" + name.replace(" ", "+");
id = id.toLocaleLowerCase();

return id;
}

const generateResultLink = () => {
if (ExecutionEnvironment.canUseDOM) {
return resultBaseUrl + "#" + generateQuizId(props.name);
}
return "#";
}

useEffect(() => {
// Add quiz to the central storage

// To set the color scheme of quizdown
document.documentElement.style.setProperty('--quizdownPrimaryColor', "var(--ifm-color-primary)");

const observer = new MutationObserver(() => {
setColorsDependingOnTheme();
});

observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] });

startQuiz();
setColorsDependingOnTheme();
return () => {
observer.disconnect();
};
}, [props.question]); // Add dependency array with props.question

return (
<span id="quizContainer">
<span id="quizDownContainer" className='quizdown'>
</span>
<a id="resultLink" href={ generateResultLink() } >View results</a>
</span>
);
}
73 changes: 73 additions & 0 deletions website/src/components/Quiz/QuizStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';

// Define the interfaces
interface QuizResult {
id: string;
quizId: string;
timestamp: string;
results: {
numberOfQuestions: number;
solved: number;
right: number;
wrong: number;
}
}

interface Quiz {
quiz: QuizResult[];
addQuizResult: (quizId: string, numberOfQuestions: number, solved: number, right: number, wrong: number) => string;
getQuizResults: (id: string) => QuizResult[];
}


// Create the store
const useQuizStore = create<Quiz>()(
persist(
(set, get) => ({
quiz: [],

// Action to add a new quiz
addQuizResult: (quizId: string, numberOfQuestions: number, solved: number, right: number, wrong: number): string => {
const state = get();

const id: string = self.crypto.randomUUID();;

const timestamp = new Date().toISOString();

// Otherwise add the new quiz
set({
quiz: [
...state.quiz,
{
id,
quizId,
timestamp,
results: {
numberOfQuestions,
solved,
right,
wrong,
}
}
]
});

return id;
},

getQuizResults: (quizId: string): QuizResult[] => {
const state = get();
return state.quiz.filter((value) => {
return value.quizId === quizId;
});
}
}),
{
name: 'quiz-results', // unique name for localStorage
}
)
);


export default useQuizStore;
38 changes: 38 additions & 0 deletions website/src/components/Quiz/quizComponents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file is automatically generated and will be overridden when running the build process.
* Generated on: 6/5/2025, 6:08:35 AM
*/

export interface QuizPage {
id: string;
name: string;
quizzes: QuizComponent[];
}

export interface QuizComponent {
id: string | null;
name: string;
}

export const quizPages: QuizPage[] = [
{
"id": "docs-chapter-02-03_executing",
"name": "executing",
"quizzes": [
{
"id": "chapter-02/executing#executing+rf",
"name": "Executing RF"
}
]
},
{
"id": "docs-example-exam",
"name": "example-exam",
"quizzes": [
{
"id": "example-exam#example1",
"name": "example1"
}
]
}
];
Loading