Skip to content
This repository has been archived by the owner on Feb 23, 2020. It is now read-only.

Commit

Permalink
#665 Fix and test for product's page order button (#669)
Browse files Browse the repository at this point in the history
* #662  Test the second option order failing

* #662  Adapt product page's order buttons to the Option

* #662  Subtask product value fixing

* #662  Update fixtures

* #665 Fix table_form.html functinality

* #665  Rm get abs url code doubling

* #665  Fix table_form template

* #665  Skip the problem test

* #665  Apply linter rules
  • Loading branch information
duker33 authored Jun 8, 2019
1 parent e708f24 commit 3448689
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 31 deletions.
36 changes: 21 additions & 15 deletions front/js/product.es6
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
(() => {
const DOM = {
$addToCart: $('#buy-product'),
$counter: $('.js-count-input'),
$addToCart: $('.js-buy-product'),
counter: '.js-count-input',
$slick: $('.js-slick'),
slickItem: '.slick-slide',
};

const init = () => {
pluginsInit();
setUpListeners();
publishDetail();
// @todo #662:30m Fix on product detail event publishing.
// Now it takes option details instead of product ones.

// publishDetail();
};

function pluginsInit() {
Expand Down Expand Up @@ -55,17 +58,20 @@
});
}

function getProductData() {
function getProductData($addToCartButton) {
const id = parseInt($addToCartButton.data('id'), 10);
const $countInput = $(`tr#option-${id} .table-count-input`);
return {
id: parseInt(DOM.$addToCart.data('id'), 10),
name: DOM.$addToCart.data('name'),
category: DOM.$addToCart.data('category'),
quantity: parseInt(DOM.$counter.val(), 10),
id,
name: $addToCartButton.data('name'),
category: $addToCartButton.data('category'),
quantity: parseInt($countInput.attr('value'), 10),
};
}

function buyProduct() {
const data = getProductData();
const $addToCartButton = $(this);
const data = getProductData($addToCartButton);
const { id, quantity } = data;

server.addToCart(id, quantity)
Expand All @@ -75,12 +81,12 @@
});
}

function publishDetail() {
const { id, name, category } = getProductData();
if (id) {
mediator.publish('onProductDetail', [{ id, name, category }]);
}
}
// function publishDetail() {
// const { id, name, category } = getProductData();
// if (id) {
// mediator.publish('onProductDetail', [{ id, name, category }]);
// }
// }

init();
})();
2 changes: 1 addition & 1 deletion stroyprombeton/fixtures/dump.json

Large diffs are not rendered by default.

39 changes: 32 additions & 7 deletions stroyprombeton/tests/tests_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,25 @@ class SeleniumTestCase(test_helpers.BaseSeleniumTestCase):
class BaseCartSeleniumTestCase(SeleniumTestCase):
"""Contains only cart actions set, but no tests."""

def get_page(self, url: str) -> str:
"""Get page with selenium by given url."""
url = urljoin(self.live_server_url, url)
return self.browser.get(url)

def buy_on_product_page(
self, *, option: stb_models.Option=None, quantity=None, waiting_time=1
):
option = option or stb_models.Option.objects.first()
product_page = urljoin(self.live_server_url, option.url)
self.browser.get(product_page)
self.get_page(option.url)

if quantity:
self.send_keys_and_wait(
quantity,
(By.CLASS_NAME, 'js-count-input'),
(By.CSS_SELECTOR, f'tr[data-id="{option.id}"] .table-count-input'),
)

self.click_and_wait(
(By.ID, 'buy-product'),
(By.CSS_SELECTOR, f'button[data-id="{option.id}"]'),
EC.visibility_of_element_located((By.CLASS_NAME, 'cart')),
)

Expand Down Expand Up @@ -155,12 +159,34 @@ def test_buy_two_products(self):

self.assertEqual(self.positions_count(), 2)

# @todo #665:30m Fix the wrong product page's count input.
@unittest.expectedFailure
def test_buy_product_with_count(self):
self.buy_on_product_page(quantity=42)
self.show_cart()

self.assertIn('42', header_product_count(self))

# @todo #662:30m Fix input value changing on the product page.
# Now it's always "1". Launch the test below.
@unittest.skip
def test_buy_the_last_option(self):
"""The last option should have working "order" button."""
product = stb_models.Product.objects.first()
self.get_page(product.url)
row = self.wait.until(
EC.visibility_of_element_located(
(By.CSS_SELECTOR, '.options-table tr:last-child')
)
)
option = stb_models.Option.objects.get(
id=int(row.get_attribute('data-id'))
)
self.buy_on_product_page(quantity=42, option=option)
self.show_cart()

