-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Run unit test with separate data. DO NOT MERGE #36593
Changes from all commits
5ab2834
1a4ebe9
c97031f
6b6b7a8
94ef32d
da89194
2621b9a
877f4ce
68facfb
33da955
d6ec6ae
2ec53d1
4b5f373
aca19a8
36c32d6
d8701f2
17fa7e9
2abc737
17e8f41
dfe7b65
b13f966
325f896
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,149 @@ | ||||||||||||||||||||||
import { tableDateColumnTypes } from "../../../../../fixtures/tableDateColumnTypes"; | ||||||||||||||||||||||
import { | ||||||||||||||||||||||
agHelper, | ||||||||||||||||||||||
entityExplorer, | ||||||||||||||||||||||
propPane, | ||||||||||||||||||||||
table, | ||||||||||||||||||||||
} from "../../../../../support/Objects/ObjectsCore"; | ||||||||||||||||||||||
|
||||||||||||||||||||||
import EditorNavigation, { | ||||||||||||||||||||||
EntityType, | ||||||||||||||||||||||
} from "../../../../../support/Pages/EditorNavigation"; | ||||||||||||||||||||||
|
||||||||||||||||||||||
describe( | ||||||||||||||||||||||
"Table widget date column type validation", | ||||||||||||||||||||||
{ tags: ["@tag.Widget", "@tag.Table"] }, | ||||||||||||||||||||||
() => { | ||||||||||||||||||||||
before(() => { | ||||||||||||||||||||||
entityExplorer.DragNDropWidget("tablewidgetv2", 350, 500); | ||||||||||||||||||||||
EditorNavigation.SelectEntityByName("Table1", EntityType.Widget); | ||||||||||||||||||||||
propPane.ToggleJSMode("Table data", true); | ||||||||||||||||||||||
propPane.UpdatePropertyFieldValue("Table data", tableDateColumnTypes); | ||||||||||||||||||||||
table.EditColumn("unixs", "v2"); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
beforeEach(() => { | ||||||||||||||||||||||
propPane.NavigateBackToPropertyPane(false); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
const setEditableDateFormats = (format: string) => { | ||||||||||||||||||||||
// Update date format property | ||||||||||||||||||||||
propPane.ToggleJSMode("Date format", true); | ||||||||||||||||||||||
propPane.UpdatePropertyFieldValue("Date format", format); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Update display format property | ||||||||||||||||||||||
propPane.ToggleJSMode("Display format", true); | ||||||||||||||||||||||
propPane.UpdatePropertyFieldValue("Display format", "YYYY-MM-DD"); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Toggle editable | ||||||||||||||||||||||
propPane.TogglePropertyState("Editable", "On"); | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
|
||||||||||||||||||||||
const clickAndValidateDateCell = (row: number, column: number) => { | ||||||||||||||||||||||
// Click unix cell edit | ||||||||||||||||||||||
table.ClickOnEditIcon(row, column); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Click on specific date within | ||||||||||||||||||||||
agHelper.GetNClick( | ||||||||||||||||||||||
`${table._dateInputPopover} [aria-label='${table.getFormattedTomorrowDates().verboseFormat}']`, | ||||||||||||||||||||||
); | ||||||||||||||||||||||
Comment on lines
+47
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using attribute selectors; utilize data- attributes and locator variables instead.* Using attribute selectors like Consider modifying your selector to use a data-* attribute or a locator variable. For example: - agHelper.GetNClick(
- `${table._dateInputPopover} [aria-label='${table.getFormattedTomorrowDates().verboseFormat}']`,
- );
+ agHelper.GetNClick(
+ `${table._dateInputPopover} ${table._datePickerCell}`,
+ ); Ensure that
|
||||||||||||||||||||||
|
||||||||||||||||||||||
// Check that date is set in column | ||||||||||||||||||||||
table | ||||||||||||||||||||||
.ReadTableRowColumnData(row, column, "v2") | ||||||||||||||||||||||
.then((val) => | ||||||||||||||||||||||
expect(val).to.equal(table.getFormattedTomorrowDates().isoFormat), | ||||||||||||||||||||||
); | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
|
||||||||||||||||||||||
it("1. should allow inline editing of Unix Timestamp in seconds (unix/s)", () => { | ||||||||||||||||||||||
table.ChangeColumnType("unixs", "Date"); | ||||||||||||||||||||||
setEditableDateFormats("Epoch"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 0); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
it("2. should allow inline editing of Unix Timestamp in milliseconds (unix/ms)", () => { | ||||||||||||||||||||||
table.ChangeColumnType("unixms", "Date"); | ||||||||||||||||||||||
setEditableDateFormats("Milliseconds"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 1); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
it("3. should allow inline editing of date in YYYY-MM-DD format", () => { | ||||||||||||||||||||||
table.EditColumn("yyyymmdd", "v2"); | ||||||||||||||||||||||
setEditableDateFormats("YYYY-MM-DD"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 2); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
it("4. should allow inline editing of date in YYYY-MM-DD HH:mm format", () => { | ||||||||||||||||||||||
table.EditColumn("yyyymmddhhmm", "v2"); | ||||||||||||||||||||||
setEditableDateFormats("YYYY-MM-DD HH:mm"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 3); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
it("5. should allow inline editing of date in ISO 8601 format (YYYY-MM-DDTHH:mm:ss)", () => { | ||||||||||||||||||||||
table.EditColumn("iso8601", "v2"); | ||||||||||||||||||||||
setEditableDateFormats("YYYY-MM-DDTHH:mm:ss"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 4); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
it("6. should allow inline editing of date in YYYY-MM-DD HH:mm format", () => { | ||||||||||||||||||||||
table.EditColumn("yyyymmddTHHmmss", "v2"); | ||||||||||||||||||||||
setEditableDateFormats("YYYY-MM-DD HH:mm"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 5); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
it("7. should allow inline editing of date in 'do MMM yyyy' format", () => { | ||||||||||||||||||||||
table.ChangeColumnType("yyyymmddhhmmss", "Date"); | ||||||||||||||||||||||
setEditableDateFormats("YYYY-MM-DDTHH:mm:ss"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 6); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
Comment on lines
+95
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a mismatch between your test description and the date format used. The test description indicates you're validating the Let's adjust the - setEditableDateFormats("YYYY-MM-DDTHH:mm:ss");
+ setEditableDateFormats("Do MMM YYYY"); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
it("8. should allow inline editing of date in DD/MM/YYYY format", () => { | ||||||||||||||||||||||
table.ChangeColumnType("doMMMyyyy", "Date"); | ||||||||||||||||||||||
setEditableDateFormats("Do MMM YYYY"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 7); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
Comment on lines
+101
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure consistency between your test description and the date format provided. Your test description specifies the 'DD/MM/YYYY' format, but the date format you've set is Please update the date format to match the test description: - setEditableDateFormats("Do MMM YYYY");
+ setEditableDateFormats("DD/MM/YYYY"); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
it("9. should allow inline editing of date in DD/MM/YYYY HH:mm format", () => { | ||||||||||||||||||||||
table.EditColumn("ddmmyyyy", "v2"); | ||||||||||||||||||||||
setEditableDateFormats("DD/MM/YYYY"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 8); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
Comment on lines
+107
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the date format with your test objective for accuracy. The test aims to validate the Modify the date format as follows: - setEditableDateFormats("DD/MM/YYYY");
+ setEditableDateFormats("DD/MM/YYYY HH:mm"); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
it("10. should allow inline editing of date in LLL (Month Day, Year Time) format", () => { | ||||||||||||||||||||||
table.EditColumn("ddmmyyyyhhmm", "v2"); | ||||||||||||||||||||||
setEditableDateFormats("DD/MM/YYYY HH:mm"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 9); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
it("11. should allow inline editing of date in LL (Month Day, Year) format", () => { | ||||||||||||||||||||||
table.EditColumn("lll", "v2"); | ||||||||||||||||||||||
setEditableDateFormats("LLL"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 10); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
it("12. should allow inline editing of date in 'D MMMM, YYYY' format", () => { | ||||||||||||||||||||||
table.EditColumn("ll", "v2"); | ||||||||||||||||||||||
setEditableDateFormats("LL"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 11); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
it("13. should allow inline editing of date in 'h:mm A D MMMM, YYYY' format", () => { | ||||||||||||||||||||||
table.EditColumn("dmmmmyyyy", "v2"); | ||||||||||||||||||||||
setEditableDateFormats("D MMMM, YYYY"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 12); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
it("14. should allow inline editing of date in MM-DD-YYYY format", () => { | ||||||||||||||||||||||
table.EditColumn("hmmAdmmmmyyyy", "v2"); | ||||||||||||||||||||||
setEditableDateFormats("H:mm A D MMMM, YYYY"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 13); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
Comment on lines
+137
to
+141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verify that the date format matches the test case purpose. In this test case, you're supposed to test the Adjust the date format to reflect the intended test: - setEditableDateFormats("H:mm A D MMMM, YYYY");
+ setEditableDateFormats("MM-DD-YYYY"); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
it("15. should allow inline editing of date in DD-MM-YYYY format", () => { | ||||||||||||||||||||||
table.EditColumn("mm1dd1yyyy", "v2"); | ||||||||||||||||||||||
setEditableDateFormats("MM-DD-YYYY"); | ||||||||||||||||||||||
clickAndValidateDateCell(0, 14); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
Comment on lines
+143
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure the date format corresponds with the test's goal. The test description mentions the Update the date format accordingly: - setEditableDateFormats("MM-DD-YYYY");
+ setEditableDateFormats("DD-MM-YYYY"); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
}, | ||||||||||||||||||||||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const tableDateColumnTypes = ` | ||
{{ | ||
[ | ||
{ | ||
"unixs": 1727212200, | ||
"unixms": 1727212200000, | ||
"yyyymmdd": "2024-09-25", | ||
"yyyymmddhhmm": "2024-09-25 14:30", | ||
iso8601: "2024-09-25T14:30:00.000Z", | ||
"yyyymmddTHHmmss": "2024-09-25T14:30:00", | ||
"yyyymmddhhmmss": "2024-09-25 02:30:00", | ||
"doMMMyyyy": "25th Sep 2024", | ||
"ddmmyyyy": "25/09/2024", | ||
"ddmmyyyyhhmm": "25/09/2024 14:30", | ||
lll: "September 25, 2024 2:30 PM", | ||
ll: "September 25, 2024", | ||
"dmmmmyyyy": "25 September, 2024", | ||
"hmmAdmmmmyyyy": "2:30 PM 25 September, 2024", | ||
"mm1dd1yyyy": "09-25-2024", | ||
"dd1mm1yyyy": "25-09-2024", | ||
"ddimmiyy": "25/09/24", | ||
"mmddyy": "09/25/24", | ||
}, | ||
] | ||
}} | ||
`; | ||
Comment on lines
+1
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Let's make our lesson plan more dynamic! While your current approach is like having a well-prepared set of flashcards, we could make this even more flexible and easier to maintain. Instead of hardcoding all these date formats, why don't we create them programmatically? Consider refactoring the code to generate the date representations dynamically. Here's an example of how you might do this: import moment from 'moment';
function generateDateFormats(date: Date) {
return {
unixs: Math.floor(date.getTime() / 1000),
unixms: date.getTime(),
yyyymmdd: moment(date).format('YYYY-MM-DD'),
yyyymmddhhmm: moment(date).format('YYYY-MM-DD HH:mm'),
iso8601: date.toISOString(),
// ... add other formats here
};
}
const sampleDate = new Date('2024-09-25T14:30:00Z');
export const tableDateColumnTypes = JSON.stringify([generateDateFormats(sampleDate)], null, 2); This approach is like creating a reusable lesson plan that we can easily update for different dates. It reduces the chance of errors and makes our code more maintainable. What do you think, class? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { ReactTableColumnProps } from "widgets/TableWidgetV2/component/Constants"; | ||
import { | ||
columns, | ||
columnsNonDate, | ||
expectedData, | ||
expectedDataNonDate, | ||
tableData, | ||
tableDataNonDate, | ||
} from "./fixtures"; | ||
import { transformDataPureFn } from "./transformDataPureFn"; | ||
|
||
describe("transformDataPureFn", () => { | ||
it("should transform table data based on column meta properties", () => { | ||
let result = transformDataPureFn( | ||
[tableData[0]], | ||
columns as ReactTableColumnProps[], | ||
); | ||
|
||
expect(result[0]).toEqual(expectedData[0]); | ||
|
||
result = transformDataPureFn( | ||
[tableData[1]], | ||
columns as ReactTableColumnProps[], | ||
); | ||
expect(result[0]).toEqual(expectedData[1]); | ||
}); | ||
|
||
it("should handle invalid date values", () => { | ||
const invalidTableData = [ | ||
{ | ||
epoch: "invalid_epoch", | ||
milliseconds: "invalid_milliseconds", | ||
iso_8601: "invalid_iso_8601", | ||
yyyy_mm_dd: "invalid_date", | ||
lll: "invalid_date", | ||
}, | ||
]; | ||
|
||
const expectedInvalidData = [ | ||
{ | ||
epoch: "Invalid date", | ||
milliseconds: "Invalid date", | ||
iso_8601: "8601-01-01", | ||
yyyy_mm_dd: "Invalid date", | ||
lll: "Invalid date", | ||
}, | ||
]; | ||
|
||
const result = transformDataPureFn( | ||
invalidTableData, | ||
columns as ReactTableColumnProps[], | ||
); | ||
|
||
expect(result).toEqual(expectedInvalidData); | ||
}); | ||
|
||
it("should return an empty array when tableData is empty", () => { | ||
const result = transformDataPureFn([], columns as ReactTableColumnProps[]); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
|
||
it("should not transform non-date data", () => { | ||
const result = transformDataPureFn( | ||
tableDataNonDate, | ||
columnsNonDate as ReactTableColumnProps[], | ||
); | ||
|
||
expect(result).toEqual(expectedDataNonDate); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Let's enhance reusability by parameterizing the 'Display format'.
By making 'Display format' a parameter in your
setEditableDateFormats
function, you can test various display formats more effectively. This adjustment will make your tests more flexible and your code more maintainable.Here's how you can modify the function:
Then, update your test cases to pass the appropriate
displayFormat
argument.📝 Committable suggestion