-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from hchayan/hchayan
[1단계 - 자동차 경주 구현] 인치(한창희) 미션 제출합니다.
- Loading branch information
Showing
22 changed files
with
2,077 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Using fixtures to represent data", | ||
"email": "hello@cypress.io", | ||
"body": "Fixtures are a great way to mock data for responses to routes" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
class CypressWrapper { | ||
type = (name, value) => { | ||
try { | ||
this._getCy(name).type(value); | ||
} catch (error) { | ||
new Error(error); | ||
} | ||
|
||
return this; | ||
}; | ||
|
||
click = name => { | ||
try { | ||
this._getCy(name).click(); | ||
} catch (error) { | ||
new Error(error); | ||
} | ||
|
||
return this; | ||
}; | ||
|
||
should = (name, ...param) => { | ||
try { | ||
this._getCy(name).should(...param); | ||
} catch (error) { | ||
new Error(error); | ||
} | ||
|
||
return this; | ||
}; | ||
|
||
_getCy = name => { | ||
return cy.get(name); | ||
}; | ||
} | ||
|
||
const cw = new CypressWrapper(); | ||
|
||
function testCar(value) { | ||
cw.type("#car-input", value) | ||
.click("#car-btn") | ||
.should("#count", "have.css", "display", "block"); | ||
} | ||
|
||
function testCount(value) { | ||
cw.type("#count-input", value) | ||
.click("#count-btn") | ||
.should("#process", "have.css", "display", "block"); | ||
} | ||
|
||
describe("ui-play", () => { | ||
before(() => { | ||
cy.visit("http://localhost:5500/"); | ||
}); | ||
|
||
it("자동차 섹션을 입력하고 버튼을 클릭하면 횟수 영역이 보여진다", () => { | ||
testCar("a,b,c,d"); | ||
}); | ||
|
||
it("시도 횟수를 입력하고 버튼을 클릭하면 진행 영역이 보여진다", () => { | ||
testCount(5); | ||
}); | ||
|
||
it("자동차 이름을 입력한 순서대로 자동차들을 생성한다", () => { | ||
const cars = ["a", "b", "c", "d"]; | ||
cy.get(".car-player").each((v, i, arr) => { | ||
cw.should(v, "have.text", cars[i]); | ||
}); | ||
}); | ||
|
||
it("시도 횟수보다 화살표의 개수가 적거나 같아야한다", () => { | ||
cy.get(".process-car").each(v => { | ||
if (v.find(".forward-icon").length > 0) { | ||
cy.get(v).find(".forward-icon").its("length").should("be.lte", 5); | ||
} | ||
}); | ||
}); | ||
|
||
it("가장많은 화살표를 가지고 있는 차의 이름이 우승자에 있어야 한다", () => { | ||
let largestCount = 0; | ||
cy.get(".process-car") | ||
.each(v => { | ||
if (v.find(".forward-icon").length > largestCount) { | ||
largestCount = v.find(".forward-icon").length; | ||
} | ||
}) | ||
.then(() => { | ||
cy.get(".process-car").each(v => { | ||
if (v.find(".forward-icon").length === largestCount) { | ||
const winner = v.find(".car-player")[0].outerText; | ||
cy.get("#result-winner").contains(winner); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
it("다시 시작하기 버튼을 클릭하면 자동차 섹션만 보이고, 입력 값이 초기화된다", () => { | ||
cw.click("#reset-btn") | ||
.should("#count", "have.css", "display", "none") | ||
.should("#process", "have.css", "display", "none") | ||
.should("#result", "have.css", "display", "none"); | ||
|
||
cy.get("#process").children().should("not.exist"); | ||
cw.should("#car-input", "have.value", ""); | ||
}); | ||
}); | ||
|
||
describe("ui-input-vaild-check", () => { | ||
beforeEach(() => { | ||
cy.visit("http://localhost:5500/"); | ||
cy.window() | ||
.then(win => cy.stub(win, "alert")) | ||
.as("alertStub"); | ||
}); | ||
|
||
it("자동차 이름이 5글자 초과하면 alert 출력", () => { | ||
testCar("overFive,a,b,c,d"); | ||
cw.should( | ||
"@alertStub", | ||
"be.calledWith", | ||
"자동차 이름의 길이는 최대 5글자 입니다." | ||
); | ||
}); | ||
|
||
it("자동차 이름에 공백 있으면 alert 출력", () => { | ||
testCar("a,b,,c,d"); | ||
cw.should( | ||
"@alertStub", | ||
"be.calledWith", | ||
"자동차 이름은 공백이 될 수 없습니다." | ||
); | ||
}); | ||
|
||
it("자동차 이름에 중복 있으면 alert 출력", () => { | ||
testCar("a,b,a,c,d"); | ||
cw.should( | ||
"@alertStub", | ||
"be.calledWith", | ||
"자동차 이름은 중복이 될 수 없습니다." | ||
); | ||
}); | ||
|
||
it("입력한 시도 횟수가 공백이면 alert 출력", () => { | ||
testCar("a,b,c,d"); | ||
testCount(" "); | ||
cw.should( | ||
"@alertStub", | ||
"be.calledWith", | ||
"시도 횟수는 공백 혹은 문자가 될 수 없습니다." | ||
); | ||
}); | ||
|
||
it("입력한 시도 횟수가 0 이하면 alert 출력", () => { | ||
testCar("a,b,c,d"); | ||
testCount(-1); | ||
cw.should( | ||
"@alertStub", | ||
"be.calledWith", | ||
"시도 횟수는 0보다 작거나 같을 수 없습니다." | ||
); | ||
}); | ||
|
||
it("입력한 시도 횟수가 소수면 alert 출력", () => { | ||
testCar("a,b,c,d"); | ||
testCount(4.21); | ||
cw.should( | ||
"@alertStub", | ||
"be.calledWith", | ||
"시도 횟수는 소수가 될 수 없습니다." | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// <reference types="cypress" /> | ||
// *********************************************************** | ||
// This example plugins/index.js can be used to load plugins | ||
// | ||
// You can change the location of this file or turn off loading | ||
// the plugins file with the 'pluginsFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/plugins-guide | ||
// *********************************************************** | ||
|
||
// This function is called when a project is opened or re-opened (e.g. due to | ||
// the project's config changing) | ||
|
||
/** | ||
* @type {Cypress.PluginConfig} | ||
*/ | ||
module.exports = (on, config) => { | ||
// `on` is used to hook into various events Cypress emits | ||
// `config` is the resolved Cypress config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// *********************************************** | ||
// This example commands.js 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) => { ... }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// *********************************************************** | ||
// This example support/index.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands' | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.