Skip to content

Commit fb7bfdd

Browse files
majestic-owl448gikfShaunSHamilton
authored
feat(curriculum): add more validation of table structure to Book Inventory App lab (freeCodeCamp#64647)
Co-authored-by: Krzysztof G. <60067306+gikf@users.noreply.github.com> Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
1 parent f7f6e9d commit fb7bfdd

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

curriculum/challenges/english/blocks/lab-book-inventory-app/66a207974c806a19d6607073.md

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,27 @@ assert.equal(document.querySelector('h1')?.innerText.trim(), 'Book Inventory');
4242
You should have only one `h1` element.
4343
4444
```js
45-
assert.equal(document.querySelectorAll('h1')?.length, 1);
45+
assert.lengthOf(document.querySelectorAll('h1'), 1);
4646
```
4747
4848
You should have a `table` element.
4949
5050
```js
51-
assert.equal(document.querySelectorAll('table')?.length, 1);
51+
assert.lengthOf(document.querySelectorAll('table'), 1);
5252
```
5353
54-
Your `table` element should have five columns.
54+
You should have one `thead` element and one `tbody` element inside `table`.
5555
5656
```js
57-
const rows = document.querySelectorAll('tr');
58-
assert.isNotEmpty(rows);
59-
for (const row of rows) {
60-
assert.equal(row.children.length, 5);
61-
}
57+
assert.lengthOf(document.querySelectorAll("table > thead"), 1);
58+
assert.lengthOf(document.querySelectorAll("table > tbody"), 1);
59+
```
60+
61+
Inside the `thead` there should be one `tr` with 5 `th` elements.
62+
63+
```js
64+
assert.lengthOf(document.querySelectorAll("table > thead > tr"), 1);
65+
assert.lengthOf(document.querySelectorAll("table > thead > tr > th"), 5);
6266
```
6367
6468
Your first column should have the text `Title` as the heading.
@@ -98,11 +102,21 @@ const rows = document.querySelectorAll('tr');
98102
assert.isAtLeast(rows.length, 4);
99103
```
100104
105+
Each row should always have 5 columns.
106+
107+
```js
108+
const rows = document.querySelectorAll('tbody tr');
109+
assert.isNotEmpty(rows);
110+
for (const row of rows) {
111+
assert.lengthOf(row.children, 5);
112+
}
113+
```
114+
101115
Each table row except the heading row should have either the class `read`, `to-read`, or `in-progress`.
102116
103117
```js
104118
const rows = document.querySelectorAll('tr');
105-
assert.isAtLeast(rows.length, 4);
119+
assert.isNotEmpty(rows);
106120
for (let i = 1; i < rows.length; i++) {
107121
const classList = [...rows[i].classList];
108122
const currentProgress = classList[0];
@@ -114,7 +128,7 @@ for (let i = 1; i < rows.length; i++) {
114128
115129
```js
116130
const statusColumnData = document.querySelectorAll('td:nth-child(4)');
117-
assert.isAbove(statusColumnData.length, 0);
131+
assert.isNotEmpty(statusColumnData);
118132
for (let e of statusColumnData) {
119133
assert.equal(e?.children[0]?.tagName, 'SPAN');
120134
}
@@ -124,7 +138,7 @@ Each `span` element of the `Status` column should have the class of `status`.
124138
125139
```js
126140
const statusSpans = document.querySelectorAll('tr td:nth-child(4) :first-child');
127-
assert.isAbove(statusSpans.length, 0);
141+
assert.isNotEmpty(statusSpans);
128142
for (let e of statusSpans) {
129143
assert.isTrue(e.classList.contains('status'));
130144
}
@@ -135,7 +149,7 @@ Each `.status` element should have the text `Read`, `To Read`, or `In Progress`,
135149
```js
136150
const statusSpans = document.querySelectorAll('tr td:nth-child(4) :first-child');
137151
const rows = Array.from(document.querySelectorAll('tr')).slice(1);
138-
assert.isAbove(statusSpans.length, 0);
152+
assert.isNotEmpty(statusSpans);
139153
for (let i = 0; i < rows.length; i++) {
140154
switch (statusSpans[i]?.innerText.trim()) {
141155
case 'Read':
@@ -157,7 +171,7 @@ for (let i = 0; i < rows.length; i++) {
157171
158172
```js
159173
const rateColumnData = document.querySelectorAll('tr td:last-child');
160-
assert.isAbove(rateColumnData.length, 0);
174+
assert.isNotEmpty(rateColumnData);
161175
for (let e of rateColumnData) {
162176
assert.equal(e.children[0]?.tagName, 'SPAN')
163177
}
@@ -167,7 +181,7 @@ Each `span` element which is a direct child of a `td` element of the `Rate` colu
167181
168182
```js
169183
const rateSpans = document.querySelectorAll('tr td:last-child > span:first-child');
170-
assert.isAbove(rateSpans.length, 0);
184+
assert.isNotEmpty(rateSpans);
171185
for (let e of rateSpans) {
172186
assert.equal(e.classList[0], 'rate');
173187
}
@@ -177,7 +191,7 @@ Each `.rate` element should contain three empty `span` elements.
177191
178192
```js
179193
const rateSpans = document.getElementsByClassName('rate');
180-
assert.isAbove(rateSpans.length, 0);
194+
assert.isNotEmpty(rateSpans);
181195
for (let e of rateSpans) {
182196
assert.equal(e.children.length, 3);
183197
for (let child of e.children) {
@@ -191,7 +205,7 @@ for (let e of rateSpans) {
191205
192206
```js
193207
const readBooksRates = document.querySelectorAll('.read .rate');
194-
assert.isAbove(readBooksRates.length, 0);
208+
assert.isNotEmpty(readBooksRates);
195209
for (let e of readBooksRates) {
196210
assert.oneOf(e.classList[1], ['one', 'two', 'three']);
197211
}

0 commit comments

Comments
 (0)