-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.test.js
More file actions
104 lines (90 loc) · 3.07 KB
/
Copy pathmain.test.js
File metadata and controls
104 lines (90 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const { expect } = require("chai");
const {
getTotalBooksCount,
getTotalAccountsCount,
getBooksBorrowedCount,
getMostCommonGenres,
getMostPopularBooks,
getMostPopularAuthors,
} = require("../public/src/home.js");
const authorsFixture = require("./fixtures/authors.fixture");
const booksFixture = require("./fixtures/books.fixture");
describe("Home Page", () => {
let authors;
let books;
beforeEach(() => {
authors = authorsFixture.slice();
books = booksFixture.slice();
});
describe("getTotalBooksCount()", () => {
it("should return the total number of books in the array", () => {
const actual = getTotalBooksCount([{}, {}]);
expect(actual).to.equal(2);
});
it("should return zero if the array is empty", () => {
const actual = getTotalBooksCount([]);
expect(actual).to.equal(0);
});
});
describe("getTotalAccountsCount()", () => {
it("should return the total number of accounts in the array", () => {
const actual = getTotalAccountsCount([{}, {}]);
expect(actual).to.equal(2);
});
it("should return zero if the array is empty", () => {
const actual = getTotalAccountsCount([]);
expect(actual).to.equal(0);
});
});
describe("getBooksBorrowedCount()", () => {
it("should return the total number of books that are currently borrowed", () => {
const actual = getBooksBorrowedCount(books);
expect(actual).to.equal(6);
});
});
describe("getMostCommonGenres()", () => {
it("should return an ordered list of most common genres", () => {
const actual = getMostCommonGenres(books);
const [first, second] = [
{ name: "Science", count: 3 },
{ name: "Classics", count: 2 },
];
expect(actual[0]).to.eql(first);
expect(actual[1]).to.eql(second);
});
it("should limit the list to the top five", () => {
const actual = getMostCommonGenres(books);
expect(actual.length).to.equal(5);
});
});
describe("getMostPopularBooks()", () => {
it("should return an ordered list of most popular books", () => {
const actual = getMostPopularBooks(books);
const [first, second] = [
{ name: "sit eiusmod occaecat eu magna", count: 11 },
{ name: "ullamco est minim", count: 5 },
];
expect(actual[0]).to.eql(first);
expect(actual[1]).to.eql(second);
});
it("should limit the list to the top five", () => {
const actual = getMostPopularBooks(books);
expect(actual.length).to.equal(5);
});
});
describe("getMostPopularAuthors()", () => {
it("should return an ordered list of most popular authors", () => {
const actual = getMostPopularAuthors(books, authors);
const [first, second] = [
{ name: "Susanne Lawson", count: 11 },
{ name: "Matthews Sanders", count: 5 },
];
expect(actual[0]).to.eql(first);
expect(actual[1]).to.eql(second);
});
it("should limit the list to the top five", () => {
const actual = getMostPopularAuthors(books, authors);
expect(actual.length).to.equal(5);
});
});
});