Skip to content

Commit 5d72db3

Browse files
committed
chore: update and fix tests
1 parent 793df2c commit 5d72db3

26 files changed

+225
-151
lines changed

tests/checkValidAyahId.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { checkValidAyahId, meta } from "../src"
2-
import { isValidAyahId } from "../src/typeGuards"
1+
import { checkValidAyahId, isValidAyahId, meta } from "../src"
32

43
describe("checkValidAyahId", () => {
54
it("should throw RangeError for ayah id less than 1", () => {

tests/checkValidSurah.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { checkValidSurah, meta } from "../src"
2-
import { isValidSurah } from "../src/typeGuards"
1+
import { isValidSurah, checkValidSurah, meta } from "../src"
32

43
describe("checkValidSurah", () => {
54
it("should return true for valid surah numbers", () => {

tests/checkValidSurahAyah.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { checkValidSurahAyah } from "../src"
2-
import { isValidSurahAyah } from "../src/typeGuards"
1+
import { checkValidSurahAyah, isValidSurahAyah } from "../src"
32

43
describe("checkValidSurahAyah", () => {
54
it("should return true for valid surah and ayah", () => {

tests/findJuzAndShift.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { meta } from "../src"
2-
import { findJuzAndShift, findJuzAndShiftByAyahId } from "../src/findJuzAndShift"
1+
import { meta, findJuzAndShift, findJuzAndShiftByAyahId } from "../src"
32

43
describe("findJuzAndShift", () => {
54
it("basic", () => {

tests/findJuzHizbByAyahId.spec.ts

Lines changed: 0 additions & 100 deletions
This file was deleted.

tests/findJuzMetaBySurah.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { expect, vi } from "vitest"
2-
import { findJuzMetaBySurah } from "../src/findJuzMetaBySurah"
1+
import { findJuzMetaBySurah } from "../src"
32
import * as findSurahByAyahIdModule from "../src/findSurahByAyahId"
43

54
describe("findJuzMetaBySurah", () => {

tests/findPage.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { expect, vi } from "vitest"
2-
import { findPage } from "../src"
1+
import { findPage, findPagebyAyahId } from "../src"
32
import * as ayahIdModule from "../src/findAyahIdBySurah"
4-
import { findPagebyAyahId } from "../src/findPagebyAyahId"
53
import * as module from "../src/validation"
64

75
describe("findPage", () => {

tests/findRangeAroundAyah.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ describe("findRangeAroundSurahAyah", () => {
4545
expect(findRangeAroundSurahAyah(114, 6, "surah")).toEqual([6231, 6236])
4646
})
4747

48+
it("should return correct ruku range for first ayah", () => {
49+
expect(findRangeAroundSurahAyah(1, 1, "ruku")).toEqual([1, 7])
50+
expect(findRangeAroundSurahAyah(1, 7, "ruku")).toEqual([1, 7])
51+
})
52+
53+
it("should return correct ruku range for last ayah", () => {
54+
expect(findRangeAroundSurahAyah(114, 1, "ruku")).toEqual([6231, 6236])
55+
expect(findRangeAroundSurahAyah(114, 4, "ruku")).toEqual([6231, 6236])
56+
})
57+
4858
it("should handle edge cases in findRangeAroundAyah", () => {
4959
// First ayah
5060
expect(findRangeAroundAyah(1, "juz")).toEqual([1, 148])

tests/findRubAlHizb.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { findRubAlHizb, findRubAlHizbByAyahId, HizbQuarterList, JuzList, meta } from "../src"
22

33
describe("findRubAlHizb", () => {
4-
it("should return correct JuzHizb for first surah and ayah", () => {
4+
it("should return correct RubAlHizb for first surah and ayah", () => {
55
expect(findRubAlHizb(1, 1)).toEqual(1)
66
})
77

8-
it("should return correct JuzHizb for a middle surah and ayah", () => {
8+
it("should return correct RubAlHizb for a middle surah and ayah", () => {
99
expect(findRubAlHizb(18, 1)).toEqual(117)
1010
})
1111

12-
it("should return correct JuzHizb for a last surah and ayah", () => {
12+
it("should return correct RubAlHizb for a last surah and ayah", () => {
1313
expect(findRubAlHizb(114, 6)).toEqual(meta.numRubAlHizbs)
1414

1515
expect(findRubAlHizb(114, 6)).toEqual(240)

tests/findRukuByAyahId.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { describe, it, expect } from "vitest"
2-
import { findRukuByAyahId } from "../src/findRukuByAyahId"
1+
import { findRukuByAyahId } from "../src"
32

43
describe("findRukuByAyahId", () => {
54
it("should find correct ruku for valid ayah IDs", () => {

tests/findSurahByAyahId.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { meta } from "../src"
2-
import { findSurahAyahByAyahId } from "../src/findSurahAyahByAyahId"
1+
import { meta, findSurahAyahByAyahId } from "../src"
32

43
describe("findSurahByAyahId", () => {
54
it("surah of ayahId 1", () => {

tests/getAyahMetasForSurah.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { describe, it, expect } from "vitest"
2-
import { getAyahMetasForSurah } from "../src/getAyahMetasForSurah"
3-
import { Surah } from "../src/types"
4-
import { getAyahMeta } from "../src/getAyahMeta"
5-
import { SurahList } from "../src"
1+
import { getAyahMetasForSurah, getAyahMeta, SurahList } from "../src"
2+
import type { Surah } from "../src"
63

74
describe("getAyahMetasForSurah", () => {
85
it("should return correct number of ayahs for Al-Fatiha (surah 1)", () => {
@@ -24,8 +21,8 @@ describe("getAyahMetasForSurah", () => {
2421
})
2522

2623
it("should return correct number of ayahs for Al-Fatiha (surah 1)", () => {
27-
for (let i: Surah = 1; i <= 114; i++) {
28-
const result = getAyahMetasForSurah(i as Surah)
24+
for (let i = 1 as Surah; i <= 114; i++ as Surah) {
25+
const result = getAyahMetasForSurah(i)
2926
const [
3027
startAyahId, ayahCount
3128
] = SurahList[i]

tests/getJuzMeta.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { getJuzMeta } from "../src/getJuzMeta"
2-
import { JuzMeta } from "../src/types"
1+
import { JuzMeta, getJuzMeta } from "../src"
32

43
describe("getJuzMeta", () => {
54
it("should return correct metadata for a valid Juz number", () => {

tests/getList.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { meta } from "../src"
2-
import { getList, partNames, PartType } from "../src/getList"
1+
import { meta, getList } from "../src"
2+
import { partNames, PartType } from "../src/getList"
33

44
describe("getList", () => {
55
it("should return an array", () => {
@@ -48,13 +48,10 @@ describe("getList", () => {
4848

4949
it("should return same array on multiple calls", () => {
5050
const res = getList("surah")
51-
console.log(res)
51+
const res2 = getList("surah")
52+
expect(res).toEqual(res2)
5253
})
5354

54-
it("should return same array on multiple calls", () => {
55-
const res = getList("manzil")
56-
console.log(res)
57-
})
5855
// it("should return array in ascending order", () => {
5956
// const list = getList()
6057
// const sorted = [...list].sort((a, b) => a - b)

tests/getRubAlHizbByAyahId.spec.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { getRubAlHizb, findJuzByAyahId, getRubAlHizbByAyahId, HizbQuarterList, JuzList, meta, RubAlHizbId } from "../src"
2+
3+
import * as module from "../src/validation"
4+
5+
describe("getRubAlHizbByAyahId", () => {
6+
beforeEach(() => {
7+
vi.clearAllMocks()
8+
})
9+
10+
it("basic", () => {
11+
expect(getRubAlHizbByAyahId(1)).toEqual({
12+
hizbId: 1,
13+
juz: 1,
14+
juzPart: 1,
15+
rubAlHizbId: 1
16+
})
17+
expect(getRubAlHizbByAyahId(32)).toEqual({
18+
hizbId: 1,
19+
juz: 1,
20+
juzPart: 1,
21+
rubAlHizbId: 1
22+
})
23+
expect(getRubAlHizbByAyahId(33)).toEqual({
24+
hizbId: 1,
25+
juz: 1,
26+
juzPart: 2,
27+
rubAlHizbId: 2
28+
})
29+
expect(getRubAlHizbByAyahId(148)).toEqual({
30+
hizbId: 2,
31+
juz: 1,
32+
juzPart: 8,
33+
rubAlHizbId: 8
34+
})
35+
expect(getRubAlHizbByAyahId(149)).toEqual({
36+
hizbId: 3,
37+
juz: 2,
38+
juzPart: 1,
39+
rubAlHizbId: 9
40+
})
41+
expect(getRubAlHizbByAyahId(meta.numAyahs)).toEqual({
42+
hizbId: 60,
43+
juzPart: 8,
44+
rubAlHizbId: 240,
45+
juz: 30
46+
})
47+
})
48+
49+
it("should return correct RubAlHizb for first ayah", () => {
50+
const result = getRubAlHizbByAyahId(1)
51+
expect(result).toEqual({
52+
hizbId: 1,
53+
juz: 1,
54+
juzPart: 1,
55+
rubAlHizbId: 1
56+
})
57+
})
58+
59+
it("should return correct RubAlHizb for last ayah", () => {
60+
const result = getRubAlHizbByAyahId(6236)
61+
expect(result).toEqual({
62+
hizbId: 60,
63+
juzPart: 8,
64+
rubAlHizbId: 240,
65+
juz: 30
66+
})
67+
})
68+
69+
it("should return correct RubAlHizb for ayah 3000", () => {
70+
const result = getRubAlHizbByAyahId(3000)
71+
expect(result).toEqual({
72+
hizbId: 37,
73+
juzPart: 4,
74+
rubAlHizbId: 148,
75+
juz: 19
76+
})
77+
})
78+
79+
it("Each Rub Ul Hizb should have a corresponding Juz", () => {
80+
for (let rubAlHizbId = 1 as RubAlHizbId; rubAlHizbId <= meta.numRubAlHizbs; rubAlHizbId++ as RubAlHizbId) {
81+
const juzAyahId = JuzList[Math.ceil(rubAlHizbId / 8)]
82+
const rubulHizbAyahId = HizbQuarterList[rubAlHizbId]
83+
const rubMeta = getRubAlHizbByAyahId(rubulHizbAyahId)
84+
const hizbAyahId = HizbQuarterList[Math.ceil((rubAlHizbId) / 4) * 4 - 3]
85+
// console.log("Maqra:", rubAlHizbId, "Maqra Ayah:", rubulHizbAyahId, findSurahByAyahId(rubulHizbAyahId), "hizb Ayah id", hizbAyahId, `Juz Ayah:`, juzAyahId, rubMeta)
86+
expect(rubMeta.juz).toEqual(findJuzByAyahId(juzAyahId))
87+
expect(rubAlHizbId).toEqual(rubMeta.rubAlHizbId)
88+
expect(getRubAlHizb(rubAlHizbId)).toEqual(rubMeta)
89+
expect(getRubAlHizbByAyahId(hizbAyahId).hizbId).toEqual(rubMeta.hizbId)
90+
expect(getRubAlHizbByAyahId(juzAyahId).hizbId).toEqual(rubMeta.juzPart <= 4 ? rubMeta.hizbId : rubMeta.hizbId - 1)
91+
}
92+
})
93+
94+
it("should call checkValidAyahId with correct argument", () => {
95+
const spy = vi.spyOn(module, "checkValidAyahId")
96+
97+
getRubAlHizbByAyahId(100)
98+
expect(spy).toHaveBeenCalledWith(100)
99+
})
100+
101+
describe("getRubAlHizbByAyahId error handling", () => {
102+
it("should throw an error for invalid Ayah ID", () => {
103+
expect(() => getRubAlHizbByAyahId(6237)).toThrow()
104+
expect(() => getRubAlHizbByAyahId(0)).toThrow()
105+
})
106+
})
107+
108+
it("should handle edge case when ayahId is at hizb boundary", () => {
109+
const result = getRubAlHizbByAyahId(148)
110+
expect(result).toEqual({
111+
hizbId: 2,
112+
juzPart: 8,
113+
rubAlHizbId: 8,
114+
juz: 1
115+
})
116+
})
117+
})

0 commit comments

Comments
 (0)