-
Notifications
You must be signed in to change notification settings - Fork 168
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 #23 from zigsong/zig-step1
[1단계 - 행운의 로또 미션] 지그(송지은) 미션 제출합니다.
- Loading branch information
Showing
20 changed files
with
2,449 additions
and
42 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,24 @@ | ||
{ | ||
"plugins": ["prettier"], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:prettier/recommended", | ||
"plugin:cypress/recommended" | ||
], | ||
"rules": { | ||
"prettier/prettier": ["error", { | ||
"endOfLine": "auto" | ||
}], | ||
"max-depth": ["error", 2] | ||
}, | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"sourceType": "module", | ||
"ecmaVersion": 12 | ||
}, | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"es6": true | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": true, | ||
"bracketSpacing": true, | ||
"arrowParens": "avoid", | ||
"printWidth": 80 | ||
} |
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,60 @@ | ||
describe('로또 게임 테스트', () => { | ||
beforeEach(() => { | ||
cy.visit('http://127.0.0.1:5500/'); | ||
}); | ||
|
||
const price = 10000; | ||
const lottoTotalCount = price / 1000; | ||
|
||
function clickAfterTypePrice() { | ||
cy.get('#input-price').type(price); | ||
cy.get('#input-price-btn').click(); | ||
} | ||
|
||
it('프로그램을 시작하면 구입금액 입력폼만 보인다.', () => { | ||
cy.get('#input-price-form').should('be.visible'); | ||
cy.get('#purchased-lottos').should('not.be.visible'); | ||
cy.get('#input-lotto-nums').should('not.be.visible'); | ||
}); | ||
|
||
it('사용자는 로또 구입 금액을 입력하면, 확인 버튼을 누르면 사용자가 구매한 로또와 지난 주 당첨 로또 입력폼이 보인다.', () => { | ||
clickAfterTypePrice(); | ||
cy.get('#purchased-lottos').should('be.visible'); | ||
cy.get('#input-lotto-nums').should('be.visible'); | ||
}); | ||
|
||
it('사용자는 로또 구입 금액을 입력하면, Enter를 누르면 사용자가 구매한 로또와 지난 주 당첨 로또 입력폼이 보인다.', () => { | ||
cy.get('#input-price').type(`${price}{enter}`); | ||
cy.get('#purchased-lottos').should('be.visible'); | ||
cy.get('#input-lotto-nums').should('be.visible'); | ||
}); | ||
|
||
it('사용자가 구매한 로또의 개수와 개수 만큼의 로또 이모지를 보여준다.', () => { | ||
clickAfterTypePrice(); | ||
|
||
cy.get('#purchased-lottos').should('be.visible'); | ||
cy.get('#total-purchased').should('have.text', lottoTotalCount); | ||
cy.get('#lotto-icons') | ||
.children('.lotto-wrapper') | ||
.should('have.length', lottoTotalCount); | ||
cy.get('#input-lotto-nums').should('be.visible'); | ||
}); | ||
|
||
it('번호 보기 스위치 off 상태에서는 로또 아이콘들이 가로로, on에서는 세로로 정렬된다.', () => { | ||
clickAfterTypePrice(); | ||
|
||
cy.get('.switch').click(); | ||
cy.get('#lotto-icons').should('have.class', 'flex-col'); | ||
cy.get('.switch').click(); | ||
cy.get('#lotto-icons').should('not.have.class', 'flex-col'); | ||
}); | ||
|
||
it('번호 보기 스위치가 off이면 구매한 로또의 번호가 보이지 않고, on이면 번호가 보인다.', () => { | ||
clickAfterTypePrice(); | ||
|
||
cy.get('.switch').click(); | ||
cy.get('.lotto-wrapper').children('.lotto-detail').should('be.visible'); | ||
cy.get('.switch').click(); | ||
cy.get('.lotto-wrapper').children('.lotto-detail').should('not.be.visible'); | ||
}); | ||
}); |
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,47 @@ | ||
describe('로또 금액 입력 예외 처리 테스트', () => { | ||
beforeEach(() => { | ||
cy.visit('http://127.0.0.1:5500/'); | ||
}); | ||
|
||
function exceptionAlert(wrongPrice, alertMessage) { | ||
const alertStub = cy.stub(); | ||
cy.on('window:alert', alertStub); | ||
|
||
cy.get('#input-price').type(wrongPrice); | ||
cy.get('#input-price-btn') | ||
.click() | ||
.then(() => { | ||
expect(alertStub.getCall(0)).to.be.calledWith(alertMessage); | ||
}); | ||
} | ||
|
||
function checkInvalid(wrongPrice, errorMessage) { | ||
cy.get('#input-price').type(wrongPrice); | ||
cy.get('#input-price-btn').click(); | ||
|
||
cy.get('input:invalid').should('have.length', 1); | ||
cy.get('#input-price').then($input => { | ||
expect($input[0].validationMessage).to.eq(errorMessage); | ||
}); | ||
} | ||
|
||
it('로또 구입 금액은 최소 1,000원으로 제한한다.', () => { | ||
checkInvalid(200, '값은 1000 이상이어야 합니다.'); | ||
|
||
cy.get('#purchased-lottos').should('not.be.visible'); | ||
cy.get('#input-lotto-nums').should('not.be.visible'); | ||
}); | ||
|
||
it('로또 구입 금액은 최대 100,000원으로 제한한다.', () => { | ||
checkInvalid(120000, '값은 100000 이하여야 합니다.'); | ||
|
||
cy.get('#purchased-lottos').should('not.be.visible'); | ||
cy.get('#input-lotto-nums').should('not.be.visible'); | ||
}); | ||
|
||
it('로또 구입 금액은 1,000원 단위여야 한다.', () => { | ||
exceptionAlert(1200, '로또 구입 금액을 1,000원 단위로 입력해 주세요.'); | ||
cy.get('#purchased-lottos').should('not.be.visible'); | ||
cy.get('#input-lotto-nums').should('not.be.visible'); | ||
}); | ||
}); |
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
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 |
---|---|---|
|
@@ -22,3 +22,7 @@ body { | |
width: 30px; | ||
height: 36px; | ||
} | ||
|
||
ul { | ||
padding: 0; | ||
} |
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,20 @@ | ||
import getRandomNumber from './utils/utils.js'; | ||
|
||
export default class Lotto { | ||
static LOTT0_LENGTH = 6; | ||
|
||
constructor() { | ||
this.numbers = new Set(); | ||
this.initNumbers(); | ||
} | ||
|
||
initNumbers() { | ||
while (this.numbers.size < Lotto.LOTT0_LENGTH) { | ||
this.numbers.add(getRandomNumber()); | ||
} | ||
} | ||
|
||
get numberDetail() { | ||
return [...this.numbers.values()].join(', '); | ||
} | ||
} |
Oops, something went wrong.