2022-11-15 00:53:07 +00:00
|
|
|
import {strict as assert} from "node:assert";
|
2022-11-11 02:39:40 +00:00
|
|
|
import {describe, it, beforeEach} from "mocha";
|
|
|
|
import {saveReviewsToStorage, getReviewsFromStorage} from "./localStorage.js";
|
2022-11-10 01:35:41 +00:00
|
|
|
|
|
|
|
describe("test app localStorage interaction", () => {
|
2022-11-17 00:10:31 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localStorage.clear();
|
|
|
|
});
|
|
|
|
|
2022-11-10 01:35:41 +00:00
|
|
|
it("get after init", () => {
|
|
|
|
assert.deepEqual(getReviewsFromStorage(), []);
|
|
|
|
});
|
|
|
|
it("store one then get", () => {
|
2022-11-10 22:33:47 +00:00
|
|
|
let reviews = [{
|
2022-11-10 01:35:41 +00:00
|
|
|
"imgSrc": "sample src",
|
|
|
|
"imgAlt": "sample alt",
|
|
|
|
"mealName": "sample name",
|
|
|
|
"restaurant": "sample restaurant",
|
2022-11-10 22:33:47 +00:00
|
|
|
"rating": 5,
|
|
|
|
"tags": ["tag 1", "tag 2", "tag 3"]
|
2022-11-10 01:35:41 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
saveReviewsToStorage(reviews);
|
|
|
|
assert.deepEqual(getReviewsFromStorage(), reviews);
|
2022-11-10 22:33:47 +00:00
|
|
|
});
|
|
|
|
it("repeated store one more and get", () => {
|
2022-11-11 02:39:40 +00:00
|
|
|
let reviews = [];
|
|
|
|
|
2022-11-10 22:33:47 +00:00
|
|
|
assert.deepEqual(getReviewsFromStorage(), reviews);
|
|
|
|
|
|
|
|
for(let i = 0; i < 1000; i++){
|
|
|
|
reviews = getReviewsFromStorage();
|
|
|
|
|
|
|
|
reviews.push(
|
|
|
|
{
|
|
|
|
"imgSrc": `sample src ${i}`,
|
|
|
|
"imgAlt": `sample alt ${i}`,
|
|
|
|
"mealName": `sample name ${i}`,
|
|
|
|
"restaurant": `sample restaurant ${i}`,
|
|
|
|
"rating": i,
|
|
|
|
"tags": [`tag ${3*i}`, `tag ${3*i + 1}`, `tag ${3*i + 2}`]
|
|
|
|
}
|
2022-11-15 00:53:07 +00:00
|
|
|
);
|
2022-11-10 22:33:47 +00:00
|
|
|
saveReviewsToStorage(reviews);
|
|
|
|
assert.deepEqual(getReviewsFromStorage(), reviews);
|
|
|
|
}
|
2022-11-15 01:11:48 +00:00
|
|
|
}).timeout(10000);
|
2022-11-11 20:07:58 +00:00
|
|
|
});
|