forked from next-step/js-racingcar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[클린코드 1기 조은규] [Step1] 자동차 경주 미션 (next-step#39)
- Loading branch information
Showing
20 changed files
with
669 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
yarn.lock | ||
dist | ||
build |
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": "[email protected]", | ||
"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,79 @@ | ||
/// <reference types="cypress" /> | ||
|
||
import { | ||
CAR_NAMES, | ||
CAR_NAMES_ARRAY, | ||
WRONG_CAR_NAMES, | ||
} from '../support/constants' | ||
|
||
describe('🏎️ 자동차 경주 게임', () => { | ||
beforeEach(() => { | ||
cy.visit('https://eungyucho.github.io/js-racingcar/') | ||
cy.get('[id=car_name_input]').as('carNameInput') | ||
cy.get('[id=car_name_button]').as('carNameButton') | ||
cy.get('[id=game_count_input]').as('gameCountInput') | ||
cy.get('[id=game_count_button]').as('gameCountButton') | ||
cy.get('[id=game_count_button]').as('gameCountButton') | ||
}) | ||
|
||
it('유효하지 않은 자동차 이름을 입력하면 경고메세지를 띄워준다.', () => { | ||
cy.get('@carNameInput').should('be.visible') | ||
cy.get('@carNameButton').should('be.visible') | ||
cy.get('@gameCountInput').should('not.be.visible') | ||
cy.get('@gameCountButton').should('not.be.visible') | ||
|
||
cy.get('@carNameInput').type(WRONG_CAR_NAMES) | ||
cy.alertMessageWillBeEqual( | ||
'자동차의 이름은 한글자 ~ 5글자 사이만 가능합니다.' | ||
) | ||
cy.get('@carNameButton').click() | ||
cy.get('@gameCountInput').should('not.be.visible') | ||
cy.get('@gameCountButton').should('not.be.visible') | ||
}) | ||
|
||
it('유효한 자동차 이름을 입력하면 시도할 횟수를 입력받을 수 있다.', () => { | ||
cy.get('@carNameInput').should('be.visible') | ||
cy.get('@carNameButton').should('be.visible') | ||
cy.get('@gameCountInput').should('not.be.visible') | ||
cy.get('@gameCountButton').should('not.be.visible') | ||
|
||
cy.get('@carNameInput').type(CAR_NAMES) | ||
cy.get('@carNameButton').click() | ||
cy.get('@gameCountInput').should('be.visible') | ||
cy.get('@gameCountButton').should('be.visible') | ||
}) | ||
|
||
it('게임횟수에 3을 입력하면 횟수를 입력하면 입력했던 자동차 이름들이 Road에 세팅된다.', () => { | ||
cy.get('@carNameInput').type(CAR_NAMES) | ||
cy.get('@carNameButton').click() | ||
cy.get('@gameCountInput').type(3) | ||
cy.get('@gameCountButton').click('') | ||
|
||
cy.getPlayers() | ||
.should('be.visible') | ||
.should('have.length', 4) | ||
.each((player, index) => | ||
cy.wrap(player).should('have.text', CAR_NAMES_ARRAY[index]) | ||
) | ||
}) | ||
|
||
it('게임횟수에 3을 입력하면 횟수를 입력하면 게임을 시작한다.', () => { | ||
cy.get('@carNameInput').type(CAR_NAMES) | ||
cy.get('@carNameButton').click() | ||
cy.get('@gameCountInput').type(3) | ||
cy.get('@gameCountButton').click('') | ||
|
||
cy.wait(3000) | ||
|
||
cy.getPlayers() | ||
.should('be.visible') | ||
.should('have.length', 4) | ||
.each((player) => | ||
cy | ||
.wrap(player) | ||
.parent() | ||
.children('.forward-icon') | ||
.should('have.length.lessThan', 4) | ||
) | ||
}) | ||
}) |
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,22 @@ | ||
/// <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} | ||
*/ | ||
// eslint-disable-next-line no-unused-vars | ||
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,9 @@ | ||
Cypress.Commands.add('alertMessageWillBeEqual', (text) => { | ||
cy.on('window:alert', (txt) => { | ||
expect(text).to.equal(txt) | ||
}) | ||
}) | ||
|
||
Cypress.Commands.add('getPlayers', () => { | ||
return cy.get('.car-player') | ||
}) |
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 @@ | ||
const CAR_NAMES = 'EAST, WEST, SOUTH, NORTH' | ||
const CAR_NAMES_ARRAY = CAR_NAMES.split(',').map((name) => name.trim()) | ||
const WRONG_CAR_NAMES = CAR_NAMES + ', VERY_LONG_NAME' | ||
|
||
export { CAR_NAMES, WRONG_CAR_NAMES, CAR_NAMES_ARRAY } |
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') |
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,13 @@ | ||
{ | ||
"scripts": { | ||
"build": "esbuild --bundle src/css/index.css --outfile=build/out.css", | ||
"deploy": "gh-pages -d build", | ||
"start": "esbuild src/ts/index.ts --bundle --outfile=build/index.js --watch" | ||
}, | ||
"devDependencies": { | ||
"cypress": "^9.1.0", | ||
"esbuild": "^0.13.15", | ||
"gh-pages": "^3.2.3", | ||
"typescript": "^4.5.2" | ||
} | ||
} |
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,10 @@ | ||
const NAME_LENGTH_INVALID_ERROR = | ||
'자동차의 이름은 한글자 ~ 5글자 사이만 가능합니다.' | ||
const GAME_COUNT_INVALID_ERROR = '게임횟수는 1이상으로 입력해주세요.' | ||
|
||
const ERROR_MESSAGES = Object.freeze({ | ||
NAME_LENGTH_INVALID_ERROR, | ||
GAME_COUNT_INVALID_ERROR, | ||
}) | ||
|
||
export default ERROR_MESSAGES |
Oops, something went wrong.