Skip to content

Commit

Permalink
Merge pull request #17 from TeaByte/NewTestingWay
Browse files Browse the repository at this point in the history
New testing way
  • Loading branch information
m7medVision authored Jan 16, 2024
2 parents 048a33e + 65026ba commit 0b508d9
Show file tree
Hide file tree
Showing 33 changed files with 260 additions and 228 deletions.
6 changes: 3 additions & 3 deletions components/EditorSplit.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Editor from "../islands/Editor.tsx";
import { getPreCode } from "../utils/precode.ts";
import { getTestCase } from "../utils/testcase.ts";
import { getTestingCode } from "../utils/testingcode.ts";

export default function EditorSplit(props: { slug: string }) {
const precode = getPreCode(props.slug);
const testcases = getTestCase(props.slug);
const testingcode = getTestingCode(props.slug);
return (
<>
<div class="mt-2">
Expand All @@ -25,7 +25,7 @@ export default function EditorSplit(props: { slug: string }) {
</div>
<Editor
preCode={precode}
testcases={testcases}
testingCode={testingcode}
slug={props.slug}
/>
</>
Expand Down
7 changes: 4 additions & 3 deletions components/MarkdownSplit.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { render } from "$gfm";
import { render } from "https://deno.land/x/gfm/mod.ts";
import { Course } from "../utils/types.ts";

import EditButton from "../components/EditButton.tsx";
import IconAppWindow from "https://deno.land/x/tabler_icons_tsx@0.0.5/tsx/app-window.tsx";

export default function MarkdownSplit(
{ course, lable, lableSlug }: {
Expand Down Expand Up @@ -39,7 +38,9 @@ export default function MarkdownSplit(
id="document"
class="markdown-body"
style={{ backgroundColor: "inherit" }}
dangerouslySetInnerHTML={{ __html: render(course.content) }}
dangerouslySetInnerHTML={{ __html: render(course.content, {
disableHtmlSanitization: true
}) }}
/>
</section>
);
Expand Down
3 changes: 3 additions & 0 deletions courses/compound-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ myVar *= 5;
```js
myVar /= 5;
```
<div class="quiz">
قم بإنشاء متغير يسمى `myVar` واجعل قيمته 5. ثم استخدم عامل التشغيل `+=` لإضافة 10 إلى `myVar`.
</div>
3 changes: 3 additions & 0 deletions courses/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ order: 1
استفسارك في المجتمع. أعضاء المجتمع الآخرين سيكونون سعداء بمساعدتك ومشاركة
تجاربهم معك. هذا التفاعل يمكن أن يجعل عملية التعلم أكثر سهولة ومتعة.

<div class="quiz">
لتخطي هذا الدرس إضغط على زر إختبار
</div>
<!-- <mark>recommended</mark> -->

أنضم الان! [قناه التلغرام](https://t.me/NakhlahJS),
Expand Down
23 changes: 0 additions & 23 deletions courses/testcases.json

This file was deleted.

3 changes: 3 additions & 0 deletions courses/variables/case-sensitivity-in-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ var someVariable;
var anotherVariableName;
var thisVariableNameIsSoLong;
```
<div class="quiz">
قم بجمع متغيرين واجعلهما يساويان `5`. من ثم قم بطباعة الناتج في ال`console`.
</div>
4 changes: 3 additions & 1 deletion courses/variables/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ JavaScript. يمكنك عبر المثال التالي:
var myName = "Yazan";
console.log(myName);
```

<div class="quiz">
قم بطباعة أي شيء على الشاشة
</div>
سيكون مخرج التعليمات البرمجية السابقه `Yazan` على الشاشة. **يمكن تنفي التعليمات
السابقه في الموقع عبر الضغط على الرابط التالي **
[هنا](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string).
Expand Down
5 changes: 5 additions & 0 deletions courses/variables/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ var myName = "Yazan";

من الشائع تهيئة متغير إلى قيمة أولية في نفس السطر الذي تم الإعلان عنه.


`"Yazan"` يسمى سلسلة حرفية. السلسلة الحرفية، أو السلسلة، عبارة عن سلسلة من صفر
أو أكثر من الأحرف المحاطة بعلامات اقتباس مفردة أو مزدوجة.

<div class="quiz">
قم بإنشاء متغير ما و جعل اسمك قيمته.
</div>

يمكنك التعرف على المزيد عن (سلسلة, String) في
[MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string).
27 changes: 0 additions & 27 deletions courses/variables/testcases.json

This file was deleted.

3 changes: 3 additions & 0 deletions courses/variables/the-var-let-const.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ x = 10; // اعاده تعيين قيمه
// يمكن اعاده تعيين قيمه ( let )
// لايمكن اعاده تعيين قيمه ( const )
```
<div class="quiz">
ليس أي إختبارات لهذا الدرس فقط قم بالضغط على إختبار من ثم إنتقل للدرس التالي
</div>
4 changes: 4 additions & 0 deletions courses/variables/uninitialized-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ console.log(c); // "undefined String!"
سنتعرف قريبًا على العمليات الحسابيه على الارقام والسلاسل قريبا

</mark>

<div class="quiz">
قم بتعريف أي متغير ثم غير قيمته إلى "عربي أنا"
</div>
2 changes: 0 additions & 2 deletions fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as $about from "./routes/about.tsx";
import * as $api_test from "./routes/api/test.ts";
import * as $group_slug_ from "./routes/group/[slug].tsx";
import * as $index from "./routes/index.tsx";
import * as $DoTest from "./islands/DoTest.ts";
import * as $Editor from "./islands/Editor.tsx";
import * as $Progress from "./islands/Progress.tsx";
import * as $ProgressCheck from "./islands/ProgressCheck.tsx";
Expand All @@ -31,7 +30,6 @@ const manifest = {
"./routes/index.tsx": $index,
},
islands: {
"./islands/DoTest.ts": $DoTest,
"./islands/Editor.tsx": $Editor,
"./islands/Progress.tsx": $Progress,
"./islands/ProgressCheck.tsx": $ProgressCheck,
Expand Down
85 changes: 0 additions & 85 deletions islands/DoTest.ts

This file was deleted.

82 changes: 48 additions & 34 deletions islands/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { useEffect, useState } from "preact/hooks";
import { useToast } from "./useToast.ts";
import { doTests } from "./DoTest.ts";

interface EditorProps {
preCode: string;
testcases: any[];
testingCode: string;
slug: string;
}

// deno-lint-ignore no-var
declare var window: Window & typeof globalThis;
interface Window {
// deno-lint-ignore no-explicit-any
editor: any;
}

Expand All @@ -36,45 +37,58 @@ export default function Editor(props: EditorProps) {
setOutput("");
}
function handleCodeTest() {
// setTesting(true);
// const code: string = window.editor.getValue() || "";
// const runOutput = handleCodeRun();
// const testcases = props.testcases;
// if (testcases.length === 0) {
// showToast({
// msg: "لا يوجد اختبارات لهذا الدرس",
// type: "info",
// });
// return;
// }
// const pass = doTests(testcases, code, runOutput);
// if (pass) {
// showToast({
// msg: "تم تجاوز الاختبارات بنجاح",
// type: "success",
// });
// localStorage.setItem(props.slug, "done");
// setTesting(false);
// return;
// } else {
// showToast({
// msg: "لم يتم تجاوز الاختبارات",
// type: "error",
// });
// setTesting(false);
// return;
// }
showToast({
msg: "هذه الميزة غير متوفرة حالياً",
type: "warning",
});
setTesting(true);
const code: string = window.editor.getValue() || "";
if (props.testingCode === "") {
showToast(
{
msg: "لا يوجد اختبارات لهذا السؤال",
type: "info",
}
)
setTesting(false);
return;
}

// deno-lint-ignore prefer-const
let isPass = false;
// deno-lint-ignore prefer-const
let msg = "هناك خطأ في الاختبارات";
try {
eval(props.testingCode);
if (isPass) {
showToast({
msg: "تم تجاوز الاختبارات بنجاح",
type: "success",
});
localStorage.setItem(props.slug, "done");
setTesting(false);
return;
} else {
showToast({
msg: msg,
type: "error",
});
setTesting(false);
return;
}
} catch (error) {
console.log(error);
showToast({
msg: "لم يتم تجاوز الاختبارات",
type: "error",
});
setTesting(false);
return;
}
}

function handleCodeRun() {
const code: string | undefined = window.editor.getValue();
try {
const capturedOutput: string[] = [];
const originalConsoleLog = console.log;
// deno-lint-ignore no-explicit-any
console.log = (...args: any[]) => {
capturedOutput.push(
args.map((arg) => {
Expand Down
1 change: 0 additions & 1 deletion islands/Progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ function Progress() {
const [done, setDone] = useState(0);
const [total, setTotal] = useState(0);
useEffect(() => {
console.log(localStorage);
const done = Object.keys(localStorage).filter((key) => {
return localStorage.getItem(key) === "done";
});
Expand Down
1 change: 1 addition & 0 deletions precodes/compound-operators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var myVar = 5;
1 change: 1 addition & 0 deletions precodes/intro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("مرحبا بكم في منصة نخلة")
Loading

0 comments on commit 0b508d9

Please sign in to comment.