diff --git a/frontend/cypress/e2e/application.second-personal-information.cy.ts b/frontend/cypress/e2e/application.second-personal-information.cy.ts new file mode 100644 index 00000000..61060a18 --- /dev/null +++ b/frontend/cypress/e2e/application.second-personal-information.cy.ts @@ -0,0 +1,69 @@ +describe("2번째 인적사항 e2e 테스트", () => { + beforeEach(() => { + cy.viewport(1200, 900); + + cy.goSecondPersonalInformation(); + + cy.get("span") + .filter((index, element) => Cypress.$(element).text().trim() === "전공*") + .parent() + .next("input") + .as("major"); + + cy.get("span") + .filter( + (index, element) => Cypress.$(element).text().trim() === "복수전공" + ) + .parent() + .next("input") + .as("revengeMajor"); + + cy.get("span") + .filter((index, element) => Cypress.$(element).text().trim() === "부전공") + .parent() + .next("input") + .as("minor"); + + cy.get("button").contains("다음").as("nextButton"); + }); + + it("전공 입력 후 다음 버튼 클릭하면 기타 질문 사항으로 이동", () => { + cy.get("@major").type("컴퓨터정보통신공학과"); + cy.get("@nextButton").click(); + }); + + it("전공, 복수전공 입력 후 다음 버튼 클릭하면 기타 질문 사항으로 이동", () => { + cy.get("@major").type("컴퓨터정보통신공학과"); + cy.get("@revengeMajor").type("건축학과"); + cy.get("@nextButton").click(); + }); + + it("전공, 부전공 입력 후 다음 버튼 클릭하면 기타 질문 사항으로 이동", () => { + cy.get("@major").type("컴퓨터정보통신공학과"); + cy.get("@minor").type("물리학과"); + cy.get("@nextButton").click(); + }); + + it("전공, 복수전공, 부전공 입력 후 다음 버튼 클릭하면 기타 질문 사항으로 이동", () => { + cy.get("@major").type("컴퓨터정보통신공학과"); + cy.get("@revengeMajor").type("건축학과"); + cy.get("@minor").type("물리학과"); + cy.get("@nextButton").click(); + }); + + it("아무것도 입력하지 않고 다음 버튼 클릭하면 '필수 질문을 작성해주세요.'라는 alert창이 보인다.", () => { + cy.get("@nextButton").click(); + cy.on("window:alert", (text) => { + console.log("Alert message:", text); + }); + }); + + it("전공을 입력하지 않고 복수전공, 부전공을 입력 후 다음 버튼 클릭하면 '필수 질문을 작성해주세요.'라는 alert창이 보인다.", () => { + cy.get("@revengeMajor").type("건축학과"); + cy.get("@minor").type("물리학과"); + cy.get("@nextButton").click(); + cy.on("window:alert", (text) => { + console.log("Alert message:", text); + }); + }); +}); diff --git a/frontend/cypress/support/commands.ts b/frontend/cypress/support/commands.ts index 698b01a4..6fae91b5 100644 --- a/frontend/cypress/support/commands.ts +++ b/frontend/cypress/support/commands.ts @@ -1,37 +1,57 @@ /// -// *********************************************** -// This example commands.ts shows you how to -// create various custom commands and overwrite -// existing commands. -// -// For more comprehensive examples of custom -// commands please read more here: -// https://on.cypress.io/custom-commands -// *********************************************** -// -// -// -- This is a parent command -- -// Cypress.Commands.add('login', (email, password) => { ... }) -// -// -// -- This is a child command -- -// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) -// -// -// -- This is a dual command -- -// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) -// -// -// -- This will overwrite an existing command -- -// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) -// -// declare global { -// namespace Cypress { -// interface Chainable { -// login(email: string, password: string): Chainable -// drag(subject: string, options?: Partial): Chainable -// dismiss(subject: string, options?: Partial): Chainable -// visit(originalFn: CommandOriginalFn, url: string, options: Partial): Chainable -// } -// } -// } \ No newline at end of file + +declare namespace Cypress { + interface Chainable { + goSecondPersonalInformation(): Chainable; + } +} + +Cypress.Commands.add("goSecondPersonalInformation", () => { + cy.clearAllLocalStorage(); + cy.visit("http://localhost:3000/application"); + cy.get("label").contains("개발자").should("exist").click(); + cy.get("span") + .contains("1순위") + .next() + .contains("label", "APP") + .should("exist") + .click(); + cy.get("span") + .filter((index, element) => Cypress.$(element).text().trim() === "2순위") + .next() + .contains("label", "WEB") + .should("exist") + .click(); + cy.get("button").contains("다음").should("exist").click(); + cy.get("span") + .contains("이름") + .parent() + .next() + .type("심민보") + .invoke("val") + .should("satisfy", (value) => value.length <= 5); + cy.get("span") + .contains("연락처") + .parent() + .next() + .type("00000000000") + .invoke("val") + .should("match", /^\d{3}-\d{4}-\d{4}$/); + cy.get("span") + .contains("학번") + .parent() + .next() + .type("123456") + .invoke("val") + .should("match", /^\d{6}$/); + cy.get("span") + .contains("학적상태") + .parent() + .next() + .type("재학") + .invoke("val") + .should("satisfy", (value) => value.length >= 1); + cy.get("label").contains("4학년").should("exist").click(); + cy.get("label").contains("2학기").should("exist").click(); + cy.get("button").contains("다음").should("exist").click(); +});