Skip to content

Commit

Permalink
feat(frontend): add block tests (#8804)
Browse files Browse the repository at this point in the history
<!-- Clearly explain the need for these changes: -->
We want to be able to automatically test agent running creation and
building via the build page

### Changes 🏗️
- updates many UI elements to have new data ids 
- adds page for build
- adds spec for build
<!-- Concisely describe all of the changes made in this pull request:
-->

### Checklist 📋

#### For code changes:
- [x] I have clearly listed my changes in the PR description
- [x] I have made a test plan
- [x] I have tested my changes according to the test plan:
  - [x] Run the UI Tests!

---------

Co-authored-by: Bently <tomnoon9@gmail.com>
  • Loading branch information
ntindle and Bentlybro authored Dec 3, 2024
1 parent 43bd5c8 commit 89011aa
Show file tree
Hide file tree
Showing 11 changed files with 563 additions and 5 deletions.
11 changes: 11 additions & 0 deletions autogpt_platform/frontend/src/components/CustomNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,17 @@ export function CustomNode({
className={`${blockClasses} ${errorClass} ${statusClass}`}
data-id={`custom-node-${id}`}
z-index={1}
data-blockid={data.block_id}
data-blockname={data.title}
data-blocktype={data.blockType}
data-nodetype={data.uiType}
data-category={data.categories[0]?.category.toLowerCase() || ""}
data-inputs={JSON.stringify(
Object.keys(data.inputSchema?.properties || {}),
)}
data-outputs={JSON.stringify(
Object.keys(data.outputSchema?.properties || {}),
)}
>
{/* Header */}
<div
Expand Down
2 changes: 2 additions & 0 deletions autogpt_platform/frontend/src/components/NodeHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const NodeHandle: FC<HandleProps> = ({
<div key={keyName} className="handle-container">
<Handle
type="target"
data-testid={`input-handle-${keyName}`}
position={Position.Left}
id={keyName}
className="-ml-[26px]"
Expand All @@ -76,6 +77,7 @@ const NodeHandle: FC<HandleProps> = ({
<div key={keyName} className="handle-container justify-end">
<Handle
type="source"
data-testid={`output-handle-${keyName}`}
position={Position.Right}
id={keyName}
className="group -mr-[26px]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export const BlocksControl: React.FC<BlocksControlProps> = ({
variant="ghost"
size="icon"
data-id="blocks-control-popover-trigger"
data-testid="blocks-control-blocks-button"
name="Blocks"
>
<IconToyBrick />
</Button>
Expand All @@ -143,6 +145,7 @@ export const BlocksControl: React.FC<BlocksControlProps> = ({
htmlFor="search-blocks"
className="whitespace-nowrap text-base font-bold text-black 2xl:text-xl"
data-id="blocks-control-label"
data-testid="blocks-control-blocks-label"
>
Blocks
</Label>
Expand Down Expand Up @@ -205,6 +208,7 @@ export const BlocksControl: React.FC<BlocksControlProps> = ({
<span
className="block truncate pb-1 text-sm font-semibold"
data-id={`block-name-${block.id}`}
data-testid={`block-name-${block.id}`}
>
<TextRenderer
value={beautifyString(block.name).replace(
Expand All @@ -214,7 +218,10 @@ export const BlocksControl: React.FC<BlocksControlProps> = ({
truncateLengthLimit={45}
/>
</span>
<span className="block break-all text-xs font-normal text-gray-500">
<span
className="block break-all text-xs font-normal text-gray-500"
data-testid={`block-description-${block.id}`}
>
<TextRenderer
value={block.description}
truncateLengthLimit={165}
Expand All @@ -224,6 +231,7 @@ export const BlocksControl: React.FC<BlocksControlProps> = ({
<div
className="flex flex-shrink-0 items-center gap-1"
data-id={`block-tooltip-${block.id}`}
data-testid={`block-add`}
>
<PlusIcon className="h-6 w-6 rounded-lg bg-gray-200 stroke-black stroke-[0.5px] p-1" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const ControlPanel = ({
size="icon"
onClick={() => control.onClick()}
data-id={`control-button-${index}`}
data-testid={`blocks-control-${control.label.toLowerCase()}-button`}
disabled={control.disabled || false}
>
{control.icon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export const SaveControl = ({
variant="ghost"
size="icon"
data-id="save-control-popover-trigger"
data-testid="blocks-control-save-button"
name="Save"
>
<IconSave />
</Button>
Expand All @@ -115,6 +117,7 @@ export const SaveControl = ({
value={agentName}
onChange={(e) => onNameChange(e.target.value)}
data-id="save-control-name-input"
data-testid="save-control-name-input"
maxLength={100}
/>
<Label htmlFor="description">Description</Label>
Expand All @@ -125,6 +128,7 @@ export const SaveControl = ({
value={agentDescription}
onChange={(e) => onDescriptionChange(e.target.value)}
data-id="save-control-description-input"
data-testid="save-control-description-input"
maxLength={500}
/>
{agentMeta?.version && (
Expand All @@ -136,6 +140,7 @@ export const SaveControl = ({
className="col-span-3"
value={agentMeta?.version || "-"}
disabled
data-testid="save-control-version-output"
/>
</>
)}
Expand All @@ -146,6 +151,7 @@ export const SaveControl = ({
className="w-full"
onClick={handleSave}
data-id="save-control-save-agent"
data-testid="save-control-save-agent-button"
>
Save {getType()}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function NavBarButtons({ className }: { className?: string }) {
<Link
key={button.href}
href={button.href}
data-testid={`${button.text.toLowerCase()}-nav-link`}
className={cn(
className,
"flex items-center gap-2 rounded-xl p-3",
Expand All @@ -49,6 +50,7 @@ export function NavBarButtons({ className }: { className?: string }) {
{isCloud ? (
<Link
href="/marketplace"
data-testid="marketplace-nav-link"
className={cn(
className,
"flex items-center gap-2 rounded-xl p-3",
Expand All @@ -61,6 +63,7 @@ export function NavBarButtons({ className }: { className?: string }) {
</Link>
) : (
<MarketPopup
data-testid="marketplace-nav-link"
className={cn(
className,
"flex items-center gap-2 rounded-xl p-3 text-muted-foreground hover:text-foreground",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export function InputBlock({
</SelectTrigger>
<SelectContent>
{placeholder_values.map((placeholder, index) => (
<SelectItem key={index} value={placeholder.toString()}>
<SelectItem
key={index}
value={placeholder.toString()}
data-testid={`run-dialog-input-${name}-${placeholder.toString()}`}
>
{placeholder.toString()}
</SelectItem>
))}
Expand All @@ -49,6 +53,7 @@ export function InputBlock({
) : (
<Input
id={`${id}-Value`}
data-testid={`run-dialog-input-${name}`}
value={value}
onChange={(e) => onInputChange(id, "value", e.target.value)}
placeholder={placeholder_values?.[0]?.toString() || "Enter value"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function RunnerInputUI({
</div>
<DialogFooter className="px-6 py-4">
<Button
data-testid="run-dialog-run-button"
onClick={scheduledInput ? handleSchedule : handleRun}
className="px-8 py-2 text-lg"
disabled={scheduledInput ? isScheduling : isRunning}
Expand Down
Loading

0 comments on commit 89011aa

Please sign in to comment.