Skip to content

Commit

Permalink
test(frontend): fixed evaluator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashrafchowdury committed Sep 9, 2024
1 parent 74c32ea commit b8480d3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
39 changes: 24 additions & 15 deletions agenta-web/cypress/e2e/eval.evaluators.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {randString} from "../../src/lib/helpers/utils"

describe("Evaluators CRUD Operations Test", function () {
let newEvalName = randString(5)
let editedEvalName = randString(5)
let app_id
before(() => {
cy.createVariant()
Expand All @@ -12,30 +13,38 @@ describe("Evaluators CRUD Operations Test", function () {

context("Executing Evaluators CRUD operations", () => {
beforeEach(() => {
cy.visit(`/apps/${app_id}/evaluations/new-evaluator`)
cy.location("pathname").should("include", "/evaluations/new-evaluator")
cy.visit(`/apps/${app_id}/evaluations?configureEvaluatorModal=open`)
cy.url().should("include", "/evaluations?configureEvaluatorModal=open")
})

it("Should successfully create an Evaluator", () => {
cy.get('[data-cy="evaluator-card"]').should("exist")
cy.get(".ant-space > :nth-child(2) > .ant-btn").click()
cy.get('[data-cy="new-evaluator-modal"]').should("exist")
cy.get('[data-cy^="select-new-evaluator"]').eq(0).click()
cy.get('[data-cy="configure-new-evaluator-modal"]').should("exist")
it("Should successfully create an evaluator", () => {
cy.get(".ant-modal-content").should("exist")
cy.get('[data-cy="create-new-evaluator-button"]').click()
cy.get('[data-cy="new-evaluator-list"]').eq(0).click()
cy.contains(/configure new evaluator/i)
cy.get('[data-cy="configure-new-evaluator-modal-input"]').type(newEvalName)
cy.get('[data-cy="configure-new-evaluator-modal-save-btn"]').click()
cy.get('[data-cy="evaluator-card"]').should("have.length", 2)
cy.get('[data-cy="evaluator-list"]').should("have.length.gt", 2)
})

it("Should click on the edit button and successfully edit an evaluator", () => {
cy.get('[data-cy^="evaluator-card-edit-button"]').eq(0).click()
cy.get('[data-cy="configure-new-evaluator-modal-input"]').type("edit")
it("Should successfully edit an evaluator", () => {
cy.get(".ant-modal-content").should("exist")
cy.get('[data-cy="evaluator-menu-button"]').eq(0).trigger("mouseover")
cy.get(".ant-dropdown-menu").should("be.visible")
cy.get(".ant-dropdown-menu-item").eq(0).click()
cy.get('[data-cy="configure-new-evaluator-modal-input"]').clear()
cy.get('[data-cy="configure-new-evaluator-modal-input"]').type(editedEvalName)
cy.get('[data-cy="configure-new-evaluator-modal-save-btn"]').click()
})

it("Should click on the delete button and successfully delete an evaluator", () => {
cy.get('[data-cy^="evaluator-card-delete-button"]').eq(0).click()
cy.get(".ant-modal-confirm-btns > :nth-child(2) > span").click()
it("Should successfully delete an evaluator", () => {
cy.get(".ant-modal-content").should("exist")
cy.get('[data-cy="evaluator-menu-button"]').eq(0).trigger("mouseover")
cy.get(".ant-dropdown-menu").should("be.visible")
cy.get(".ant-dropdown-menu-item")
.contains(/delete/i)
.click()
cy.get(".ant-modal-footer > .ant-btn-primary").click()
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ const ConfigureEvaluator = ({
]}
className="flex-1"
>
<Input />
<Input data-cy="configure-new-evaluator-modal-input" />
</Form.Item>
{/* <Form.Item
name="label"
Expand Down Expand Up @@ -471,7 +471,12 @@ const ConfigureEvaluator = ({
<Button type="text" onClick={() => form.resetFields()}>
Reset
</Button>
<Button type="primary" loading={submitLoading} onClick={form.submit}>
<Button
type="primary"
loading={submitLoading}
onClick={form.submit}
data-cy="configure-new-evaluator-modal-save-btn"
>
{editMode ? "Edit configuration" : "Save configuration"}
</Button>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const EvaluatorList = ({
onClick={(e) => e.stopPropagation()}
icon={<MoreOutlined />}
size="small"
data-cy="evaluator-menu-button"
/>
</Dropdown>
)
Expand All @@ -166,6 +167,7 @@ const EvaluatorList = ({
bordered
onRow={(record) => ({
style: {cursor: "pointer"},
"data-cy": "evaluator-list",
onClick: () => {
const selectedEval = evaluators.find((e) => e.key === record.evaluator_key)
if (selectedEval) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const Evaluators = ({
type="primary"
icon={<PlusOutlined />}
onClick={() => setCurrent(1)}
data-cy="create-new-evaluator-button"
>
Create new evaluator
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const CreateEvaluatorList = ({
scroll={{x: true, y: 550}}
style={{cursor: "pointer"}}
onRow={(record) => ({
"data-cy": "new-evaluator-list",
onClick: () => {
setSelectedEvaluator(record)
setCurrent(2)
Expand Down

0 comments on commit b8480d3

Please sign in to comment.