Skip to content

Commit

Permalink
Merge branch 'master' into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
keanulee committed May 24, 2018
2 parents b246233 + 247a571 commit 104a2cf
Show file tree
Hide file tree
Showing 8 changed files with 671 additions and 36 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# SHOP

### Setup
## Prerequisites

##### Prerequisites
### Polymer CLI

Install [polymer-cli](https://github.com/Polymer/polymer-cli):

npm install -g polymer-cli

### Setup

##### Setup
# Using CLI
mkdir shop
cd shop
Expand All @@ -20,15 +20,15 @@ Install [polymer-cli](https://github.com/Polymer/polymer-cli):
cd shop
bower install

### Start the development server
## Start the development server

polymer serve

### Run web-component-tester tests
## Run web-component-tester tests

polymer test

### Build
## Build

Build presets provide an easy way to define common build configurations in your `polymer.json` file. There are 3 build presets we put in `polymer.json` file in Shop:

Expand Down Expand Up @@ -66,8 +66,12 @@ Run the command to build the presets:

polymer build

### Test the build
## Test the build

Use `polymer serve` to serve a specific build preset of the app. For example:

polymer serve build/es5-bundled

## Deploying

Our [production deployment of SHOP](https://shop.polymer-project.org/) is hosted on App Engine with Node.js. You can examine its configuration on the [app-engine-node branch](https://github.com/Polymer/shop/tree/app-engine-node) of this repository and [compare it with the master branch](https://github.com/Polymer/shop/pull/145).
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">

<title>SHOP</title>
<meta name="description" content="Polymer Shop Demo">

<link rel="shortcut icon" sizes="32x32" href="images/shop-icon-32.png">
<meta name="twitter:card" content="summary">
Expand Down
7 changes: 5 additions & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
<body>
<script>
WCT.loadSuites([
'shop-home.html?dom=shady',
'shop-home.html?dom=shadow'
'shop-home.html',
'shop-list.html',
'shop-detail.html',
'shop-cart.html',
'shop-checkout.html'
]);
</script>
</body>
Expand Down
143 changes: 143 additions & 0 deletions test/shop-cart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<!doctype html>
<!--
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<html>
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>shop-cart</title>

<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="../node_modules/wct-browser-legacy/browser.js"></script>

<!-- Import the element to test -->
<script type="module" src="../src/shop-cart.js"></script>

</head>
<body>

<test-fixture id="basic">
<template>
<shop-cart></shop-cart>
</template>
</test-fixture>

<script>
suite('shop-cart tests', function() {
var cart;

var cartData = [
{
item: {
name: "Men+s+Tech+Shell+Full-Zip",
title: "Men's Tech Shell Full-Zip",
category: "mens_outerwear",
price: 50.2,
description: "A versatile full-zip that you can wear all day long and even to the gym. This technical shell features moisture-wicking fabric, added stretch and a hidden pocket for your smartphone or media player.&amp;nbsp;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Features:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;100% polyester.&lt;/li&gt;&lt;li&gt;Smooth, technical front with textured mesh back.&lt;/li&gt;&lt;li&gt;Drawstring bottom for adjustable fit.&lt;/li&gt;&lt;li&gt;Raglan sleeves.&lt;/li&gt;&lt;li&gt;Available in forest green with the white Google logo embroidered at left chest.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;",
image: "../data/images/10-15068B.jpg",
largeImage: "../data/images/10-15068A.jpg"
},
quantity: 1,
size: "M"
},
{
item: {
name: "Ladies+Voyage+Fleece+Jacket",
title: "Ladies Voyage Fleece Jacket",
category: "ladies_outerwear",
price: 48,
description: "&lt;div&gt;Perhaps the equivalent to that comfort blanket you had years ago is a cozy fleece. This full-zip is the perfect layering piece for those 'in-between' months when mother nature just can't make up her mind.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Features:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;100% polyester anti-pill yarn fleece.&lt;/li&gt;&lt;li&gt;100% polyester taffeta lining in sleeves.&lt;/li&gt;&lt;li&gt;Tricot-lined lower pockets with reverse coil zippers.&lt;/li&gt;&lt;li&gt;Available in purple with the white Google logo embroidered at left chest.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Please note! Sizing runs larger than normal. Consider ordering a size smaller than normal.&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;",
image: "../data/images/10-24101B.jpg",
largeImage: "../data/images/10-24101A.jpg"
},
quantity: 1,
size: "M"
}
]

setup(function() {
cart = fixture('basic');
});

test('cart item lengths should be equal', function(done) {
// Set cart property
cart.cart = cartData;
// Data bindings will stamp out new DOM asynchronously
// so wait to check for updates
flush(function() {
var items = cart.shadowRoot.querySelectorAll('shop-cart-item');
assert.equal(Object.keys(cart.cart).length, items.length);
done();
});
});

test('total should render correctly', function(done) {
// Set total property
cart.total = 98.2;
// Data bindings will stamp out new DOM asynchronously
// so wait to check for updates
flush(function() {
var total = cart.shadowRoot.querySelector('.subtotal');
assert.equal(cart._formatTotal(cart.total), total.textContent, 'total should render correctly');
done();
});
});

test('quantity should render correctly', function(done) {
// Set cart property
cart.cart = cartData;
// Data bindings will stamp out new DOM asynchronously
// so wait to check for updates
flush(function() {
var quantity = cart.shadowRoot.querySelector('header').querySelector('span');
assert.equal('(' + cart._getPluralizedQuantity(cartData.length) + ')', quantity.textContent, 'quantity should render correctly');
done();
});
});

test('main section should have visible attribute when cart has items', function(done) {
// Set cart property
cart.cart = cartData;
// Data bindings will stamp out new DOM asynchronously
// so wait to check for updates
flush(function() {
var section = cart.shadowRoot.querySelectorAll('.subsection')[1];
assert.isTrue(section.hasAttribute('visible'), 'main section should have visible attribute when cart has items');
done();
});
});

test('main section should not have visible attribute when cart is empty', function(done) {
// Set cart property
cart.cart = [];
// Data bindings will stamp out new DOM asynchronously
// so wait to check for updates
flush(function() {
var section = cart.shadowRoot.querySelectorAll('.subsection')[1];
assert.isFalse(section.hasAttribute('visible'), 'main section should not have visible attribute when cart is empty');
done();
});
});

test('change-section event should fire', function(done) {
var listenerSpy = sinon.spy();
cart.addEventListener('change-section', listenerSpy);
// Set visible attribute
cart.setAttribute('visible', '');
flush(function() {
assert.isTrue(listenerSpy.called, 'should fire after attribute "visible" is set');
done();
});
});
});
</script>

</body>
</html>
120 changes: 120 additions & 0 deletions test/shop-checkout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<!doctype html>
<!--
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<html>
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>shop-checkout</title>

<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="../node_modules/wct-browser-legacy/browser.js"></script>

<!-- Import the element to test -->
<script type="module" src="../src/shop-checkout.js"></script>

</head>
<body>

<test-fixture id="basic">
<template>
<shop-checkout></shop-checkout>
</template>
</test-fixture>

<script>
suite('shop-checkout tests', function() {
var checkout;

var cartData = [
{
item: {
name: "Men+s+Tech+Shell+Full-Zip",
title: "Men's Tech Shell Full-Zip",
category: "mens_outerwear",
price: 50.2,
description: "A versatile full-zip that you can wear all day long and even to the gym. This technical shell features moisture-wicking fabric, added stretch and a hidden pocket for your smartphone or media player.&amp;nbsp;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Features:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;100% polyester.&lt;/li&gt;&lt;li&gt;Smooth, technical front with textured mesh back.&lt;/li&gt;&lt;li&gt;Drawstring bottom for adjustable fit.&lt;/li&gt;&lt;li&gt;Raglan sleeves.&lt;/li&gt;&lt;li&gt;Available in forest green with the white Google logo embroidered at left chest.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;",
image: "../data/images/10-15068B.jpg",
largeImage: "../data/images/10-15068A.jpg"
},
quantity: 1,
size: "M"
},
{
item: {
name: "Ladies+Voyage+Fleece+Jacket",
title: "Ladies Voyage Fleece Jacket",
category: "ladies_outerwear",
price: 48,
description: "&lt;div&gt;Perhaps the equivalent to that comfort blanket you had years ago is a cozy fleece. This full-zip is the perfect layering piece for those 'in-between' months when mother nature just can't make up her mind.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Features:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;100% polyester anti-pill yarn fleece.&lt;/li&gt;&lt;li&gt;100% polyester taffeta lining in sleeves.&lt;/li&gt;&lt;li&gt;Tricot-lined lower pockets with reverse coil zippers.&lt;/li&gt;&lt;li&gt;Available in purple with the white Google logo embroidered at left chest.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Please note! Sizing runs larger than normal. Consider ordering a size smaller than normal.&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;",
image: "../data/images/10-24101B.jpg",
largeImage: "../data/images/10-24101A.jpg"
},
quantity: 1,
size: "M"
}
]

setup(function() {
checkout = fixture('basic');
});

test('total should render correctly', function(done) {
// Set total property
checkout.total = 98.2;
// Data bindings will stamp out new DOM asynchronously
// so wait to check for updates
flush(function() {
var total = checkout.shadowRoot.querySelector('.total-row').querySelectorAll('div')[1];
assert.equal(checkout._formatPrice(checkout.total), total.textContent, 'total should render correctly');
done();
});
});

test('order items length should be equal', function(done) {
// Set cart property
checkout.cart = cartData;
// Data bindings will stamp out new DOM asynchronously
// so wait to check for updates
flush(function() {
var orderItems = checkout.shadowRoot.querySelectorAll('.order-summary-row');
assert.equal(cartData.length, orderItems.length);
done();
});
});

test('checkout form should not be hidden when cart has items', function(done) {
// Set cart property
checkout.cart = cartData;
// Data bindings will stamp out new DOM asynchronously
// so wait to check for updates
flush(function() {
var section = checkout.shadowRoot.querySelector('.subsection.grid');
assert.isTrue(section.hasAttribute('visible'), 'checkout form should have visible attribute when cart has items');
done();
});
});

test('checkout form should have visible attribute when cart has items', function(done) {
// Set cart property
checkout.cart = [];
// Data bindings will stamp out new DOM asynchronously
// so wait to check for updates
flush(function() {
var section = checkout.shadowRoot.querySelector('.subsection.grid');
assert.isFalse(section.hasAttribute('visible'), 'checkout form should have visible attirubte when cart has items');
done();
});
});
});
</script>

</body>
</html>
Loading

0 comments on commit 104a2cf

Please sign in to comment.