CEC-5150: search on fleets in bulk action (#454)
* CEC-5150: search on fleets in bulk action * add deps * add deps * sonar * sonar * break out fetch
This commit is contained in:
13
src/utils/truncateCSV.js
Normal file
13
src/utils/truncateCSV.js
Normal file
@@ -0,0 +1,13 @@
|
||||
export default function truncateCSV(strings = [], max = Infinity) {
|
||||
const count = strings.length;
|
||||
|
||||
if (max === 0) {
|
||||
return `${count}`;
|
||||
}
|
||||
|
||||
if (count <= max) {
|
||||
return strings.join(", ");
|
||||
}
|
||||
|
||||
return `${strings.slice(0, max).join(", ")}, +${count - max} more`;
|
||||
}
|
||||
18
src/utils/truncateCSV.test.js
Normal file
18
src/utils/truncateCSV.test.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import truncateCSV from "./truncateCSV";
|
||||
|
||||
const tests = [
|
||||
[["ocean", "pear", "ronin", "alaska"], 4, "ocean, pear, ronin, alaska"],
|
||||
[["ocean", "pear", "ronin", "alaska"], 3, "ocean, pear, ronin, +1 more"],
|
||||
[["ocean", "pear", "ronin", "alaska"], 2, "ocean, pear, +2 more"],
|
||||
[["ocean", "pear", "ronin", "alaska"], 0, "4"],
|
||||
[["ocean", "pear", "ronin", "alaska"], 6, "ocean, pear, ronin, alaska"],
|
||||
[["ocean", "pear", "ronin", "alaska"], Infinity, "ocean, pear, ronin, alaska"],
|
||||
];
|
||||
|
||||
describe("truncateCSV", () => {
|
||||
it("properly concatenates", () => {
|
||||
tests.forEach(([strings, max, expected]) => {
|
||||
expect(truncateCSV(strings, max)).toBe(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user