diff --git a/src/__mocks__/store.js b/src/__mocks__/store.js index f0a5d6c6d..2ada7f03b 100644 --- a/src/__mocks__/store.js +++ b/src/__mocks__/store.js @@ -1,21 +1,20 @@ -/* export default { - get: () => { - return Promise.resolve({ - data: [{ - "id": "47qAXb6fIm2zOKkLzMro", - "vat": "80", - "fileUrl": "https://test.storage.tld/v0/b/billable-677b6.a…f-1.jpg?alt=media&token=c1640e12-a24b-4b11-ae52-529112e9602a", - "status": "pending", - "type": "Hôtel et logement", - "commentary": "séminaire billed", - "name": "encore", - "fileName": "preview-facture-free-201801-pdf-1.jpg", - "date": "2004-04-04", - "amount": 400, - "commentAdmin": "ok", - "email": "a@a", - "pct": 20 - }, +const mockedBills = { + list() { + return Promise.resolve([{ + "id": "47qAXb6fIm2zOKkLzMro", + "vat": "80", + "fileUrl": "https://test.storage.tld/v0/b/billable-677b6.a…f-1.jpg?alt=media&token=c1640e12-a24b-4b11-ae52-529112e9602a", + "status": "pending", + "type": "Hôtel et logement", + "commentary": "séminaire billed", + "name": "encore", + "fileName": "preview-facture-free-201801-pdf-1.jpg", + "date": "2004-04-04", + "amount": 400, + "commentAdmin": "ok", + "email": "a@a", + "pct": 20 + }, { "id": "BeKy5Mo4jkmdfPGYpTxZ", "vat": "", @@ -60,27 +59,7 @@ "commentary": "test2", "type": "Restaurants et bars", "fileUrl": "https://test.storage.tld/v0/b/billable-677b6.a…f-1.jpg?alt=media&token=4df6ed2c-12c8-42a2-b013-346c1346f732" - }] - }) - } -} */ -const mockedBills = { - list() { - return Promise.resolve([{ - "id": "47qAXb6fIm2zOKkLzMro", - "vat": "80", - "fileUrl": "https://firebasestorage.googleapis.com/v0/b/billable-677b6.a…f-1.jpg?alt=media&token=c1640e12-a24b-4b11-ae52-529112e9602a", - "status": "pending", - "type": "Hôtel et logement", - "commentary": "séminaire billed", - "name": "encore", - "fileName": "preview-facture-free-201801-pdf-1.jpg", - "date": "2004-04-04", - "amount": 400, - "commentAdmin": "ok", - "email": "a@a", - "pct": 20 - }]) + }]) }, create(bill) { diff --git a/src/__tests__/Dashboard.js b/src/__tests__/Dashboard.js index 31ae81b26..ae971723d 100644 --- a/src/__tests__/Dashboard.js +++ b/src/__tests__/Dashboard.js @@ -227,17 +227,15 @@ describe("Given I am a user connected as Admin", () => { router() window.onNavigate(ROUTES_PATH.Dashboard) await waitFor(() => screen.getByText("Validations")) + const contentPending = await screen.getByText("En attente (1)") + expect(contentPending).toBeTruthy() + const contentRefused = await screen.getByText("Refusé (2)") + expect(contentRefused).toBeTruthy() expect(screen.getByTestId("big-billed-icon")).toBeTruthy() }) - - test("fetches bills from an API and fails with 404 message error", async () => { - jest.spyOn(mockStore, "bills") - mockStore.bills.mockImplementationOnce(() => { - return { - list : () => { - return Promise.reject(new Error("Erreur 404")) - } - }}) + describe("When an error occurs on API", () => { + beforeEach(() => { + jest.spyOn(mockStore, "bills") Object.defineProperty( window, 'localStorage', @@ -250,9 +248,16 @@ describe("Given I am a user connected as Admin", () => { const root = document.createElement("div") root.setAttribute("id", "root") document.body.appendChild(root) - router() + }) + test("fetches bills from an API and fails with 404 message error", async () => { + mockStore.bills.mockImplementationOnce(() => { + return { + list : () => { + return Promise.reject(new Error("Erreur 404")) + } + }}) window.onNavigate(ROUTES_PATH.Dashboard) await new Promise(process.nextTick); const message = await screen.getByText(/Erreur 404/) @@ -260,27 +265,13 @@ describe("Given I am a user connected as Admin", () => { }) test("fetches messages from an API and fails with 500 message error", async () => { - jest.spyOn(mockStore, "bills") + mockStore.bills.mockImplementationOnce(() => { return { list : () => { return Promise.reject(new Error("Erreur 500")) } }}) - Object.defineProperty( - window, - 'localStorage', - { value: localStorageMock } - ) - window.localStorage.setItem('user', JSON.stringify({ - type: 'Admin', - email: "a@a" - })) - const root = document.createElement("div") - root.setAttribute("id", "root") - document.body.appendChild(root) - - router() window.onNavigate(ROUTES_PATH.Dashboard) await new Promise(process.nextTick); @@ -288,5 +279,7 @@ describe("Given I am a user connected as Admin", () => { expect(message).toBeTruthy() }) }) + + }) }) diff --git a/src/__tests__/DashboardFormUI.js b/src/__tests__/DashboardFormUI.js index 8d75804d9..e106a60f9 100644 --- a/src/__tests__/DashboardFormUI.js +++ b/src/__tests__/DashboardFormUI.js @@ -68,7 +68,7 @@ describe('Given I am connected as an Admin and I am on Dashboard Page', () => { expect(screen.getByText(bill.commentAdmin)).toBeTruthy() }) }) - describe('When acceptrefuseded bill is passed to DashboardUI', () => { + describe('When refused bill is passed to DashboardUI', () => { test(('Then, it should show admin commentary'), () => { const html = DashboardFormUI(billrefused) document.body.innerHTML = html diff --git a/src/__tests__/Logout.js b/src/__tests__/Logout.js index ca3d1dc54..653eed604 100644 --- a/src/__tests__/Logout.js +++ b/src/__tests__/Logout.js @@ -24,7 +24,6 @@ const bills = [{ "commentAdmin": "ok", "email": "a@a", "pct": 20, - "email": "john.snow@billed.com" }] describe('Given I am connected', () => { diff --git a/src/containers/Login.js b/src/containers/Login.js index 841369aaf..c3cb058bd 100644 --- a/src/containers/Login.js +++ b/src/containers/Login.js @@ -41,8 +41,8 @@ export default class Login { e.preventDefault() const user = { type: "Admin", - email: e.target.querySelector(`input[data-testid="admin-email-input"]`).value, - password: e.target.querySelector(`input[data-testid="admin-password-input"]`).value, + email: e.target.querySelector(`input[data-testid="employee-email-input"]`).value, + password: e.target.querySelector(`input[data-testid="employee-password-input"]`).value, status: "connected" } this.localStorage.setItem("user", JSON.stringify(user))