-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: [M3-8393] - Cypress test for Account Maintenance CSV downloads (#…
…11168) * Updated test confirm maintenance details in the tables - to validate entry in downloaded csv files * Added changeset: Cypress test for Account Maintenance CSV downloads * Removed console.log * Removed library - papaparse to parse csv;Implemented script to parse the csv file * Removed it.only from test * Using specific locator for Download CSV and added code to delete downloaded file after assertion * Refeactoring as per review comment for delete files * Added assertion in readFile to ensure file content is not empty
- Loading branch information
1 parent
c81667d
commit c59c943
Showing
3 changed files
with
170 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Tests | ||
--- | ||
|
||
Cypress test for Account Maintenance CSV downloads ([#11168](https://github.com/linode/manager/pull/11168)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @file Utilities for handling csv files. | ||
*/ | ||
|
||
/** | ||
* Parses a CSV string and returns an array of objects representing the data. | ||
* | ||
* @param {string} csvContent - The CSV content as a string. | ||
* @returns {any[]} - An array of objects where each object represents a row in the CSV. | ||
* The keys of the objects are the headers from the CSV. | ||
*/ | ||
|
||
export function parseCsv(csvContent: string): any[] { | ||
// Split the CSV content into lines and filter out any empty lines | ||
const lines = csvContent.split('\n').filter((line) => line.trim() !== ''); | ||
|
||
// Extract the headers from the first line and remove any quotes | ||
const headers = lines[0] | ||
.split(',') | ||
.map((header) => header.trim().replace(/^"|"$/g, '')); | ||
|
||
// Map the remaining lines to objects using the headers | ||
const data = lines.slice(1).map((line) => { | ||
// Split each line into values, handling quoted values with commas and embedded quotes | ||
// The regular expression matches: | ||
// - Values enclosed in double quotes, which may contain commas and escaped double quotes (e.g., "value, with, commas" or "value with ""embedded"" quotes") | ||
// - Values not enclosed in double quotes, which are separated by commas | ||
// The map function then: | ||
// - Trims any leading or trailing whitespace from each value | ||
// - Removes the enclosing double quotes from quoted values | ||
// - Replaces any escaped double quotes within quoted values with a single double quote | ||
const values = line | ||
.match(/("([^"]|"")*"|[^",\s]+)(?=\s*,|\s*$)/g) | ||
?.map((value) => value.trim().replace(/^"|"$/g, '').replace(/""/g, '"')); | ||
|
||
// Create an object to represent the row | ||
const entry: any = {}; | ||
headers.forEach((header, index) => { | ||
entry[header] = values ? values[index] : ''; | ||
}); | ||
|
||
// Return the object representing the row | ||
return entry; | ||
}); | ||
|
||
// Return the array of objects representing the CSV data | ||
return data; | ||
} |