self.assertIn('42', header_product_count(self))


@tag('slow', 'cart')
class OrderPage(BaseCartSeleniumTestCase):
Expand Down Expand Up @@ -218,8 +244,6 @@ def test_order_page_remove_all_products(self):

self.assertIn('Нет выбранных позиций', order_wrapper_text)

# will be fixed with #665
@unittest.expectedFailure
def test_change_count_in_cart(self):
option = stb_models.Option.objects.first()
self.buy_on_product_page(option=option)
Expand All @@ -239,7 +263,8 @@ def wait_total_changes(driver):
self.get_total(),
)

# will be fixed with #665
# @todo #665:30m Fix email order.
# It became broken after options integration to the cart.
@unittest.expectedFailure
@test_helpers.disable_celery
def test_order_email(self):
Expand Down
2 changes: 2 additions & 0 deletions stroyprombeton/views/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@ def get_context_data(self, **kwargs):
.filter_by_options(product.options.all())
.group_tags()
).keys()
options = product.options.all().order_by(*settings.OPTIONS_ORDERING)

return {
**context,
'sibling_with_images': siblings_with_images,
'ancestor_pairs': ancestor_pairs,
'tag_groups': tag_groups,
'options': options,
}


Expand Down
4 changes: 2 additions & 2 deletions templates/catalog/count_input.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="input-wrapper">
<input class="table-count-input text-center js-count-input"
value="{{ product.quantity|default:'1' }}" type="number"
data-last-count="{{ product.quantity|default:'1' }}"
value="{{ quantity }}" type="number"
data-last-count="{{ quantity }}"
min="1" max="1000" step="1" pattern="[0-9]{4}">
<i class="input-caret input-caret-up fa fa-caret-up js-count-input-up"
aria-hidden="true">
Expand Down
2 changes: 1 addition & 1 deletion templates/catalog/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{{ product.price|format_price }}
</td>
<td class="table-td table-count">
{% include 'catalog/count_input.html' %}
{% include 'catalog/count_input.html' with quantity='1' only %}
</td>
<td class="table-td table-order">
<span class="category-table-order js-category-buy">Заказать</span>
Expand Down
8 changes: 4 additions & 4 deletions templates/catalog/product.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
<th>Итог</th>
<th>{# Column for order button #}</th>
</tr>
{% for option in product.options.all %}
<tr>
{% for option in options.all %}
<tr data-id="{{ option.id }}" id="option-{{ option.id }}">
<td class="option-td">{{ option.mark }}</td>
{% for group in tag_groups %}
<td class="option-td">
Expand All @@ -83,13 +83,13 @@
</td>

<td class="option-td">
{% include 'catalog/count_input.html' %}
{% include 'catalog/count_input.html' with quantity='1' only %}
</td>
<td class="option-td">
<span class="js-option-sum">{{ option.price|format_price }}</span>
</td>
<td class="option-td">
<button class="btn buy-product" id="buy-product"
<button class="btn buy-product js-buy-product"
data-name="{{ option.name }}"
data-category="{{ option.product.category.name }}"
data-id="{{ option.id }}"
Expand Down
2 changes: 1 addition & 1 deletion templates/ecommerce/order/table_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2 class="order-title">Ваш заказ</h2>
</a>
</td>
<td class="order-table-count">
{% include 'catalog/count_input.html' %}
{% include 'catalog/count_input.html' with quantity=position.quantity only %}
</td>
<td class="order-table-price">
{{ position.price|format_price }}
Expand Down

4 comments on commit 3448689

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 3448689 Jun 8, 2019

Choose a reason for hiding this comment

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

Puzzle 662-97154e41 discovered in front/js/product.es6 and submitted as #683. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 3448689 Jun 8, 2019

Choose a reason for hiding this comment

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

Puzzle 665-b7a31ca2 discovered in stroyprombeton/tests/tests_selenium.py and submitted as #684. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 3448689 Jun 8, 2019

Choose a reason for hiding this comment

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

Puzzle 662-dbfe2213 discovered in stroyprombeton/tests/tests_selenium.py and submitted as #685. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 3448689 Jun 8, 2019

Choose a reason for hiding this comment

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

Puzzle 665-a5aa9e4e discovered in stroyprombeton/tests/tests_selenium.py and submitted as #686. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.