|
|
@ -4,6 +4,7 @@ import { GridPage } from '../../Grid'; |
|
|
|
import { ToolbarPage } from './index'; |
|
|
|
import { ToolbarPage } from './index'; |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
import fs from 'fs'; |
|
|
|
import fs from 'fs'; |
|
|
|
|
|
|
|
import XLSX from 'xlsx'; |
|
|
|
|
|
|
|
|
|
|
|
export class ToolbarViewMenuPage extends BasePage { |
|
|
|
export class ToolbarViewMenuPage extends BasePage { |
|
|
|
readonly toolbar: ToolbarPage; |
|
|
|
readonly toolbar: ToolbarPage; |
|
|
@ -38,14 +39,42 @@ export class ToolbarViewMenuPage extends BasePage { |
|
|
|
]); |
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
// Save downloaded file somewhere
|
|
|
|
// Save downloaded file somewhere
|
|
|
|
await download.saveAs('./output/at.txt'); |
|
|
|
await download.saveAs('./output/test.txt'); |
|
|
|
|
|
|
|
|
|
|
|
// verify downloaded content against expected content
|
|
|
|
// verify downloaded content against expected content
|
|
|
|
const expectedData = fs.readFileSync(expectedDataFile, 'utf8'); |
|
|
|
const expectedData = fs.readFileSync(expectedDataFile, 'utf8').replace(/\r/g, '').split('\n'); |
|
|
|
const file = fs.readFileSync('./output/at.txt', 'utf8'); |
|
|
|
const file = fs.readFileSync('./output/test.txt', 'utf8').replace(/\r/g, '').split('\n'); |
|
|
|
await expect(file).toEqual(expectedData); |
|
|
|
await expect(file).toEqual(expectedData); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async verifyDownloadAsXLSX({ |
|
|
|
|
|
|
|
downloadLocator, |
|
|
|
|
|
|
|
expectedDataFile, |
|
|
|
|
|
|
|
}: { |
|
|
|
|
|
|
|
downloadLocator: Locator; |
|
|
|
|
|
|
|
expectedDataFile: string; |
|
|
|
|
|
|
|
}) { |
|
|
|
|
|
|
|
const [download] = await Promise.all([ |
|
|
|
|
|
|
|
// Start waiting for the download
|
|
|
|
|
|
|
|
this.rootPage.waitForEvent('download'), |
|
|
|
|
|
|
|
// Perform the action that initiates download
|
|
|
|
|
|
|
|
downloadLocator.click(), |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save downloaded file somewhere
|
|
|
|
|
|
|
|
await download.saveAs('./output/test.xlsx'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// convert xlsx to csv
|
|
|
|
|
|
|
|
const wb = XLSX.readFile('./output/test.xlsx'); |
|
|
|
|
|
|
|
XLSX.writeFile(wb, './output/test.txt', { bookType: 'csv' }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// verify downloaded content against expected content
|
|
|
|
|
|
|
|
const expectedData = fs.readFileSync(expectedDataFile, 'utf8'); |
|
|
|
|
|
|
|
const file = fs.readFileSync('./output/test.txt', 'utf8'); |
|
|
|
|
|
|
|
// XLSX writes file with UTF-8 BOM, adds '\ufeff' to cater it
|
|
|
|
|
|
|
|
await expect(file).toEqual('\ufeff' + expectedData); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// menu items
|
|
|
|
// menu items
|
|
|
|
// Collaborative View
|
|
|
|
// Collaborative View
|
|
|
|
// Download
|
|
|
|
// Download
|
|
|
@ -68,6 +97,13 @@ export class ToolbarViewMenuPage extends BasePage { |
|
|
|
.last(), |
|
|
|
.last(), |
|
|
|
expectedDataFile: verificationInfo?.verificationFile ?? './fixtures/expectedBaseDownloadData.txt', |
|
|
|
expectedDataFile: verificationInfo?.verificationFile ?? './fixtures/expectedBaseDownloadData.txt', |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} else if (subMenu === 'Download as XLSX') { |
|
|
|
|
|
|
|
await this.verifyDownloadAsXLSX({ |
|
|
|
|
|
|
|
downloadLocator: await this.rootPage |
|
|
|
|
|
|
|
.locator(`.ant-dropdown-menu-title-content:has-text("${subMenu}")`) |
|
|
|
|
|
|
|
.last(), |
|
|
|
|
|
|
|
expectedDataFile: verificationInfo?.verificationFile ?? './fixtures/expectedBaseDownloadData.txt', |
|
|
|
|
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
await this.rootPage.locator(`.ant-dropdown-menu-title-content:has-text("${subMenu}")`).last().click(); |
|
|
|
await this.rootPage.locator(`.ant-dropdown-menu-title-content:has-text("${subMenu}")`).last().click(); |
|
|
|
} |
|
|
|
} |
|
|
@ -78,6 +114,11 @@ export class ToolbarViewMenuPage extends BasePage { |
|
|
|
message: 'Successfully exported all table data', |
|
|
|
message: 'Successfully exported all table data', |
|
|
|
}); |
|
|
|
}); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case 'Download as XLSX': |
|
|
|
|
|
|
|
await this.verifyToast({ |
|
|
|
|
|
|
|
message: 'Successfully exported all table data', |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
break; |
|
|
|
case 'Locked View': |
|
|
|
case 'Locked View': |
|
|
|
await this.verifyToast({ |
|
|
|
await this.verifyToast({ |
|
|
|
message: 'Successfully Switched to locked view', |
|
|
|
message: 'Successfully Switched to locked view', |
|
|
|