Skip to content
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

RUN-2321-added unit test for date time picker #9100

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jayas006
Copy link
Contributor

@jayas006 jayas006 commented May 3, 2024

Is this a bugfix, or an enhancement? Please describe.
This is an enhancement

Describe the solution you've implemented

Describe alternatives you've considered

Additional context

@jayas006 jayas006 changed the title added unit test for date time picker RUN-2321-added unit test for date time picker May 13, 2024
@jayas006 jayas006 marked this pull request as ready for review May 15, 2024 00:28
Copy link
Contributor

@smartinellibenedetti smartinellibenedetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some pointers, but recommend revisiting these tests, as a few of them seem to be redundant.

Comment on lines 118 to 122
it("renders correctly when mounted", async () => {
const wrapper = await mountDateTimePicker();
expect(wrapper.vm.dateString).toBe(moment().format("YYYY-MM-DD"));
expect(wrapper.vm.time).toBeInstanceOf(Date);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend to remove this test

Comment on lines 28 to 32
it("sets initial data correctly", async () => {
const wrapper = await mountDateTimePicker();
expect(wrapper.vm.dateString).toBe(now.format("YYYY-MM-DD"));
expect(wrapper.vm.time).toBeInstanceOf(Date);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend to remove this test

await wrapper.setData({ dateString: newDateString });
expect(moment(wrapper.vm.time).format("YYYY-MM-DD")).toBe(newDateString);
});
it("binds v-model and class correctly to date-picker and time-picker", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the test checks that the v-model and classes are correctly applied to the data-picker and time-picker, this test should be checking those components have the classes and the v-model, not the wrapper.

Comment on lines 66 to 89
it("applies CSS classes and props correctly", async () => {
const wrapper = await mountDateTimePicker();
expect(wrapper.find(".date-class").exists()).toBe(true);
expect(wrapper.find(".time-class").exists()).toBe(true);
expect(wrapper.find(".bs-date-picker").exists()).toBe(true);
});
it("sets correct attributes on date-picker", async () => {
const wrapper = await mountDateTimePicker();
const datePicker = wrapper.findComponent({ name: "date-picker" });
expect(datePicker.attributes("modelvalue")).toBe(wrapper.vm.dateString);
expect(datePicker.attributes("class")).toContain(wrapper.vm.dateClass);
expect(datePicker.attributes("clear-btn")).toBe("false");
});
it("sets correct attributes on time-picker", async () => {
const wrapper = await mountDateTimePicker();
const timePicker = wrapper.findComponent({ name: "time-picker" });
// Convert both values to ISO string format before comparing them
const receivedTime = new Date(
timePicker.attributes("modelvalue")
).toISOString();
const expectedTime = new Date(wrapper.vm.time).toISOString();
expect(receivedTime).toBe(expectedTime);
expect(timePicker.attributes("class")).toContain(wrapper.vm.timeClass);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend to combine the test binds v-model and class correctly to date-picker and time-picker and all the tests from lines 66 to 89 into one single test, avoiding scenarios like checking if the components exist (as mentioned before, if the components don't have a v-if condition attached to it, there's no need to check its existence).

const wrapper = await mountDateTimePicker();
const newTime = new Date();
const newTimeFormatted = moment(newTime).format();
await wrapper.setData({ time: newTime });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend replacing the wrapper.setData with an emit from timePicker (update:modelValue), ie:

timePicker.vm.$emit(update:modelValue, newTime)

Comment on lines +40 to +42
if (emitted) {
expect(emitted[0]).toEqual([newTimeFormatted]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the if, but keep the line 41.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants