11import { test , expect } from "@playwright/test" ;
22import { loginAs , openTimesheetUpload , readE2EState , uploadTimesheet } from "./helpers/agiladmin.js" ;
3+ import { createHash } from "node:crypto" ;
34import fs from "node:fs/promises" ;
45import os from "node:os" ;
56import path from "node:path" ;
67
8+ async function sha256File ( filePath ) {
9+ const data = await fs . readFile ( filePath ) ;
10+ return createHash ( "sha256" ) . update ( data ) . digest ( "hex" ) ;
11+ }
12+
713test ( "admin can login and upload a real timesheet" , async ( { page } ) => {
814 const state = await readE2EState ( ) ;
915 await loginAs ( page , "admin" ) ;
1016 await openTimesheetUpload ( page ) ;
1117 await uploadTimesheet ( page , state . fixtures . admin ) ;
1218
1319 await expect ( page . getByText ( "Uploaded: 2016_timesheet_Luca-Pacioli.xlsx" ) ) . toBeVisible ( ) ;
20+ const uploadedTempPath = await page . locator ( 'input[name="tempfile"]' ) . inputValue ( ) ;
21+ await expect ( uploadedTempPath ) . toBeTruthy ( ) ;
22+ await expect ( sha256File ( uploadedTempPath ) ) . resolves . toBe ( await sha256File ( state . fixtures . admin ) ) ;
1423 await page . getByRole ( "button" , { name : "Contents" } ) . click ( ) ;
1524 await expect ( page . getByText ( "Contents of the new timesheet" ) ) . toBeVisible ( ) ;
1625 await expect ( page . getByText ( "Error parsing timesheet" ) ) . toHaveCount ( 0 ) ;
@@ -23,6 +32,9 @@ test("manager can login and upload their own timesheet", async ({ page }) => {
2332 await uploadTimesheet ( page , state . fixtures . manager ) ;
2433
2534 await expect ( page . getByText ( "Uploaded: 2016_timesheet_Manager.xlsx" ) ) . toBeVisible ( ) ;
35+ const uploadedTempPath = await page . locator ( 'input[name="tempfile"]' ) . inputValue ( ) ;
36+ await expect ( uploadedTempPath ) . toBeTruthy ( ) ;
37+ await expect ( sha256File ( uploadedTempPath ) ) . resolves . toBe ( await sha256File ( state . fixtures . manager ) ) ;
2638 await page . getByRole ( "button" , { name : "Contents" } ) . click ( ) ;
2739 await expect ( page . getByText ( "Contents of the new timesheet" ) ) . toBeVisible ( ) ;
2840 await expect ( page . getByText ( "Error parsing timesheet" ) ) . toHaveCount ( 0 ) ;
0 commit comments