-
Notifications
You must be signed in to change notification settings - Fork 484
/
Bills.js
39 lines (34 loc) · 1.43 KB
/
Bills.js
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
/**
* @jest-environment jsdom
*/
import {screen, waitFor} from "@testing-library/dom"
import BillsUI from "../views/BillsUI.js"
import { bills } from "../fixtures/bills.js"
import { ROUTES_PATH} from "../constants/routes.js";
import {localStorageMock} from "../__mocks__/localStorage.js";
import router from "../app/Router.js";
describe("Given I am connected as an employee", () => {
describe("When I am on Bills Page", () => {
test("Then bill icon in vertical layout should be highlighted", async () => {
Object.defineProperty(window, 'localStorage', { value: localStorageMock })
window.localStorage.setItem('user', JSON.stringify({
type: 'Employee'
}))
const root = document.createElement("div")
root.setAttribute("id", "root")
document.body.append(root)
router()
window.onNavigate(ROUTES_PATH.Bills)
await waitFor(() => screen.getByTestId('icon-window'))
const windowIcon = screen.getByTestId('icon-window')
//to-do write expect expression
})
test("Then bills should be ordered from earliest to latest", () => {
document.body.innerHTML = BillsUI({ data: bills })
const dates = screen.getAllByText(/^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$/i).map(a => a.innerHTML)
const antiChrono = (a, b) => ((a < b) ? 1 : -1)
const datesSorted = [...dates].sort(antiChrono)
expect(dates).toEqual(datesSorted)
})
})
})