├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .github └── FUNDING.yml ├── .gitignore ├── .postcssrc.js ├── README.md ├── build ├── build.js ├── check-versions.js ├── dev-client.js ├── dev-server.js ├── utils.js ├── vue-loader.conf.js ├── webpack.base.conf.js ├── webpack.dev.conf.js ├── webpack.prod.conf.js └── webpack.test.conf.js ├── config ├── dev.env.js ├── index.js ├── prod.env.js └── test.env.js ├── index.html ├── package-lock.json ├── package.json ├── src ├── App.vue ├── api │ └── fixtures.js ├── assets │ ├── bg.jpg │ └── logo.png ├── components │ ├── Hello.vue │ ├── contact │ │ ├── Email.vue │ │ ├── Gmap.vue │ │ ├── Index.vue │ │ └── Phone.vue │ ├── homepage │ │ └── Slideshow.vue │ ├── shared │ │ ├── Footer.vue │ │ └── Navbar.vue │ └── shop │ │ ├── Shop.vue │ │ ├── cart │ │ ├── Cart.vue │ │ ├── Checkout.vue │ │ ├── Items.vue │ │ ├── Summery.vue │ │ └── Thanks.vue │ │ └── products │ │ ├── AddToCart.vue │ │ ├── List.vue │ │ ├── RemoveFromCart.vue │ │ └── Single.vue ├── main.js ├── pipes │ └── Currency.js ├── router │ └── index.js └── store │ ├── index.js │ └── shop │ ├── actions.js │ ├── getters.js │ ├── modules │ ├── cart.js │ ├── products.js │ ├── profile.js │ └── promotions.js │ └── mutation-constant.js ├── static └── .gitkeep ├── test ├── e2e │ ├── custom-assertions │ │ └── elementCount.js │ ├── nightwatch.conf.js │ ├── runner.js │ └── specs │ │ └── test.js └── unit │ ├── .eslintrc │ ├── index.js │ ├── karma.conf.js │ └── specs │ └── Hello.spec.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { "modules": false }], 4 | "stage-2" 5 | ], 6 | "plugins": ["transform-runtime"], 7 | "comments": false, 8 | "env": { 9 | "test": { 10 | "presets": ["env", "stage-2"], 11 | "plugins": [ "istanbul" ] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | build/*.js 2 | config/*.js 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // http://eslint.org/docs/user-guide/configuring 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | sourceType: 'module' 8 | }, 9 | env: { 10 | browser: true, 11 | }, 12 | extends: 'airbnb-base', 13 | // required to lint *.vue files 14 | plugins: [ 15 | 'html' 16 | ], 17 | // check if imports actually resolve 18 | 'settings': { 19 | 'import/resolver': { 20 | 'webpack': { 21 | 'config': 'build/webpack.base.conf.js' 22 | } 23 | } 24 | }, 25 | // add your custom rules here 26 | 'rules': { 27 | // don't require .vue extension when importing 28 | 'import/extensions': ['error', 'always', { 29 | 'js': 'never', 30 | 'vue': 'never' 31 | }], 32 | // allow optionalDependencies 33 | 'import/no-extraneous-dependencies': ['error', { 34 | 'optionalDependencies': ['test/unit/index.js'] 35 | }], 36 | // allow debugger during development 37 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [mhadaily] 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | npm-debug.log 5 | yarn-error.log 6 | test/unit/coverage 7 | test/e2e/reports 8 | selenium-debug.log 9 | -------------------------------------------------------------------------------- /.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | // to edit target browsers: use "browserlist" field in package.json 6 | "autoprefixer": {} 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vue2-Vuex-shop 2 | 3 | > This is an experimental Vue Project in order to compare with Angular2 and Ember2, [Live Demo](https://www.majidhajian.com/vue2-shop/). 4 | 5 | Please checkout Angular2 and Ember.js Version of this project.(Coming soon) 6 | I encourage you to read my [article about this comparison](https://goo.gl/cnaXDq). 7 | 8 | This project has been initialized by Vue-Cli using Webpack, Mocha, ESlint. 9 | 10 | ## Dependencies 11 | 12 | * "vue" 13 | * "vue-router" 14 | * "vuex" 15 | 16 | ## Deploy to gh-page 17 | 18 | easily run this command when you forked: `npm run deploy` 19 | 20 | ## Build Setup 21 | 22 | ``` bash 23 | # install dependencies 24 | npm install 25 | 26 | 27 | # serve with hot reload at localhost:8080 28 | npm run dev 29 | 30 | # build for production with minification 31 | npm run build 32 | 33 | # build for production and view the bundle analyzer report 34 | npm run build --report 35 | 36 | # run unit tests 37 | npm run unit 38 | 39 | # run e2e tests 40 | npm run e2e 41 | 42 | # run all tests 43 | npm test 44 | ``` 45 | 46 | ## TODO 47 | * Unit Test 48 | * Integration Test 49 | * Add backend logic 50 | * Pagination 51 | * Add Guard for Route (User Profile) 52 | * Promotions and Discounts 53 | * Refine code and bundle 54 | 55 | For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader). 56 | -------------------------------------------------------------------------------- /build/build.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | process.env.NODE_ENV = 'production' 4 | 5 | var ora = require('ora') 6 | var rm = require('rimraf') 7 | var path = require('path') 8 | var chalk = require('chalk') 9 | var webpack = require('webpack') 10 | var config = require('../config') 11 | var webpackConfig = require('./webpack.prod.conf') 12 | 13 | var spinner = ora('building for production...') 14 | spinner.start() 15 | 16 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 17 | if (err) throw err 18 | webpack(webpackConfig, function (err, stats) { 19 | spinner.stop() 20 | if (err) throw err 21 | process.stdout.write(stats.toString({ 22 | colors: true, 23 | modules: false, 24 | children: false, 25 | chunks: false, 26 | chunkModules: false 27 | }) + '\n\n') 28 | 29 | console.log(chalk.cyan(' Build complete.\n')) 30 | console.log(chalk.yellow( 31 | ' Tip: built files are meant to be served over an HTTP server.\n' + 32 | ' Opening index.html over file:// won\'t work.\n' 33 | )) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /build/check-versions.js: -------------------------------------------------------------------------------- 1 | var chalk = require('chalk') 2 | var semver = require('semver') 3 | var packageConfig = require('../package.json') 4 | 5 | function exec (cmd) { 6 | return require('child_process').execSync(cmd).toString().trim() 7 | } 8 | 9 | var versionRequirements = [ 10 | { 11 | name: 'node', 12 | currentVersion: semver.clean(process.version), 13 | versionRequirement: packageConfig.engines.node 14 | }, 15 | { 16 | name: 'npm', 17 | currentVersion: exec('npm --version'), 18 | versionRequirement: packageConfig.engines.npm 19 | } 20 | ] 21 | 22 | module.exports = function () { 23 | var warnings = [] 24 | for (var i = 0; i < versionRequirements.length; i++) { 25 | var mod = versionRequirements[i] 26 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 27 | warnings.push(mod.name + ': ' + 28 | chalk.red(mod.currentVersion) + ' should be ' + 29 | chalk.green(mod.versionRequirement) 30 | ) 31 | } 32 | } 33 | 34 | if (warnings.length) { 35 | console.log('') 36 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 37 | console.log() 38 | for (var i = 0; i < warnings.length; i++) { 39 | var warning = warnings[i] 40 | console.log(' ' + warning) 41 | } 42 | console.log() 43 | process.exit(1) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /build/dev-client.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | require('eventsource-polyfill') 3 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') 4 | 5 | hotClient.subscribe(function (event) { 6 | if (event.action === 'reload') { 7 | window.location.reload() 8 | } 9 | }) 10 | -------------------------------------------------------------------------------- /build/dev-server.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | var config = require('../config') 4 | if (!process.env.NODE_ENV) { 5 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) 6 | } 7 | 8 | var opn = require('opn') 9 | var path = require('path') 10 | var express = require('express') 11 | var webpack = require('webpack') 12 | var proxyMiddleware = require('http-proxy-middleware') 13 | var webpackConfig = process.env.NODE_ENV === 'testing' 14 | ? require('./webpack.prod.conf') 15 | : require('./webpack.dev.conf') 16 | 17 | // default port where dev server listens for incoming traffic 18 | var port = process.env.PORT || config.dev.port 19 | // automatically open browser, if not set will be false 20 | var autoOpenBrowser = !!config.dev.autoOpenBrowser 21 | // Define HTTP proxies to your custom API backend 22 | // https://github.com/chimurai/http-proxy-middleware 23 | var proxyTable = config.dev.proxyTable 24 | 25 | var app = express() 26 | var compiler = webpack(webpackConfig) 27 | 28 | var devMiddleware = require('webpack-dev-middleware')(compiler, { 29 | publicPath: webpackConfig.output.publicPath, 30 | quiet: true 31 | }) 32 | 33 | var hotMiddleware = require('webpack-hot-middleware')(compiler, { 34 | log: () => {} 35 | }) 36 | // force page reload when html-webpack-plugin template changes 37 | compiler.plugin('compilation', function (compilation) { 38 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { 39 | hotMiddleware.publish({ action: 'reload' }) 40 | cb() 41 | }) 42 | }) 43 | 44 | // proxy api requests 45 | Object.keys(proxyTable).forEach(function (context) { 46 | var options = proxyTable[context] 47 | if (typeof options === 'string') { 48 | options = { target: options } 49 | } 50 | app.use(proxyMiddleware(options.filter || context, options)) 51 | }) 52 | 53 | // handle fallback for HTML5 history API 54 | app.use(require('connect-history-api-fallback')()) 55 | 56 | // serve webpack bundle output 57 | app.use(devMiddleware) 58 | 59 | // enable hot-reload and state-preserving 60 | // compilation error display 61 | app.use(hotMiddleware) 62 | 63 | // serve pure static assets 64 | var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) 65 | app.use(staticPath, express.static('./static')) 66 | 67 | var uri = 'http://localhost:' + port 68 | 69 | devMiddleware.waitUntilValid(function () { 70 | console.log('> Listening at ' + uri + '\n') 71 | }) 72 | 73 | module.exports = app.listen(port, function (err) { 74 | if (err) { 75 | console.log(err) 76 | return 77 | } 78 | 79 | // when env is testing, don't need open it 80 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { 81 | opn(uri) 82 | } 83 | }) 84 | -------------------------------------------------------------------------------- /build/utils.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var config = require('../config') 3 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 4 | 5 | exports.assetsPath = function (_path) { 6 | var assetsSubDirectory = process.env.NODE_ENV === 'production' 7 | ? config.build.assetsSubDirectory 8 | : config.dev.assetsSubDirectory 9 | return path.posix.join(assetsSubDirectory, _path) 10 | } 11 | 12 | exports.cssLoaders = function (options) { 13 | options = options || {} 14 | 15 | var cssLoader = { 16 | loader: 'css-loader', 17 | options: { 18 | minimize: process.env.NODE_ENV === 'production', 19 | sourceMap: options.sourceMap 20 | } 21 | } 22 | 23 | // generate loader string to be used with extract text plugin 24 | function generateLoaders (loader, loaderOptions) { 25 | var loaders = [cssLoader] 26 | if (loader) { 27 | loaders.push({ 28 | loader: loader + '-loader', 29 | options: Object.assign({}, loaderOptions, { 30 | sourceMap: options.sourceMap 31 | }) 32 | }) 33 | } 34 | 35 | // Extract CSS when that option is specified 36 | // (which is the case during production build) 37 | if (options.extract) { 38 | return ExtractTextPlugin.extract({ 39 | use: loaders, 40 | fallback: 'vue-style-loader' 41 | }) 42 | } else { 43 | return ['vue-style-loader'].concat(loaders) 44 | } 45 | } 46 | 47 | // http://vuejs.github.io/vue-loader/en/configurations/extract-css.html 48 | return { 49 | css: generateLoaders(), 50 | postcss: generateLoaders(), 51 | less: generateLoaders('less'), 52 | sass: generateLoaders('sass', { indentedSyntax: true }), 53 | scss: generateLoaders('sass'), 54 | stylus: generateLoaders('stylus'), 55 | styl: generateLoaders('stylus') 56 | } 57 | } 58 | 59 | // Generate loaders for standalone style files (outside of .vue) 60 | exports.styleLoaders = function (options) { 61 | var output = [] 62 | var loaders = exports.cssLoaders(options) 63 | for (var extension in loaders) { 64 | var loader = loaders[extension] 65 | output.push({ 66 | test: new RegExp('\\.' + extension + '$'), 67 | use: loader 68 | }) 69 | } 70 | return output 71 | } 72 | -------------------------------------------------------------------------------- /build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var config = require('../config') 3 | var isProduction = process.env.NODE_ENV === 'production' 4 | 5 | module.exports = { 6 | loaders: utils.cssLoaders({ 7 | sourceMap: isProduction 8 | ? config.build.productionSourceMap 9 | : config.dev.cssSourceMap, 10 | extract: isProduction 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var config = require('../config') 4 | var vueLoaderConfig = require('./vue-loader.conf') 5 | 6 | function resolve (dir) { 7 | return path.join(__dirname, '..', dir) 8 | } 9 | 10 | module.exports = { 11 | entry: { 12 | app: './src/main.js' 13 | }, 14 | output: { 15 | path: config.build.assetsRoot, 16 | filename: '[name].js', 17 | publicPath: process.env.NODE_ENV === 'production' 18 | ? config.build.assetsPublicPath 19 | : config.dev.assetsPublicPath 20 | }, 21 | resolve: { 22 | extensions: ['.js', '.vue', '.json'], 23 | alias: { 24 | 'vue$': 'vue/dist/vue.esm.js', 25 | '@': resolve('src'), 26 | } 27 | }, 28 | module: { 29 | rules: [ 30 | { 31 | test: /\.(js|vue)$/, 32 | loader: 'eslint-loader', 33 | enforce: "pre", 34 | include: [resolve('src'), resolve('test')], 35 | options: { 36 | formatter: require('eslint-friendly-formatter') 37 | } 38 | }, 39 | { 40 | test: /\.vue$/, 41 | loader: 'vue-loader', 42 | options: vueLoaderConfig 43 | }, 44 | { 45 | test: /\.js$/, 46 | loader: 'babel-loader', 47 | include: [resolve('src'), resolve('test')] 48 | }, 49 | { 50 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 51 | loader: 'url-loader', 52 | query: { 53 | limit: 10000, 54 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 55 | } 56 | }, 57 | { 58 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 59 | loader: 'url-loader', 60 | query: { 61 | limit: 10000, 62 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 63 | } 64 | } 65 | ] 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var webpack = require('webpack') 3 | var config = require('../config') 4 | var merge = require('webpack-merge') 5 | var baseWebpackConfig = require('./webpack.base.conf') 6 | var HtmlWebpackPlugin = require('html-webpack-plugin') 7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 8 | 9 | // add hot-reload related code to entry chunks 10 | Object.keys(baseWebpackConfig.entry).forEach(function (name) { 11 | baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) 12 | }) 13 | 14 | module.exports = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) 17 | }, 18 | // cheap-module-eval-source-map is faster for development 19 | devtool: '#cheap-module-eval-source-map', 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | 'process.env': config.dev.env 23 | }), 24 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage 25 | new webpack.HotModuleReplacementPlugin(), 26 | new webpack.NoEmitOnErrorsPlugin(), 27 | // https://github.com/ampedandwired/html-webpack-plugin 28 | new HtmlWebpackPlugin({ 29 | filename: 'index.html', 30 | template: 'index.html', 31 | inject: true 32 | }), 33 | new FriendlyErrorsPlugin() 34 | ] 35 | }) 36 | -------------------------------------------------------------------------------- /build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var webpack = require('webpack') 4 | var config = require('../config') 5 | var merge = require('webpack-merge') 6 | var baseWebpackConfig = require('./webpack.base.conf') 7 | var CopyWebpackPlugin = require('copy-webpack-plugin') 8 | var HtmlWebpackPlugin = require('html-webpack-plugin') 9 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 11 | 12 | var env = process.env.NODE_ENV === 'testing' 13 | ? require('../config/test.env') 14 | : config.build.env 15 | 16 | var webpackConfig = merge(baseWebpackConfig, { 17 | module: { 18 | rules: utils.styleLoaders({ 19 | sourceMap: config.build.productionSourceMap, 20 | extract: true 21 | }) 22 | }, 23 | devtool: config.build.productionSourceMap ? '#source-map' : false, 24 | output: { 25 | path: config.build.assetsRoot, 26 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 27 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 28 | }, 29 | plugins: [ 30 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 31 | new webpack.DefinePlugin({ 32 | 'process.env': env 33 | }), 34 | new webpack.optimize.UglifyJsPlugin({ 35 | compress: { 36 | warnings: false 37 | }, 38 | sourceMap: true 39 | }), 40 | // extract css into its own file 41 | new ExtractTextPlugin({ 42 | filename: utils.assetsPath('css/[name].[contenthash].css') 43 | }), 44 | // Compress extracted CSS. We are using this plugin so that possible 45 | // duplicated CSS from different components can be deduped. 46 | new OptimizeCSSPlugin(), 47 | // generate dist index.html with correct asset hash for caching. 48 | // you can customize output by editing /index.html 49 | // see https://github.com/ampedandwired/html-webpack-plugin 50 | new HtmlWebpackPlugin({ 51 | filename: process.env.NODE_ENV === 'testing' 52 | ? 'index.html' 53 | : config.build.index, 54 | template: 'index.html', 55 | inject: true, 56 | minify: { 57 | removeComments: true, 58 | collapseWhitespace: true, 59 | removeAttributeQuotes: true 60 | // more options: 61 | // https://github.com/kangax/html-minifier#options-quick-reference 62 | }, 63 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 64 | chunksSortMode: 'dependency' 65 | }), 66 | // split vendor js into its own file 67 | new webpack.optimize.CommonsChunkPlugin({ 68 | name: 'vendor', 69 | minChunks: function (module, count) { 70 | // any required modules inside node_modules are extracted to vendor 71 | return ( 72 | module.resource && 73 | /\.js$/.test(module.resource) && 74 | module.resource.indexOf( 75 | path.join(__dirname, '../node_modules') 76 | ) === 0 77 | ) 78 | } 79 | }), 80 | // extract webpack runtime and module manifest to its own file in order to 81 | // prevent vendor hash from being updated whenever app bundle is updated 82 | new webpack.optimize.CommonsChunkPlugin({ 83 | name: 'manifest', 84 | chunks: ['vendor'] 85 | }), 86 | // copy custom static assets 87 | new CopyWebpackPlugin([ 88 | { 89 | from: path.resolve(__dirname, '../static'), 90 | to: config.build.assetsSubDirectory, 91 | ignore: ['.*'] 92 | } 93 | ]) 94 | ] 95 | }) 96 | 97 | if (config.build.productionGzip) { 98 | var CompressionWebpackPlugin = require('compression-webpack-plugin') 99 | 100 | webpackConfig.plugins.push( 101 | new CompressionWebpackPlugin({ 102 | asset: '[path].gz[query]', 103 | algorithm: 'gzip', 104 | test: new RegExp( 105 | '\\.(' + 106 | config.build.productionGzipExtensions.join('|') + 107 | ')$' 108 | ), 109 | threshold: 10240, 110 | minRatio: 0.8 111 | }) 112 | ) 113 | } 114 | 115 | if (config.build.bundleAnalyzerReport) { 116 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 117 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 118 | } 119 | 120 | module.exports = webpackConfig 121 | -------------------------------------------------------------------------------- /build/webpack.test.conf.js: -------------------------------------------------------------------------------- 1 | // This is the webpack config used for unit tests. 2 | 3 | var utils = require('./utils') 4 | var webpack = require('webpack') 5 | var merge = require('webpack-merge') 6 | var baseConfig = require('./webpack.base.conf') 7 | 8 | var webpackConfig = merge(baseConfig, { 9 | // use inline sourcemap for karma-sourcemap-loader 10 | module: { 11 | rules: utils.styleLoaders() 12 | }, 13 | devtool: '#inline-source-map', 14 | plugins: [ 15 | new webpack.DefinePlugin({ 16 | 'process.env': require('../config/test.env') 17 | }) 18 | ] 19 | }) 20 | 21 | // no need for app entry during tests 22 | delete webpackConfig.entry 23 | 24 | module.exports = webpackConfig 25 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var prodEnv = require('./prod.env') 3 | 4 | module.exports = merge(prodEnv, { 5 | NODE_ENV: '"development"' 6 | }) 7 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | // see http://vuejs-templates.github.io/webpack for documentation. 2 | var path = require('path') 3 | 4 | module.exports = { 5 | build: { 6 | env: require('./prod.env'), 7 | index: path.resolve(__dirname, '../dist/index.html'), 8 | assetsRoot: path.resolve(__dirname, '../dist'), 9 | assetsSubDirectory: 'static', 10 | assetsPublicPath: '/vue2-shop' + '/', 11 | productionSourceMap: true, 12 | // Gzip off by default as many popular static hosts such as 13 | // Surge or Netlify already gzip all static assets for you. 14 | // Before setting to `true`, make sure to: 15 | // npm install --save-dev compression-webpack-plugin 16 | productionGzip: false, 17 | productionGzipExtensions: ['js', 'css'], 18 | // Run the build command with an extra argument to 19 | // View the bundle analyzer report after build finishes: 20 | // `npm run build --report` 21 | // Set to `true` or `false` to always turn it on or off 22 | bundleAnalyzerReport: process.env.npm_config_report 23 | }, 24 | dev: { 25 | env: require('./dev.env'), 26 | port: 8080, 27 | autoOpenBrowser: true, 28 | assetsSubDirectory: 'static', 29 | assetsPublicPath: '/', 30 | proxyTable: {}, 31 | // CSS Sourcemaps off by default because relative paths are "buggy" 32 | // with this option, according to the CSS-Loader README 33 | // (https://github.com/webpack/css-loader#sourcemaps) 34 | // In our experience, they generally work as expected, 35 | // just be aware of this issue when enabling this option. 36 | cssSourceMap: false 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /config/test.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var devEnv = require('./dev.env') 3 | 4 | module.exports = merge(devEnv, { 5 | NODE_ENV: '"testing"' 6 | }) 7 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | vue2-shop 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue2-shop", 3 | "version": "1.0.0", 4 | "description": "This is an experimental Vue Project in order to compare with Angular2 and Ember2, please check out readme. ", 5 | "author": "Majid ", 6 | "private": true, 7 | "scripts": { 8 | "dev": "node build/dev-server.js", 9 | "deploy": "gh-pages -d dist", 10 | "build": "node build/build.js", 11 | "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run", 12 | "e2e": "node test/e2e/runner.js", 13 | "test": "npm run unit && npm run e2e", 14 | "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs" 15 | }, 16 | "dependencies": { 17 | "accounting": "^0.4.1", 18 | "element-ui": "^1.3.3", 19 | "pluralize": "^5.0.0", 20 | "vue": "^2.3.3", 21 | "vue-router": "^2.5.3", 22 | "vuex": "^2.3.1" 23 | }, 24 | "devDependencies": { 25 | "autoprefixer": "^7.1.0", 26 | "babel-core": "^6.24.1", 27 | "babel-eslint": "^7.2.3", 28 | "babel-loader": "^7.0.0", 29 | "babel-plugin-istanbul": "^4.1.3", 30 | "babel-plugin-transform-runtime": "^6.23.0", 31 | "babel-preset-env": "^1.4.0", 32 | "babel-preset-stage-2": "^6.24.1", 33 | "babel-register": "^6.24.1", 34 | "chai": "^3.5.0", 35 | "chalk": "^1.1.3", 36 | "chromedriver": "^2.29.0", 37 | "connect-history-api-fallback": "^1.3.0", 38 | "copy-webpack-plugin": "^4.0.1", 39 | "cross-env": "^5.0.0", 40 | "cross-spawn": "^5.0.1", 41 | "css-loader": "^0.28.1", 42 | "eslint": "^3.19.0", 43 | "eslint-config-airbnb-base": "^11.2.0", 44 | "eslint-friendly-formatter": "^3.0.0", 45 | "eslint-import-resolver-webpack": "^0.8.1", 46 | "eslint-loader": "^1.7.1", 47 | "eslint-plugin-html": "^2.0.3", 48 | "eslint-plugin-import": "^2.2.0", 49 | "eventsource-polyfill": "^0.9.6", 50 | "express": "^4.15.3", 51 | "extract-text-webpack-plugin": "^2.0.0", 52 | "file-loader": "^0.11.1", 53 | "friendly-errors-webpack-plugin": "^1.1.3", 54 | "function-bind": "^1.1.0", 55 | "gh-pages": "^1.0.0", 56 | "html-webpack-plugin": "^2.28.0", 57 | "http-proxy-middleware": "^0.17.3", 58 | "inject-loader": "^3.0.0", 59 | "karma": "^1.7.0", 60 | "karma-coverage": "^1.1.1", 61 | "karma-mocha": "^1.3.0", 62 | "karma-phantomjs-launcher": "^1.0.2", 63 | "karma-sinon-chai": "^1.3.1", 64 | "karma-sourcemap-loader": "^0.3.7", 65 | "karma-spec-reporter": "^0.0.31", 66 | "karma-webpack": "^2.0.3", 67 | "lolex": "^1.5.2", 68 | "mocha": "^3.4.1", 69 | "nightwatch": "^0.9.15", 70 | "opn": "^5.0.0", 71 | "optimize-css-assets-webpack-plugin": "^1.3.1", 72 | "ora": "^1.2.0", 73 | "phantomjs-prebuilt": "^2.1.14", 74 | "rimraf": "^2.6.0", 75 | "selenium-server": "^3.4.0", 76 | "semver": "^5.3.0", 77 | "sinon": "^2.2.0", 78 | "sinon-chai": "^2.10.0", 79 | "url-loader": "^0.5.7", 80 | "vue-loader": "^12.0.4", 81 | "vue-style-loader": "^3.0.1", 82 | "vue-template-compiler": "^2.3.3", 83 | "webpack": "^2.5.1", 84 | "webpack-bundle-analyzer": "^2.8.1", 85 | "webpack-dev-middleware": "^1.10.2", 86 | "webpack-hot-middleware": "^2.18.0", 87 | "webpack-merge": "^4.1.0" 88 | }, 89 | "engines": { 90 | "node": ">= 4.0.0", 91 | "npm": ">= 3.0.0" 92 | }, 93 | "browserslist": [ 94 | "> 1%", 95 | "last 2 versions", 96 | "not ie <= 8" 97 | ] 98 | } 99 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 25 | 26 | 49 | -------------------------------------------------------------------------------- /src/api/fixtures.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | const profile = { 3 | 'firstName': 'Majid', 4 | 'lastName': 'Hajian', 5 | 'limit': 850.00, 6 | }; 7 | 8 | const products = [ 9 | { 'id': 1, 'title': 'iPad 4 Mini', 'price': 500.01, 'inventory': 2, 'shipping': 15.00 }, 10 | { 'id': 2, 'title': 'H&M T-Shirt White', 'price': 10.99, 'inventory': 10, 'shipping': 5.00 }, 11 | { 'id': 3, 'title': 'Nirvana - LP', 'price': 19.99, 'inventory': 3, 'shipping': 22.50 }, 12 | { 'id': 4, 'title': 'Licensed Steel Gloves', 'price': 30.99, 'inventory': 5, 'shipping': 9.00 }, 13 | { 'id': 5, 'title': 'Rustic Granite Car', 'price': 487.00, 'inventory': 1, 'shipping': 35.00 }, 14 | { 'id': 6, 'title': 'Fantastic Cotton Pants', 'price': 59.59, 'inventory': 6, 'shipping': 11.00 }, 15 | { 'id': 7, 'title': 'Tasty Wooden Pizza', 'price': 29.00, 'inventory': 2, 'shipping': 18.00 }, 16 | { 'id': 8, 'title': 'Delicious Concrete Fish', 'price': 12.99, 'inventory': 4, 'shipping': 6.00 }, 17 | { 'id': 9, 'title': 'Granite Computer', 'price': 109.10, 'inventory': 10, 'shipping': 22.70 }, 18 | { 'id': 10, 'title': 'Handcrafted Soft Salad', 'price': 13.99, 'inventory': 3, 'shipping': 3.50 }, 19 | { 'id': 11, 'title': 'Incredible Steel Bacon', 'price': 30.99, 'inventory': 5, 'shipping': 7.90 }, 20 | { 'id': 12, 'title': 'Tasty Plastic Bike', 'price': 75.00, 'inventory': 5, 'shipping': 25.00 }, 21 | ]; 22 | 23 | const promotions = [ 24 | { 'id': 1, 'title': '10% OFF' }, 25 | { 'id': 2, 'title': 'NOK500.00 Discount' }, 26 | { 'id': 3, 'title': 'Free Shipping' }, 27 | { 'id': 4, 'title': '+ NOK600.00 on limit' }, 28 | ]; 29 | 30 | // Simulate requests 31 | export default { 32 | getProfile(cb) { 33 | setTimeout(() => cb(profile), 500); 34 | }, 35 | 36 | getProducts(cb) { 37 | setTimeout(() => cb(products), 500); 38 | }, 39 | 40 | getPromotions(cb) { 41 | setTimeout(() => cb(promotions), 500); 42 | }, 43 | 44 | buyProducts(products, cb) { 45 | setTimeout(() => cb(products), 500); 46 | }, 47 | }; 48 | -------------------------------------------------------------------------------- /src/assets/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mhadaily/vue2-shop/9564f74d770622068d59dbc70f42b2c7f59ed858/src/assets/bg.jpg -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mhadaily/vue2-shop/9564f74d770622068d59dbc70f42b2c7f59ed858/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/Hello.vue: -------------------------------------------------------------------------------- 1 | 25 | 26 | 41 | 42 | 43 | 69 | -------------------------------------------------------------------------------- /src/components/contact/Email.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | -------------------------------------------------------------------------------- /src/components/contact/Gmap.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | -------------------------------------------------------------------------------- /src/components/contact/Index.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 31 | -------------------------------------------------------------------------------- /src/components/contact/Phone.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | -------------------------------------------------------------------------------- /src/components/homepage/Slideshow.vue: -------------------------------------------------------------------------------- 1 | 8 | 18 | 19 | 36 | -------------------------------------------------------------------------------- /src/components/shared/Footer.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 24 | 25 | 40 | -------------------------------------------------------------------------------- /src/components/shared/Navbar.vue: -------------------------------------------------------------------------------- 1 | 48 | 49 | 66 | 80 | -------------------------------------------------------------------------------- /src/components/shop/Shop.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 32 | 44 | -------------------------------------------------------------------------------- /src/components/shop/cart/Cart.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 40 | -------------------------------------------------------------------------------- /src/components/shop/cart/Checkout.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | 53 | -------------------------------------------------------------------------------- /src/components/shop/cart/Items.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 29 | 34 | -------------------------------------------------------------------------------- /src/components/shop/cart/Summery.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 51 | 52 | 57 | -------------------------------------------------------------------------------- /src/components/shop/cart/Thanks.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 20 | -------------------------------------------------------------------------------- /src/components/shop/products/AddToCart.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 21 | -------------------------------------------------------------------------------- /src/components/shop/products/List.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 24 | -------------------------------------------------------------------------------- /src/components/shop/products/RemoveFromCart.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 17 | -------------------------------------------------------------------------------- /src/components/shop/products/Single.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 33 | 34 | 44 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue'; 4 | import ElementUI from 'element-ui'; 5 | import 'element-ui/lib/theme-default/index.css'; 6 | import accounting from 'accounting'; 7 | import pluralize from 'pluralize'; 8 | 9 | import store from './store'; 10 | import App from './App'; 11 | import router from './router'; 12 | 13 | Vue.use(ElementUI); 14 | Vue.filter('pluralize', pluralize); 15 | Vue.filter('formatMoney', accounting.formatMoney); 16 | 17 | Vue.config.productionTip = false; 18 | 19 | /* eslint-disable no-new */ 20 | new Vue({ 21 | el: '#app', 22 | router, 23 | store, 24 | template: '', 25 | components: { App }, 26 | }); 27 | -------------------------------------------------------------------------------- /src/pipes/Currency.js: -------------------------------------------------------------------------------- 1 | //TODO 2 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import Vue from 'vue'; 3 | import Router from 'vue-router'; 4 | 5 | import Hello from '@/components/Hello'; 6 | 7 | import Thanks from '@/components/shop/cart/Thanks'; 8 | import Checkout from '@/components/shop/cart/Checkout'; 9 | import Cart from '@/components/shop/cart/Cart'; 10 | 11 | import Email from '@/components/contact/Email'; 12 | import Phone from '@/components/contact/Phone'; 13 | import Gmap from '@/components/contact/Gmap'; 14 | 15 | Vue.use(Router); 16 | 17 | export default new Router({ 18 | routes: [ 19 | { 20 | path: '/', 21 | name: 'Hello', 22 | component: Hello, 23 | }, 24 | { 25 | path: '/products', 26 | name: 'Shop', 27 | component: resolve => require(['./../components/shop/Shop.vue'], resolve), 28 | }, 29 | { 30 | path: '/cart', 31 | name: 'Cart', 32 | component: Cart, 33 | }, 34 | { 35 | path: '/checkout', 36 | name: 'Checkout', 37 | component: Checkout, 38 | }, 39 | { 40 | path: '/thanks', 41 | name: 'Thanks', 42 | component: Thanks, 43 | }, 44 | { 45 | path: '/contact', 46 | component: resolve => require(['./../components/contact/Index.vue'], resolve), 47 | children: [ 48 | { 49 | path: '', 50 | component: Email, 51 | }, 52 | { 53 | path: 'phone', 54 | component: Phone, 55 | }, 56 | { 57 | path: 'gmap', 58 | component: Gmap, 59 | }, 60 | ], 61 | }, 62 | 63 | ], 64 | }); 65 | -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Vuex from 'vuex'; 3 | import * as actions from './shop/actions'; 4 | import * as getters from './shop/getters'; 5 | import products from './shop/modules/products'; 6 | import profile from './shop/modules/profile'; 7 | import promotions from './shop/modules/promotions'; 8 | import cart from './shop/modules/cart'; 9 | 10 | Vue.use(Vuex); 11 | 12 | const debug = process.env.NODE_ENV !== 'production'; 13 | 14 | 15 | export default new Vuex.Store({ 16 | actions, 17 | getters, 18 | modules: { 19 | products, 20 | profile, 21 | promotions, 22 | cart, 23 | }, 24 | strict: debug, 25 | }); 26 | -------------------------------------------------------------------------------- /src/store/shop/actions.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import * as types from './mutation-constant' 3 | 4 | export const addToCart = ({commit}, product) => { 5 | if (product.inventory > 0) { 6 | commit(types.ADD_TO_CART, product.id) 7 | } 8 | }; 9 | 10 | export const removeFromCart = ({commit}, product) => { 11 | commit(types.REMOVE_FROM_CART, product) 12 | }; 13 | 14 | export const toggleCoupon = ({commit}, coupon) => { 15 | commit(types.TOGGLE_COUPON, coupon); 16 | }; 17 | -------------------------------------------------------------------------------- /src/store/shop/getters.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 3 | export const cartProducts = state => { 4 | return state.cart.added.map(({ id, quantity }) => { 5 | const product = 6 | state 7 | .products.all 8 | .find(product => product.id === id); 9 | 10 | return { 11 | ...product, 12 | quantity 13 | } 14 | }) 15 | }; 16 | 17 | export const itemsQuantity = state => { 18 | return cartProducts(state).reduce((quantity, item) => { 19 | return quantity + item.quantity 20 | }, 0) 21 | }; 22 | 23 | export const subtotal = state => { 24 | const sum = cartProducts(state).reduce((subtotal, item) => { 25 | return subtotal + item.price * item.quantity 26 | }, 0); 27 | 28 | return state.cart.productDiscount ? sum * 0.7 : sum 29 | }; 30 | 31 | export const taxes = state => subtotal(state) * 0.005; 32 | 33 | export const shipping = state => { 34 | const shipping = cartProducts(state).map(item => item.shipping); 35 | 36 | if (state.cart.freeShipping || !shipping.length) { 37 | return 0 38 | } else { 39 | return Math.max(...shipping); 40 | } 41 | }; 42 | 43 | export const total = state => { 44 | const discount = state.cart.totalDiscount ? -100 : 0; 45 | return subtotal(state) + taxes(state) + shipping(state) + discount; 46 | }; 47 | 48 | export const orderOnLimit = state => state.profile.data.limit <= total(state); 49 | -------------------------------------------------------------------------------- /src/store/shop/modules/cart.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import api from './../../../api/fixtures'; 3 | import * as types from './../mutation-constant'; 4 | 5 | // initial state 6 | const state = { 7 | added: [], 8 | checkoutStatus: null, 9 | productDiscount: false, 10 | totalDiscount: false, 11 | freeShipping: false, 12 | }; 13 | 14 | // getters 15 | const getters = { 16 | checkoutStatus: state => state.checkoutStatus, 17 | }; 18 | 19 | // actions 20 | const actions = { 21 | checkout ({ commit, state }, products) { 22 | const savedCartItems = [...state.added]; 23 | commit(types.CHECKOUT_REQUEST); 24 | api.buyProducts( 25 | products, 26 | () => commit(types.CHECKOUT_SUCCESS), 27 | () => commit(types.CHECKOUT_FAILURE, { savedCartItems }), 28 | ); 29 | }, 30 | }; 31 | 32 | // mutations 33 | const mutations = { 34 | [types.ADD_TO_CART] (state, id) { 35 | state.lastCheckout = null; 36 | const record = state.added.find(p => p.id === id); 37 | if (!record) { 38 | state.added.push({ 39 | id, 40 | quantity: 1, 41 | }); 42 | } else { 43 | record.quantity++; 44 | } 45 | }, 46 | 47 | [types.REMOVE_FROM_CART] (state, item) { 48 | const index = state.added.findIndex(added => added.id === item.id); 49 | state.added.splice(index, 1); 50 | }, 51 | 52 | [types.TOGGLE_COUPON] (state, coupon) { 53 | const coupons = { 54 | '1': 'productDiscount', 55 | '2': 'totalDiscount', 56 | '3': 'freeShipping', 57 | }; 58 | 59 | if (coupons[coupon.id]) { 60 | state[coupons[coupon.id]] = !state[coupons[coupon.id]]; 61 | } 62 | }, 63 | 64 | [types.CHECKOUT_REQUEST] (state) { 65 | // clear cart 66 | state.added = []; 67 | state.checkoutStatus = null; 68 | }, 69 | 70 | [types.CHECKOUT_SUCCESS] (state) { 71 | state.checkoutStatus = 'successful'; 72 | }, 73 | 74 | [types.CHECKOUT_FAILURE] (state, { savedCartItems }) { 75 | // rollback to the cart saved before sending the request 76 | state.added = savedCartItems; 77 | state.checkoutStatus = 'failed'; 78 | }, 79 | }; 80 | 81 | export default { 82 | state, 83 | getters, 84 | actions, 85 | mutations, 86 | }; 87 | -------------------------------------------------------------------------------- /src/store/shop/modules/products.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import api from './../../../api/fixtures'; 3 | import * as types from './../mutation-constant'; 4 | 5 | // initial state 6 | const state = { 7 | all: [] 8 | }; 9 | 10 | // getters 11 | const getters = { 12 | allProducts: state => state.all 13 | }; 14 | 15 | // actions 16 | const actions = { 17 | getAllProducts({ commit }) { 18 | api.getProducts(products => { 19 | commit(types.RECEIVE_PRODUCTS, { products }) 20 | }) 21 | }, 22 | }; 23 | 24 | // mutations 25 | const mutations = { 26 | [types.RECEIVE_PRODUCTS] (state, { products }) { 27 | state.all = products 28 | }, 29 | [types.ADD_TO_CART] (state, id ) { 30 | state.all.find(p => p.id === id).inventory--; 31 | }, 32 | [types.REMOVE_FROM_CART] (state, removedProduct) { 33 | state.all 34 | .find(product => product.id === removedProduct.id) 35 | .inventory += removedProduct.quantity 36 | } 37 | }; 38 | 39 | export default { 40 | state, 41 | getters, 42 | actions, 43 | mutations 44 | } 45 | -------------------------------------------------------------------------------- /src/store/shop/modules/profile.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import api from './../../../api/fixtures'; 3 | import * as types from './../mutation-constant'; 4 | 5 | // initial state 6 | const state = { 7 | data: [] 8 | }; 9 | 10 | // getters 11 | const getters = { 12 | profile: state => state.data 13 | }; 14 | 15 | // actions 16 | const actions = { 17 | getProfile({commit}){ 18 | api.getProfile(profile => { 19 | commit(types.RECEIVE_PROFILE, profile) 20 | }) 21 | }, 22 | }; 23 | 24 | const mutations = { 25 | [types.RECEIVE_PROFILE] (state, profile) { 26 | state.data = profile 27 | }, 28 | 29 | [types.TOGGLE_COUPON] (state, coupon) { 30 | const couponLimitId = 4; 31 | 32 | if (coupon.id !== couponLimitId) return; 33 | 34 | if (!coupon.active) { 35 | state.data.limit += 100 36 | } else { 37 | state.data.limit -= 100 38 | } 39 | } 40 | }; 41 | 42 | export default { 43 | state, 44 | mutations, 45 | actions, 46 | getters, 47 | } 48 | -------------------------------------------------------------------------------- /src/store/shop/modules/promotions.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | import api from './../../../api/fixtures'; 3 | import * as types from './../mutation-constant'; 4 | 5 | const state = { 6 | all: [] 7 | }; 8 | 9 | // getters 10 | const getters = { 11 | allPromotions: state => state.all 12 | }; 13 | 14 | // actions 15 | const actions = { 16 | getAllPromotions({commit}){ 17 | api.getPromotions(promotions => { 18 | commit(types.RECEIVE_PROMOTIONS, promotions) 19 | }) 20 | }, 21 | }; 22 | 23 | const mutations = { 24 | [types.RECEIVE_PROMOTIONS] (state, promotions) { 25 | state.all = promotions 26 | }, 27 | 28 | [types.TOGGLE_COUPON] (state, coupon) { 29 | coupon.active = !coupon.active 30 | } 31 | }; 32 | 33 | export default { 34 | state, 35 | mutations, 36 | getters, 37 | actions, 38 | } 39 | -------------------------------------------------------------------------------- /src/store/shop/mutation-constant.js: -------------------------------------------------------------------------------- 1 | export const ADD_TO_CART = 'ADD_TO_CART'; 2 | export const REMOVE_FROM_CART = 'REMOVE_FROM_CART'; 3 | export const CHECKOUT_REQUEST = 'CHECKOUT_REQUEST'; 4 | export const CHECKOUT_SUCCESS = 'CHECKOUT_SUCCESS'; 5 | export const CHECKOUT_FAILURE = 'CHECKOUT_FAILURE'; 6 | export const RECEIVE_PRODUCTS = 'RECEIVE_PRODUCTS'; 7 | export const TOGGLE_COUPON = 'TOGGLE_COUPON'; 8 | export const RECEIVE_PROFILE = 'RECEIVE_PROFILE'; 9 | export const RECEIVE_PROMOTIONS = 'RECEIVE_PROMOTIONS'; 10 | -------------------------------------------------------------------------------- /static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mhadaily/vue2-shop/9564f74d770622068d59dbc70f42b2c7f59ed858/static/.gitkeep -------------------------------------------------------------------------------- /test/e2e/custom-assertions/elementCount.js: -------------------------------------------------------------------------------- 1 | // A custom Nightwatch assertion. 2 | // the name of the method is the filename. 3 | // can be used in tests like this: 4 | // 5 | // browser.assert.elementCount(selector, count) 6 | // 7 | // for how to write custom assertions see 8 | // http://nightwatchjs.org/guide#writing-custom-assertions 9 | exports.assertion = function (selector, count) { 10 | this.message = 'Testing if element <' + selector + '> has count: ' + count; 11 | this.expected = count; 12 | this.pass = function (val) { 13 | return val === this.expected; 14 | } 15 | this.value = function (res) { 16 | return res.value; 17 | } 18 | this.command = function (cb) { 19 | var self = this; 20 | return this.api.execute(function (selector) { 21 | return document.querySelectorAll(selector).length; 22 | }, [selector], function (res) { 23 | cb.call(self, res); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/e2e/nightwatch.conf.js: -------------------------------------------------------------------------------- 1 | require('babel-register') 2 | var config = require('../../config') 3 | 4 | // http://nightwatchjs.org/getingstarted#settings-file 5 | module.exports = { 6 | src_folders: ['test/e2e/specs'], 7 | output_folder: 'test/e2e/reports', 8 | custom_assertions_path: ['test/e2e/custom-assertions'], 9 | 10 | selenium: { 11 | start_process: true, 12 | server_path: require('selenium-server').path, 13 | host: '127.0.0.1', 14 | port: 4444, 15 | cli_args: { 16 | 'webdriver.chrome.driver': require('chromedriver').path 17 | } 18 | }, 19 | 20 | test_settings: { 21 | default: { 22 | selenium_port: 4444, 23 | selenium_host: 'localhost', 24 | silent: true, 25 | globals: { 26 | devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port) 27 | } 28 | }, 29 | 30 | chrome: { 31 | desiredCapabilities: { 32 | browserName: 'chrome', 33 | javascriptEnabled: true, 34 | acceptSslCerts: true 35 | } 36 | }, 37 | 38 | firefox: { 39 | desiredCapabilities: { 40 | browserName: 'firefox', 41 | javascriptEnabled: true, 42 | acceptSslCerts: true 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/e2e/runner.js: -------------------------------------------------------------------------------- 1 | // 1. start the dev server using production config 2 | process.env.NODE_ENV = 'testing'; 3 | var server = require('../../build/dev-server.js'); 4 | 5 | // 2. run the nightwatch test suite against it 6 | // to run in additional browsers: 7 | // 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings" 8 | // 2. add it to the --env flag below 9 | // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox` 10 | // For more information on Nightwatch's config file, see 11 | // http://nightwatchjs.org/guide#settings-file 12 | var opts = process.argv.slice(2); 13 | if (opts.indexOf('--config') === -1) { 14 | opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']); 15 | } 16 | if (opts.indexOf('--env') === -1) { 17 | opts = opts.concat(['--env', 'chrome']); 18 | } 19 | 20 | var spawn = require('cross-spawn'); 21 | var runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' }); 22 | 23 | runner.on('exit', function (code) { 24 | server.close(); 25 | process.exit(code); 26 | }); 27 | 28 | runner.on('error', function (err) { 29 | server.close(); 30 | throw err; 31 | }); 32 | -------------------------------------------------------------------------------- /test/e2e/specs/test.js: -------------------------------------------------------------------------------- 1 | // For authoring Nightwatch tests, see 2 | // http://nightwatchjs.org/guide#usage 3 | 4 | module.exports = { 5 | 'default e2e tests': function test(browser) { 6 | // automatically uses dev Server port from /config.index.js 7 | // default: http://localhost:8080 8 | // see nightwatch.conf.js 9 | const devServer = browser.globals.devServerURL; 10 | 11 | browser 12 | .url(devServer) 13 | .waitForElementVisible('#app', 5000) 14 | .assert.elementPresent('.hello') 15 | .assert.containsText('h1', 'Welcome to Your Vue.js App') 16 | .assert.elementCount('img', 1) 17 | .end(); 18 | }, 19 | }; 20 | -------------------------------------------------------------------------------- /test/unit/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true 4 | }, 5 | "globals": { 6 | "expect": true, 7 | "sinon": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/unit/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | Vue.config.productionTip = false; 3 | 4 | // Polyfill fn.bind() for PhantomJS 5 | /* eslint-disable no-extend-native */ 6 | Function.prototype.bind = require('function-bind'); 7 | 8 | // require all test files (files that ends with .spec.js) 9 | const testsContext = require.context('./specs', true, /\.spec$/); 10 | testsContext.keys().forEach(testsContext); 11 | 12 | // require all src files except main.js for coverage. 13 | // you can also change this to match only the subset of files that 14 | // you want coverage for. 15 | const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/); 16 | srcContext.keys().forEach(srcContext); 17 | -------------------------------------------------------------------------------- /test/unit/karma.conf.js: -------------------------------------------------------------------------------- 1 | // This is a karma config file. For more details see 2 | // http://karma-runner.github.io/0.13/config/configuration-file.html 3 | // we are also using it with karma-webpack 4 | // https://github.com/webpack/karma-webpack 5 | 6 | var webpackConfig = require('../../build/webpack.test.conf'); 7 | 8 | module.exports = function (config) { 9 | config.set({ 10 | // to run in additional browsers: 11 | // 1. install corresponding karma launcher 12 | // http://karma-runner.github.io/0.13/config/browsers.html 13 | // 2. add it to the `browsers` array below. 14 | browsers: ['PhantomJS'], 15 | frameworks: ['mocha', 'sinon-chai'], 16 | reporters: ['spec', 'coverage'], 17 | files: ['./index.js'], 18 | preprocessors: { 19 | './index.js': ['webpack', 'sourcemap'] 20 | }, 21 | webpack: webpackConfig, 22 | webpackMiddleware: { 23 | noInfo: true, 24 | }, 25 | coverageReporter: { 26 | dir: './coverage', 27 | reporters: [ 28 | { type: 'lcov', subdir: '.' }, 29 | { type: 'text-summary' }, 30 | ] 31 | }, 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /test/unit/specs/Hello.spec.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Hello from '@/components/Hello'; 3 | 4 | describe('Hello.vue', () => { 5 | it('should render correct contents', () => { 6 | const Constructor = Vue.extend(Hello); 7 | const vm = new Constructor().$mount(); 8 | expect(vm.$el.querySelector('.hello h1').textContent) 9 | .to.equal('Welcome to Your Vue.js App'); 10 | }); 11 | }); 12 | --------------------------------------------------------------------------------