mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-19 21:09:51 +08:00
fix(curriculum): add tests for globals in cash register (#54769)
Co-authored-by: Ilenia <26656284+ilenia-magoni@users.noreply.github.com> Co-authored-by: Ilenia M <nethleen@gmail.com>
This commit is contained in:
parent
5922014401
commit
121db4a02e
@ -53,6 +53,27 @@ Fulfill the user stories and pass all the tests below to complete this project.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have the HTML file link to the JavaScript file.
|
||||
|
||||
```js
|
||||
const script = document.querySelector('script[data-src$="script.js"]');
|
||||
assert.isNotNull(script);
|
||||
```
|
||||
|
||||
You should have a global variable called `price`.
|
||||
|
||||
```js
|
||||
price = 10;
|
||||
assert.strictEqual(price, 10);
|
||||
```
|
||||
|
||||
You should have a global variable called `cid`.
|
||||
|
||||
```js
|
||||
cid = [];
|
||||
assert.isDefined(cid);
|
||||
```
|
||||
|
||||
You should have an `input` element with an `id` of `"cash"`.
|
||||
|
||||
```js
|
||||
@ -119,7 +140,10 @@ cid = [['PENNY', 1.01], ['NICKEL', 2.05], ['DIME', 3.1], ['QUARTER', 4.25], ['ON
|
||||
const expected = ['Status: OPEN', 'QUARTER: $0.5'];
|
||||
cashInput.dispatchEvent(new Event('change'));
|
||||
purchaseBtn.click();
|
||||
assert.isTrue(expected.every(str => changeDueDiv.innerText.trim().toLowerCase().includes(str.toLowerCase())));
|
||||
const result = changeDueDiv.innerText.trim().toLowerCase();
|
||||
assert.isTrue(expected.every(str => result.includes(str.toLowerCase())));
|
||||
const notExpected = [/PENNY/, /NICKEL/, /DIME/, /ONE [^H]/, /FIVE/, /TEN/, /TWENTY/, /ONE HUNDRED/];
|
||||
assert.isTrue(!notExpected.some(regex => result.match(new RegExp(regex, 'i'))))
|
||||
```
|
||||
|
||||
When `price` is `3.26`, the value in the `#cash` element is `100`, `cid` is `[["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]`, and the `#purchase-btn` element is clicked, the value in the `#change-due` element should be `"Status: OPEN TWENTY: $60 TEN: $20 FIVE: $15 ONE: $1 QUARTER: $0.5 DIME: $0.2 PENNY: $0.04"`.
|
||||
@ -136,7 +160,10 @@ cid = [['PENNY', 1.01], ['NICKEL', 2.05], ['DIME', 3.1], ['QUARTER', 4.25], ['ON
|
||||
const expected = ['Status: OPEN', 'TWENTY: $60', 'TEN: $20', 'FIVE: $15', 'ONE: $1', 'QUARTER: $0.5', 'DIME: $0.2', 'PENNY: $0.04'];
|
||||
cashInput.dispatchEvent(new Event('change'));
|
||||
purchaseBtn.click();
|
||||
assert.isTrue(expected.every(str => changeDueDiv.innerText.trim().toLowerCase().includes(str.toLowerCase())));
|
||||
const result = changeDueDiv.innerText.trim().toLowerCase();
|
||||
assert.isTrue(expected.every(str => result.includes(str.toLowerCase())));
|
||||
const notExpected = [/NICKEL/];
|
||||
assert.isTrue(!notExpected.some(regex => result.match(new RegExp(regex, 'i'))))
|
||||
```
|
||||
|
||||
When `price` is `19.5`, the value in the `#cash` element is `20`, `cid` is `[["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]`, and the `#purchase-btn` element is clicked, the value in the `#change-due` element should be `"Status: INSUFFICIENT_FUNDS"`
|
||||
@ -185,7 +212,10 @@ cid = [['PENNY', 0.5], ['NICKEL', 0], ['DIME', 0], ['QUARTER', 0], ['ONE', 0], [
|
||||
const expected = ['Status: CLOSED', 'PENNY: $0.5'];
|
||||
cashInput.dispatchEvent(new Event('change'));
|
||||
purchaseBtn.click();
|
||||
assert.isTrue(expected.every(str => changeDueDiv.innerText.trim().toLowerCase().includes(str.toLowerCase())));
|
||||
const result = changeDueDiv.innerText.trim().toLowerCase();
|
||||
assert.isTrue(expected.every(str => result.includes(str.toLowerCase())));
|
||||
const notExpected = [/NICKEL/, /DIME/, /QUARTER/, /ONE [^H]/, /FIVE/, /TEN/, /TWENTY/, /ONE HUNDRED/];
|
||||
assert.isTrue(!notExpected.some(regex => result.match(new RegExp(regex, 'i'))))
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
Loading…
Reference in New Issue
Block a user