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

chore: fix form widgets bugs #38492

Merged
merged 7 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "../../../../../support/Objects/ObjectsCore";

// TODO: Enable when issue(github.com/appsmithorg/appsmith/issues/36419) is solved.
describe(
describe.skip(
`${ANVIL_EDITOR_TEST}: Anvil tests for Button Widget`,
{ tags: ["@tag.Anvil", "@tag.Visual"] },
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "../../../../../support/Objects/ObjectsCore";

// TODO: Enable when issue(github.com/appsmithorg/appsmith/issues/36419) is solved.
describe(
describe.skip(
`${ANVIL_EDITOR_TEST}: Anvil tests for Checkbox Group Widget`,
{ tags: ["@tag.Anvil", "@tag.Visual"] },
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "../../../../../support/Objects/ObjectsCore";

// TODO: Enable when issue(github.com/appsmithorg/appsmith/issues/36419) is solved.
describe(
describe.skip(
`${ANVIL_EDITOR_TEST}: Anvil tests for Checkbox Widget`,
{ tags: ["@tag.Anvil", "@tag.Visual"] },
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "../../../../../support/Objects/ObjectsCore";

// TODO: Enable when issue(github.com/appsmithorg/appsmith/issues/36419) is solved.
describe(
describe.skip(
`${ANVIL_EDITOR_TEST}: Anvil tests for Heading Widget`,
{ tags: ["@tag.Anvil", "@tag.Visual"] },
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "../../../../../support/Objects/ObjectsCore";

// TODO: Enable when issue(github.com/appsmithorg/appsmith/issues/36419) is solved.
describe(
describe.skip(
`${ANVIL_EDITOR_TEST}: Anvil tests for Icon Button Widget`,
{ tags: ["@tag.Anvil", "@tag.Visual"] },
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "../../../../../support/Objects/ObjectsCore";

// TODO: Enable when issue(github.com/appsmithorg/appsmith/issues/36419) is solved.
describe(
describe.skip(
`${ANVIL_EDITOR_TEST}: Anvil tests for Inline Button Widget`,
{ tags: ["@tag.Anvil", "@tag.Visual"] },
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "../../../../../support/Objects/ObjectsCore";

// TODO: Enable when issue(github.com/appsmithorg/appsmith/issues/36419) is solved.
describe(
describe.skip(
`${ANVIL_EDITOR_TEST}: Anvil tests for Paragraph Widget`,
{ tags: ["@tag.Anvil", "@tag.Visual"] },
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "../../../../../support/Objects/ObjectsCore";

// TODO: Enable when issue(github.com/appsmithorg/appsmith/issues/36419) is solved.
describe(
describe.skip(
`${ANVIL_EDITOR_TEST}: Anvil tests for Radio Group Widget`,
{ tags: ["@tag.Anvil", "@tag.Visual"] },
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "../../../../../support/Objects/ObjectsCore";

// TODO: Enable when issue(github.com/appsmithorg/appsmith/issues/36419) is solved.
describe(
describe.skip(
`${ANVIL_EDITOR_TEST}: Anvil tests for Stats Widget`,
{ tags: ["@tag.Anvil", "@tag.Visual"] },
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "../../../../../support/Objects/ObjectsCore";

// TODO: Enable when issue(github.com/appsmithorg/appsmith/issues/36419) is solved.
describe(
describe.skip(
`${ANVIL_EDITOR_TEST}: Anvil tests for Switch Group Widget`,
{ tags: ["@tag.Anvil", "@tag.Visual"] },
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "../../../../../support/Objects/ObjectsCore";

// TODO: Enable when issue(github.com/appsmithorg/appsmith/issues/36419) is solved.
describe(
describe.skip(
`${ANVIL_EDITOR_TEST}: Anvil tests for Switch Widget`,
{ tags: ["@tag.Anvil", "@tag.Visual"] },
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "../../../../../support/Objects/ObjectsCore";

// TODO: Enable when issue(github.com/appsmithorg/appsmith/issues/36419) is solved.
describe(
describe.skip(
`${ANVIL_EDITOR_TEST}: Anvil tests for Toolbar Button Widget`,
{ tags: ["@tag.Anvil", "@tag.Visual"] },
() => {
Expand Down
3 changes: 2 additions & 1 deletion app/client/cypress/limited-tests.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# To run only limited tests - give the spec names in below format:
cypress/e2e/Regression/ClientSide/VisualTests/JSEditorIndent_spec.js
#cypress/e2e/Regression/ClientSide/VisualTests/JSEditorIndent_spec.js
# For running all specs - uncomment below:
#cypress/e2e/**/**/*
cypress/e2e/Regression/ClientSide/Anvil/Widgets/*

#ci-test-limit uses this file to run minimum of specs. Do not run entire suite with this command.
4 changes: 2 additions & 2 deletions app/client/cypress/support/Pages/Anvil/AnvilSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ export class AnvilSnapshot {

public triggerInputInvalidState = () => {
this.enterPreviewMode();
cy.get("input[aria-required=true]").first().type("123");
cy.get("input[aria-required=true]").first().clear();
cy.get("input[required]").first().type("123");
cy.get("input[required]").first().clear();
Comment on lines +176 to +177
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve selector specificity and accessibility

Two concerns with the current implementation:

  1. Using input[required] instead of input[aria-required=true] might affect accessibility
  2. Using .first() without specific identification could make tests fragile

Consider this improvement:

-    cy.get("input[required]").first().type("123");
-    cy.get("input[required]").first().clear();
+    cy.get("[data-testid='required-input']").type("123");
+    cy.get("[data-testid='required-input']").clear();

Also, ensure the input has both required and aria-required="true" attributes for better accessibility.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cy.get("input[required]").first().type("123");
cy.get("input[required]").first().clear();
cy.get("[data-testid='required-input']").type("123");
cy.get("[data-testid='required-input']").clear();

this.exitPreviewMode();
this.agHelper.GetNClick(this.locators.propertyPaneSidebar);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import { Text, type TextProps } from "@appsmith/wds";
import React, { forwardRef, type ForwardedRef } from "react";
import { HeadingContext, useContextProps } from "react-aria-components";
import { type TextProps } from "@appsmith/wds";
import {
CalendarStateContext,
HeadingContext,
useContextProps,
} from "react-aria-components";
import React, { forwardRef, useContext, type ForwardedRef } from "react";

import styles from "./styles.module.css";
import { CalendarMonthDropdown } from "./CalendarMonthDropdown";
import { CalendarYearDropdown } from "./CalendarYearDropdown";

function CalendarHeading(
props: TextProps,
ref: ForwardedRef<HTMLHeadingElement>,
) {
[props, ref] = useContextProps(props, ref, HeadingContext);
const { children, ...domProps } = props;
const state = useContext(CalendarStateContext);

return (
<Text {...domProps} color="neutral" ref={ref}>
{children}
</Text>
<div className={styles.monthYearDropdown}>
<CalendarMonthDropdown state={state} />
<CalendarYearDropdown state={state} />
</div>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";
import type { Key } from "react";
import { useDateFormatter } from "@react-aria/i18n";
import { ListBoxItem, Select } from "@appsmith/wds";
import type { CalendarState } from "@react-stately/calendar";

import styles from "./styles.module.css";
import { useValidMonths } from "../utils/calendar";

export function CalendarMonthDropdown({ state }: { state: CalendarState }) {
const formatter = useDateFormatter({
month: "long",
timeZone: state.timeZone,
});

const months = useValidMonths(state, formatter);

const onChange = (value: Key | null) => {
const date = state.focusedDate.set({ month: Number(value) });

state.setFocusedDate(date);
};

return (
<Select
aria-label="Month"
className={styles.monthDropdown}
defaultSelectedKey={state.focusedDate.month}
onSelectionChange={onChange}
placeholder="Select Month"
size="small"
>
{months.map((month, i) => (
<ListBoxItem id={i} key={i} textValue={month}>
{month}
</ListBoxItem>
))}
</Select>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from "react";
import type { Key } from "react";
import { ListBoxItem, Select } from "@appsmith/wds";
import type { CalendarState } from "@react-stately/calendar";

import { useYearOptions } from "../utils/calendar";

export function CalendarYearDropdown({ state }: { state: CalendarState }) {
const years = useYearOptions(state);

const onChange = (value: Key | null) => {
const index = Number(value);
const date = years[index].value;

state.setFocusedDate(date);
};

return (
<Select
aria-label="Year"
onSelectionChange={onChange}
placeholder="Select Year"
selectedKey={20}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace hardcoded selectedKey with dynamic value

The selectedKey should be calculated based on the current year's position in the years array.

-      selectedKey={20}
+      selectedKey={years.findIndex(
+        (year) => year.value.compare(state.focusedDate) === 0
+      )}

Committable suggestion skipped: line range outside the PR's diff.

size="small"
>
{years.map((year, i) => (
<ListBoxItem id={i} key={i} textValue={year.formatted}>
{year.formatted}
</ListBoxItem>
))}
</Select>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@
0 0 0 calc(var(--box-shadow-offset) + var(--border-width-2))
var(--color-bd-focus);
}

.monthYearDropdown {
display: flex;
gap: var(--inner-spacing-1);
}

.monthDropdown button {
width: 14ch;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useDateFormatter } from "@react-aria/i18n";
import type { CalendarState } from "@react-stately/calendar";

export function useYearOptions(state: CalendarState) {
const formatter = useDateFormatter({
year: "numeric",
timeZone: state.timeZone,
});

const years: { value: CalendarState["focusedDate"]; formatted: string }[] =
[];

const YEAR_RANGE = 20;

for (let i = -YEAR_RANGE; i <= YEAR_RANGE; i++) {
const date = state.focusedDate.add({ years: i });

years.push({
value: date,
formatted: formatter.format(date.toDate(state.timeZone)),
});
}

return years;
}

export function useValidMonths(
state: CalendarState,
formatter: Intl.DateTimeFormat,
) {
const months = [];
const numMonths = state.focusedDate.calendar.getMonthsInYear(
state.focusedDate,
);

for (let i = 1; i <= numMonths; i++) {
const date = state.focusedDate.set({ month: i });

// Skip months outside valid range
if (state.minValue && date.compare(state.minValue) < 0) {
continue;
}

if (state.maxValue && date.compare(state.maxValue) > 0) {
continue;
}

months.push(formatter.format(date.toDate(state.timeZone)));
}

return months;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export const DatePicker = <T extends DateValue>(props: DatePickerProps<T>) => {
isLoading={isLoading}
size={size}
/>
<FieldError>{errorMessage}</FieldError>
<Popover
UNSTABLE_portalContainer={root}
className={clsx(datePickerStyles.popover, popoverClassName)}
Expand All @@ -103,6 +102,7 @@ export const DatePicker = <T extends DateValue>(props: DatePickerProps<T>) => {
)}
</Dialog>
</Popover>
<FieldError>{errorMessage}</FieldError>
</>
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ export function FieldLabel(props: LabelProps) {
className={clsx(styles.label)}
elementType="label"
>
<Text fontWeight={600} size="caption">
<Text
fontWeight={600}
lineClamp={1}
size="caption"
title={children?.toString()}
>
{children}
</Text>
{Boolean(isRequired) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mergeRefs } from "@react-aria/utils";
import React, { forwardRef, useRef, useState } from "react";
import { getTypographyClassName } from "@appsmith/wds-theming";
import { IconButton, Spinner, type IconProps } from "@appsmith/wds";
import { Group, Input as HeadlessInput } from "react-aria-components";
import { Input as HeadlessInput } from "react-aria-components";

import styles from "./styles.module.css";
import type { InputProps } from "./types";
Expand Down Expand Up @@ -49,7 +49,7 @@ function _Input(props: InputProps, ref: React.Ref<HTMLInputElement>) {
})();

return (
<Group className={styles.inputGroup}>
<div className={styles.inputGroup}>
{Boolean(prefix) && (
<span data-input-prefix onClick={() => localRef.current?.focus()}>
{prefix}
Expand All @@ -74,7 +74,7 @@ function _Input(props: InputProps, ref: React.Ref<HTMLInputElement>) {
{suffix}
</span>
)}
</Group>
</div>
);
}

Expand Down
Loading
Loading