Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[클린코드 4기 방현경] 자판기 미션 STEP 1 #54

Open
wants to merge 11 commits into
base: hyeonbang
Choose a base branch
from
Open
31 changes: 31 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"env": {
"browser": true,
"es2021": true,
"es6": true
},
"extends": "airbnb-base",
"overrides": [
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "single"],
"indent": ["error", 4],
"no-return-assign": "off",
"no-param-reassign": "off",
"arrow-parens": "off",
"import/prefer-default-export": "off",
"class-methods-use-this": "off",
"comma-dangle": "off",
"no-unused-vars": "off",
"import/extensions": "off",
"max-classes-per-file": "off",
"no-alert": "off",
"no-unsafe-negation": "off",
"consistent-return": "off"
}
}
105 changes: 105 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/js-vending-machine.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
};
27 changes: 27 additions & 0 deletions cypress/e2e/home.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe('사이트 홈 테스트', () => {
beforeEach('페이지 방문', () => {
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

방문보다는 렌더링에 초점이 있는 것 같은데 렌더링 테스트 네이밍은 어떠세요?

cy.visit('/');
});

homeSpec();
})

function homeSpec() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec이라는 의미는 기능 단위로 나눴다고 보시면 될까요?

it('첫 페이지에 상품관리, 잔돈충전, 상품구매 버튼이 있다.', () => {
cy.get('#stock-manage-menu').should('exist');
cy.get('#vending-machine-manage-menu').should('exist');
cy.get('#product-purchase-menu').should('exist');
cy.get('.stock-container').should('not.be.visible');
});

it('상품관리탭을 클릭하면 상품 추가하기 창이 보여진다.', () => {
cy.clickStockTab();
cy.get('.stock-container').should('be.visible');
});

it('잔돈충전탭을 클릭하면 잔돈 충전하기 창이 보여진다.', () => {
cy.clickRechargeTab();
cy.get('.recharge-container').should('be.visible');
});
}

80 changes: 80 additions & 0 deletions cypress/e2e/recharge.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { ERROR_MESSAGE } from "../../src/js/common/error.js";
describe('잔돈 충전하기 테스트', () => {
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import 다음에는 개행을 하나 추가하는게 어떨까요?!

beforeEach('페이지 방문', () => {
cy.visit('/');
});

beforeEach('잔돈충전 탭 클릭', () => {
cy.clickRechargeTab();
});

rechargeSpeck();
})

function rechargeSpeck() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rechargeSpec을 의도하신 네이밍 맞을까요?

const amount = 100;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사소하지만 변경되지 않는 값이라면 상수로 명시해주는게 어떨까요?
매개변수로 넘어온다고 생각할 수 있거든요!


it('최초 자판기의 보유금액은 0원이다.', () => {
cy.get('#recharge-amount').should('have.text', 0);
});

it('최소 충전 금액은 100원이다. :: 경계값', () => {
cy.typeRechargeAmount(99);
checkAlert(cy.clickRecharge(), ERROR_MESSAGE.InputMinInsufficientError);
});

it('충전 금액의 단위는 10원이다.', () => {
cy.typeRechargeAmount(101);
checkAlert(cy.clickRecharge(), ERROR_MESSAGE.InputPriceUnitError);
});

it('자판기에 금액을 입력하여 충전하기 버튼을 누르면 보유 금액을 충전할 수 있다.', () => {
cy.typeRechargeAmount(amount);
cy.clickRecharge();
cy.get('#recharge-amount').should('have.text', amount);
});

it('금액을 충전하면 잔돈이 생성된다.', () => {
cy.typeRechargeAmount(amount);
cy.clickRecharge();
cy.get('#recharge-cashbox-container').children().should('have.length', 4);
});

it('보유 금액은 누적된다.', () => {
const newAmount = 200;
cy.typeRechargeAmount(amount);
cy.clickRecharge();
cy.get('#recharge-amount').should('have.text', amount);

cy.get('#recharge-input').clear();
cy.typeRechargeAmount(newAmount);
cy.clickRecharge();
cy.get('#recharge-amount').should('have.text', amount + newAmount);
});

it('다른 탭을 클릭해도 보유된 금액은 유지된다.', () => {
cy.typeRechargeAmount(amount);
cy.clickRecharge();
cy.get('#recharge-amount').should('have.text', amount);

cy.clickStockTab();
cy.clickRechargeTab();
cy.get('#recharge-amount').should('have.text', amount);
});

it('같은 세션에서 새로고침을 해도 보유 금액과 잔돈은 저장된다.', () => {
cy.typeRechargeAmount(amount);
cy.clickRecharge();
cy.get('#recharge-amount').should('have.text', amount);

cy.reload();
cy.clickRechargeTab();
cy.get('#recharge-amount').should('have.text', amount);
});
}

function checkAlert(scenario, message) {
const stub = cy.stub();
cy.on('window:alert', stub);
scenario.then(() => expect(stub.getCall(0)?.lastArg).to.equals(message));
}
Loading