workarea-testing 3.4.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +52 -0
- data/README.md +19 -0
- data/app/assets/javascripts/workarea/admin/spec_helper.js +1 -0
- data/app/assets/javascripts/workarea/core/feature_test_helper.js +15 -0
- data/app/assets/javascripts/workarea/core/spec_helper.js +45 -0
- data/app/assets/javascripts/workarea/storefront/spec_helper.js +2 -0
- data/app/assets/stylesheets/workarea/admin/_feature_test_helper.scss +16 -0
- data/app/assets/stylesheets/workarea/core/_feature_test_helper.scss +8 -0
- data/lib/workarea/admin/integration_test.rb +15 -0
- data/lib/workarea/core/discount_condition_tests.rb +100 -0
- data/lib/workarea/core/featured_products_test.rb +30 -0
- data/lib/workarea/core/navigable_test.rb +68 -0
- data/lib/workarea/generator_test.rb +5 -0
- data/lib/workarea/integration_test.rb +45 -0
- data/lib/workarea/performance_test.rb +135 -0
- data/lib/workarea/storefront/breakpoint_helpers.rb +27 -0
- data/lib/workarea/storefront/catalog_customization_test_class.rb +28 -0
- data/lib/workarea/storefront/integration_test.rb +82 -0
- data/lib/workarea/storefront/pagination_view_model_test.rb +56 -0
- data/lib/workarea/storefront/product_browsing_view_model_test.rb +38 -0
- data/lib/workarea/storefront/system_test.rb +142 -0
- data/lib/workarea/system_test.rb +161 -0
- data/lib/workarea/test_case.rb +197 -0
- data/lib/workarea/test_help.rb +67 -0
- data/lib/workarea/testing/cassette_persister.rb +40 -0
- data/lib/workarea/testing/custom_capybara_matchers.rb +18 -0
- data/lib/workarea/testing/decoration_reporter.rb +37 -0
- data/lib/workarea/testing/deferred_garbage_collection.rb +21 -0
- data/lib/workarea/testing/elasticsearch_response.json +1 -0
- data/lib/workarea/testing/engine.rb +6 -0
- data/lib/workarea/testing/example_document.pdf +0 -0
- data/lib/workarea/testing/factories/bulk_action.rb +17 -0
- data/lib/workarea/testing/factories/catalog.rb +66 -0
- data/lib/workarea/testing/factories/comment.rb +12 -0
- data/lib/workarea/testing/factories/content.rb +38 -0
- data/lib/workarea/testing/factories/data_file.rb +21 -0
- data/lib/workarea/testing/factories/fulfillment.rb +21 -0
- data/lib/workarea/testing/factories/insights.rb +32 -0
- data/lib/workarea/testing/factories/metrics.rb +25 -0
- data/lib/workarea/testing/factories/navigation.rb +30 -0
- data/lib/workarea/testing/factories/order.rb +77 -0
- data/lib/workarea/testing/factories/payment.rb +37 -0
- data/lib/workarea/testing/factories/performance/catalog.rb +92 -0
- data/lib/workarea/testing/factories/pricing.rb +59 -0
- data/lib/workarea/testing/factories/recommendation.rb +17 -0
- data/lib/workarea/testing/factories/search.rb +72 -0
- data/lib/workarea/testing/factories/user.rb +24 -0
- data/lib/workarea/testing/factories.rb +146 -0
- data/lib/workarea/testing/factory_configuration.rb +90 -0
- data/lib/workarea/testing/indexes.rb +22 -0
- data/lib/workarea/testing/locale_routing_fixes.rb +33 -0
- data/lib/workarea/testing/product_image.jpg +0 -0
- data/lib/workarea/testing/teaspoon.rb +186 -0
- data/lib/workarea/testing/user_avatar.jpg +0 -0
- data/lib/workarea/testing/warning_suppressor.rb +59 -0
- data/lib/workarea/view_test.rb +40 -0
- data/workarea-testing.gemspec +29 -0
- metadata +240 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 22ef0b6e2ec255eaa27a7d9e3c1f9702e432a4862cd7f0d7802dcd67c963843a
|
4
|
+
data.tar.gz: ccb12e277f49d543bdd4996e865c58425363374174bf5fe765ce26791be76be6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b51541e040c2dfdae58ba7bca0b419c66ed2cf9c453a6b9455563acc24e4822f1c41bb8f4e31faa49a2358282cbdc044c71e1221cda5c591866a8b4aa34549f5
|
7
|
+
data.tar.gz: 5b7088a8fa559193df1ae6f1c3a7440bb6bac1bb255672a123585e79688509b3a1f410842cea406a197935b710373829b5bd31d6626605be82927849fce2745e
|
data/LICENSE
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
WebLinc
|
2
|
+
Business Source License
|
3
|
+
|
4
|
+
Licensor: WebLinc Corporation, 22 S. 3rd Street, 2nd Floor, Philadelphia PA 19106
|
5
|
+
|
6
|
+
Licensed Work: Workarea Commerce Platform
|
7
|
+
The Licensed Work is (c) 2019 WebLinc Corporation
|
8
|
+
|
9
|
+
Additional Use Grant:
|
10
|
+
You may make production use of the Licensed Work without an additional license agreement with WebLinc so long as you do not use the Licensed Work for a Commerce Service.
|
11
|
+
|
12
|
+
A "Commerce Service" is a commercial offering that allows third parties (other than your employees and contractors) to access the functionality of the Licensed Work by creating or managing commerce functionality, the products, taxonomy, assets and/or content of which are controlled by such third parties.
|
13
|
+
|
14
|
+
For information about obtaining an additional license agreement with WebLinc, contact licensing@workarea.com.
|
15
|
+
|
16
|
+
Change Date: 2019-08-20
|
17
|
+
|
18
|
+
Change License: Version 2.0 or later of the GNU General Public License as published by the Free Software Foundation
|
19
|
+
|
20
|
+
Terms
|
21
|
+
|
22
|
+
The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
|
23
|
+
|
24
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
|
25
|
+
|
26
|
+
If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
|
27
|
+
|
28
|
+
All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
|
29
|
+
|
30
|
+
You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
|
31
|
+
|
32
|
+
Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
|
33
|
+
|
34
|
+
This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License). TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE. MariaDB hereby grants you permission to use this License’s text to license your works and to refer to it using the trademark "Business Source License" as long as you comply with the Covenants of Licensor below.
|
35
|
+
|
36
|
+
Covenants of Licensor
|
37
|
+
In consideration of the right to use this License’s text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
|
38
|
+
|
39
|
+
To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
|
40
|
+
|
41
|
+
To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None."
|
42
|
+
|
43
|
+
To specify a Change Date.
|
44
|
+
|
45
|
+
Not to modify this License in any other way.
|
46
|
+
|
47
|
+
Notice
|
48
|
+
The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License.
|
49
|
+
|
50
|
+
For more information on the use of the Business Source License generally, please visit the Adopting and Developing Business Source License FAQ.
|
51
|
+
|
52
|
+
License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of MariaDB Corporation Ab.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Workarea Testing
|
2
|
+
================================================================================
|
3
|
+
|
4
|
+
Minitest testing support for the Workarea platform.
|
5
|
+
|
6
|
+
Getting Started
|
7
|
+
--------------------------------------------------------------------------------
|
8
|
+
|
9
|
+
To use Workarea Testing, install the `workarea` gem. See the `workarea` gem for installation instructions.
|
10
|
+
|
11
|
+
Workarea Platform Documentation
|
12
|
+
--------------------------------------------------------------------------------
|
13
|
+
|
14
|
+
See the `workarea` gem for Workarea platform documentation.
|
15
|
+
|
16
|
+
License
|
17
|
+
--------------------------------------------------------------------------------
|
18
|
+
|
19
|
+
Workarea Admin is released under the [Business Software License](LICENSE)
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require workarea/admin/application
|
@@ -0,0 +1,15 @@
|
|
1
|
+
(function () {
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
// Turn off transformations and transitions in the test environment, as they
|
5
|
+
// cause timing issues for build teams.
|
6
|
+
feature.css3Dtransform = false;
|
7
|
+
feature.cssTransform = false;
|
8
|
+
feature.cssTransition = false;
|
9
|
+
|
10
|
+
// Make sure the browser doesn't think it'll be poked.
|
11
|
+
feature.touch = false;
|
12
|
+
|
13
|
+
window.alert = function () {};
|
14
|
+
window.confirm = function () { return true; };
|
15
|
+
}());
|
@@ -0,0 +1,45 @@
|
|
1
|
+
// Teaspoon includes some support files, but you can use anything from your own support path too.
|
2
|
+
// require support/expect
|
3
|
+
//= require support/sinon
|
4
|
+
//= require support/chai
|
5
|
+
//= require support/sinon-chai
|
6
|
+
// require support/chai-jq-0.0.7
|
7
|
+
// require support/your-support-file
|
8
|
+
//
|
9
|
+
// PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion.
|
10
|
+
// Use this polyfill to avoid the confusion.
|
11
|
+
//= require support/bind-poly
|
12
|
+
//
|
13
|
+
// You can require your own javascript files here. By default this will include everything in application, however you
|
14
|
+
// may get better load performance if you require the specific files that are being used in the spec that tests them.
|
15
|
+
//= require workarea/core/workarea
|
16
|
+
//
|
17
|
+
// Deferring execution
|
18
|
+
// If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call
|
19
|
+
// Teaspoon.execute() after everything has been loaded. Simple example of a timeout:
|
20
|
+
//
|
21
|
+
// Teaspoon.defer = true
|
22
|
+
// setTimeout(Teaspoon.execute, 1000)
|
23
|
+
//
|
24
|
+
// Matching files
|
25
|
+
// By default Teaspoon will look for files that match _spec.{js,js.coffee,.coffee}. Add a filename_spec.js file in your
|
26
|
+
// spec path and it'll be included in the default suite automatically. If you want to customize suites, check out the
|
27
|
+
// configuration in teaspoon_env.rb
|
28
|
+
//
|
29
|
+
// Manifest
|
30
|
+
// If you'd rather require your spec files manually (to control order for instance) you can disable the suite matcher in
|
31
|
+
// the configuration and use this file as a manifest.
|
32
|
+
//
|
33
|
+
// For more information: http://github.com/modeset/teaspoon
|
34
|
+
//
|
35
|
+
// Chai
|
36
|
+
// If you're using Chai, you'll probably want to initialize your preferred assertion style. You can read more about Chai
|
37
|
+
// at: http://chaijs.com/guide/styles
|
38
|
+
//
|
39
|
+
// window.assert = chai.assert;
|
40
|
+
window.expect = chai.expect;
|
41
|
+
// window.should = chai.should();
|
42
|
+
|
43
|
+
// add FeatureJS class to root element
|
44
|
+
document.documentElement.className =
|
45
|
+
document.documentElement.className + ' js';
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/**
|
2
|
+
* UIs that stick shouldn't in the test environment.
|
3
|
+
*/
|
4
|
+
.header,
|
5
|
+
.workflow-bar { position: absolute !important; }
|
6
|
+
|
7
|
+
.takeover__logo,
|
8
|
+
.content-editor__aside,
|
9
|
+
.content-editor__form-actions { position: relative !important; }
|
10
|
+
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Phantom JS 2.1 does not have support for flexbox
|
14
|
+
* Overrides necessary to prevent layout issues in tests.
|
15
|
+
*/
|
16
|
+
.header__search-form { max-width: 300px; }
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Workarea
|
2
|
+
module DiscountConditionTests
|
3
|
+
module OrderTotal
|
4
|
+
def test_order_total?
|
5
|
+
refute(order_total_discount.order_total?)
|
6
|
+
|
7
|
+
order_total_discount.order_total = 0
|
8
|
+
refute(order_total_discount.order_total?)
|
9
|
+
|
10
|
+
order_total_discount.order_total = 1.to_m
|
11
|
+
assert(order_total_discount.order_total?)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_order_total_qualifies?
|
15
|
+
discounted_order.subtotal_price = 5.to_m
|
16
|
+
|
17
|
+
assert(order_total_discount.order_total_qualifies?(discounted_order))
|
18
|
+
|
19
|
+
order_total_discount.order_total_operator = :less_than
|
20
|
+
|
21
|
+
order_total_discount.order_total = 4
|
22
|
+
refute(order_total_discount.order_total_qualifies?(discounted_order))
|
23
|
+
|
24
|
+
order_total_discount.order_total = 5
|
25
|
+
refute(order_total_discount.order_total_qualifies?(discounted_order))
|
26
|
+
|
27
|
+
order_total_discount.order_total = 6
|
28
|
+
assert(order_total_discount.order_total_qualifies?(discounted_order))
|
29
|
+
|
30
|
+
order_total_discount.order_total_operator = :greater_than
|
31
|
+
|
32
|
+
order_total_discount.order_total = 4
|
33
|
+
assert(order_total_discount.order_total_qualifies?(discounted_order))
|
34
|
+
|
35
|
+
order_total_discount.order_total = 5
|
36
|
+
refute(order_total_discount.order_total_qualifies?(discounted_order))
|
37
|
+
|
38
|
+
order_total_discount.order_total = 6
|
39
|
+
refute(order_total_discount.order_total_qualifies?(discounted_order))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module PromoCodes
|
44
|
+
def test_promo_codes_qualify?
|
45
|
+
assert(promo_codes_discount.promo_codes_qualify?(discounted_order))
|
46
|
+
|
47
|
+
promo_codes_discount.promo_codes = %w(oNe TwO)
|
48
|
+
|
49
|
+
discounted_order.promo_codes = ['three']
|
50
|
+
refute(promo_codes_discount.promo_codes_qualify?(discounted_order))
|
51
|
+
|
52
|
+
discounted_order.promo_codes = ['one']
|
53
|
+
assert(promo_codes_discount.promo_codes_qualify?(discounted_order))
|
54
|
+
|
55
|
+
code_list = create_code_list
|
56
|
+
code_list.generate_promo_codes!
|
57
|
+
|
58
|
+
code = code_list.promo_codes.first.code
|
59
|
+
|
60
|
+
assert(promo_codes_discount.promo_codes_qualify?(discounted_order))
|
61
|
+
|
62
|
+
promo_codes_discount.generated_codes_id = code_list.id
|
63
|
+
discounted_order.promo_codes = [code.upcase]
|
64
|
+
|
65
|
+
assert(promo_codes_discount.promo_codes_qualify?(discounted_order))
|
66
|
+
|
67
|
+
promo_codes_discount.generated_codes_id = code_list.id
|
68
|
+
discounted_order.promo_codes = ['lkajwf']
|
69
|
+
|
70
|
+
refute(promo_codes_discount.promo_codes_qualify?(discounted_order))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
module ItemQuantity
|
75
|
+
def test_item_quantity?
|
76
|
+
item_quantity_discount.item_quantity = nil
|
77
|
+
refute(item_quantity_discount.item_quantity?)
|
78
|
+
|
79
|
+
item_quantity_discount.item_quantity = 0
|
80
|
+
refute(item_quantity_discount.item_quantity?)
|
81
|
+
|
82
|
+
item_quantity_discount.item_quantity = 1
|
83
|
+
assert(item_quantity_discount.item_quantity?)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_items_qualify?
|
87
|
+
discounted_order.items.first.quantity = 2
|
88
|
+
|
89
|
+
# When there is no item_quantity, quantity is ignored
|
90
|
+
assert(item_quantity_discount.items_qualify?(discounted_order))
|
91
|
+
|
92
|
+
item_quantity_discount.item_quantity = 2
|
93
|
+
assert(item_quantity_discount.items_qualify?(discounted_order))
|
94
|
+
|
95
|
+
item_quantity_discount.item_quantity = 3
|
96
|
+
refute(item_quantity_discount.items_qualify?(discounted_order))
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Workarea
|
2
|
+
module FeaturedProductsTest
|
3
|
+
def test_adding_a_product
|
4
|
+
featured_product_model.add_product('foo')
|
5
|
+
assert_includes(featured_product_model.reload.product_ids, 'foo')
|
6
|
+
assert(featured_product_model.featured_product?('foo'))
|
7
|
+
|
8
|
+
featured_product_model.add_product('bar')
|
9
|
+
assert_equal('bar', featured_product_model.reload.product_ids.first)
|
10
|
+
assert(featured_product_model.featured_product?('bar'))
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_removing_a_product
|
14
|
+
featured_product_model.add_product('foo')
|
15
|
+
featured_product_model.remove_product('foo')
|
16
|
+
assert_empty(featured_product_model.reload.product_ids)
|
17
|
+
refute(featured_product_model.featured_product?('foo'))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_cleaning_product_ids
|
21
|
+
['', nil].each do |blank|
|
22
|
+
featured_product_model.add_product(blank)
|
23
|
+
assert_equal(0, featured_product_model.reload.product_ids.length)
|
24
|
+
end
|
25
|
+
|
26
|
+
2.times { featured_product_model.add_product('foo') }
|
27
|
+
assert_equal(['foo'], featured_product_model.reload.product_ids)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Workarea
|
2
|
+
module NavigableTest
|
3
|
+
def test_validations
|
4
|
+
instance = navigable_class.new(name: 'test model')
|
5
|
+
instance.valid?
|
6
|
+
assert_equal('test-model', instance.slug)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_slug_generation
|
10
|
+
instance = navigable_class.new(name: 'Test Slug')
|
11
|
+
instance.valid?
|
12
|
+
instance.save(validate: false)
|
13
|
+
assert_equal('test-slug', instance.slug)
|
14
|
+
|
15
|
+
instance = navigable_class.new(name: 'Test Slug')
|
16
|
+
instance.valid?
|
17
|
+
instance.save(validate: false)
|
18
|
+
assert_equal('test-slug-1', instance.slug)
|
19
|
+
|
20
|
+
instance = navigable_class.new(name: 'Test Slug')
|
21
|
+
instance.valid?
|
22
|
+
instance.save(validate: false)
|
23
|
+
assert_equal('test-slug-2', instance.slug)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_slug_caching
|
27
|
+
model = navigable_class.new(name: 'Test Slug', slug: 'same-slug')
|
28
|
+
model.valid?
|
29
|
+
model.save(validate: false)
|
30
|
+
|
31
|
+
taxon = create_taxon(navigable: model)
|
32
|
+
|
33
|
+
model = navigable_class.find(model.id)
|
34
|
+
model.slug = 'different-slug'
|
35
|
+
model.save(validate: false)
|
36
|
+
|
37
|
+
taxon.reload
|
38
|
+
assert_equal('different-slug', taxon.navigable_slug)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_save
|
42
|
+
model = navigable_class.new(slug: 'test-slug')
|
43
|
+
model.save
|
44
|
+
assert(model.slug.nil?)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_destroy
|
48
|
+
model = navigable_class.new(name: 'Test Slug', slug: 'same-slug')
|
49
|
+
model.valid?
|
50
|
+
model.save(validate: false)
|
51
|
+
|
52
|
+
create_taxon(navigable: model)
|
53
|
+
|
54
|
+
model.destroy
|
55
|
+
assert_equal(1, Workarea::Navigation::Taxon.count)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_slug=
|
59
|
+
instance = navigable_class.new(slug: 'test slug')
|
60
|
+
assert_equal('test-slug', instance.slug)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_to_param
|
64
|
+
instance = navigable_class.new(slug: 'test-param')
|
65
|
+
assert_equal('test-param', instance.to_param)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Workarea
|
2
|
+
class IntegrationTest < ActionDispatch::IntegrationTest
|
3
|
+
module Configuration
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
setup do
|
8
|
+
Mongoid.truncate!
|
9
|
+
Workarea.redis.flushdb
|
10
|
+
default_url_options[:locale] = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
teardown do
|
14
|
+
travel_back
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_current_user(user)
|
19
|
+
Workarea::ApplicationController.subclasses.each do |klass|
|
20
|
+
if klass.method_defined?(:current_user)
|
21
|
+
klass.any_instance.stubs(:current_user).returns(user)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_current_admin(user)
|
27
|
+
Workarea::ApplicationController.subclasses.each do |klass|
|
28
|
+
if klass.method_defined?(:current_admin)
|
29
|
+
klass.any_instance.stubs(:current_admin).returns(user)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
extend TestCase::Decoration
|
36
|
+
include TestCase::Workers
|
37
|
+
include TestCase::SearchIndexing
|
38
|
+
include TestCase::Mail
|
39
|
+
include TestCase::RunnerLocation
|
40
|
+
include TestCase::Locales
|
41
|
+
include TestCase::S3
|
42
|
+
include Factories
|
43
|
+
include Configuration
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class PerformanceTest < ActionDispatch::IntegrationTest
|
5
|
+
extend TestCase::Decoration
|
6
|
+
include TestCase::Workers
|
7
|
+
include TestCase::SearchIndexing
|
8
|
+
include TestCase::RunnerLocation
|
9
|
+
include TestCase::Locales
|
10
|
+
include TestCase::S3
|
11
|
+
include Factories
|
12
|
+
include IntegrationTest::Configuration
|
13
|
+
|
14
|
+
HEADER = %w(measurement created_at workarea rails ruby revision passed)
|
15
|
+
|
16
|
+
setup :warmup_app
|
17
|
+
teardown :reset_caching
|
18
|
+
|
19
|
+
def warmup_app
|
20
|
+
@controller_caching = ActionController::Base.perform_caching
|
21
|
+
ActionController::Base.perform_caching = true
|
22
|
+
get '/'
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset_caching
|
26
|
+
ActionController::Base.perform_caching = @controller_caching
|
27
|
+
end
|
28
|
+
|
29
|
+
def run
|
30
|
+
with_info_handler do
|
31
|
+
time_it do
|
32
|
+
capture_exceptions do
|
33
|
+
pass && (return self) unless ENV['PERF_TEST'] =~ /true/
|
34
|
+
|
35
|
+
before_setup
|
36
|
+
setup
|
37
|
+
after_setup
|
38
|
+
|
39
|
+
with_benchmarking { self.send self.name }
|
40
|
+
end
|
41
|
+
|
42
|
+
Minitest::Test::TEARDOWN_METHODS.each do |hook|
|
43
|
+
capture_exceptions { self.send hook }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
self # per contract
|
49
|
+
end
|
50
|
+
|
51
|
+
def with_benchmarking(&block)
|
52
|
+
result = Benchmark.measure { yield }
|
53
|
+
previous_times = previous_run_measurements
|
54
|
+
|
55
|
+
previous_times.each do |time|
|
56
|
+
if time < result.real
|
57
|
+
assert_in_epsilon(
|
58
|
+
time,
|
59
|
+
result.real,
|
60
|
+
max_percentage_of_change,
|
61
|
+
epsilon_failure_message
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
benchmark_file.puts(formatted_results(result))
|
67
|
+
|
68
|
+
rescue Minitest::Assertion => e
|
69
|
+
benchmark_file.puts(formatted_results(result, false))
|
70
|
+
raise e
|
71
|
+
ensure
|
72
|
+
benchmark_file.close
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
# Find previous run times. Finds x+2 number of times based on
|
78
|
+
# configuration then removes the highest and lowest times to reduce
|
79
|
+
# the standard deviation of typical run times.
|
80
|
+
def previous_run_measurements
|
81
|
+
rows = benchmark_file.to_a.reverse
|
82
|
+
return [] unless rows.any?
|
83
|
+
|
84
|
+
rows
|
85
|
+
.select { |row| row['passed'].to_s =~ /true/ }
|
86
|
+
.take(Workarea.config.performance_test_comparisons + 2)
|
87
|
+
.map { |row| row.to_hash['measurement'].to_f }
|
88
|
+
.sort[1...-1] || []
|
89
|
+
end
|
90
|
+
|
91
|
+
def benchmark_file
|
92
|
+
return @benchmark_file if defined?(@benchmark_file)
|
93
|
+
|
94
|
+
fname = output_filename
|
95
|
+
new_file = !File.exist?(fname)
|
96
|
+
FileUtils.mkdir_p(File.dirname(fname)) if new_file
|
97
|
+
|
98
|
+
@benchmark_file = CSV.open(fname, 'a+b', headers: true)
|
99
|
+
@benchmark_file.puts(HEADER) if new_file
|
100
|
+
@benchmark_file
|
101
|
+
end
|
102
|
+
|
103
|
+
def output_filename
|
104
|
+
path = ENV['WORKAREA_PERF_TEST_PATH'] ||
|
105
|
+
Workarea.config.performance_test_output_path
|
106
|
+
|
107
|
+
"#{path}/#{self.class.name.underscore}/#{self.name}.csv"
|
108
|
+
end
|
109
|
+
|
110
|
+
def formatted_results(benchmark, passed = true)
|
111
|
+
[
|
112
|
+
benchmark.real,
|
113
|
+
Time.current.utc.xmlschema,
|
114
|
+
Workarea::VERSION::STRING,
|
115
|
+
Rails::VERSION::STRING,
|
116
|
+
"#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}",
|
117
|
+
git_revision,
|
118
|
+
passed
|
119
|
+
]
|
120
|
+
end
|
121
|
+
|
122
|
+
def git_revision
|
123
|
+
`git branch -v` =~ /^\* (\S+)\s+(\S+)/ ? "#{$1}.#{$2}" : "n/a"
|
124
|
+
end
|
125
|
+
|
126
|
+
def epsilon_failure_message
|
127
|
+
amount = max_percentage_of_change * 100
|
128
|
+
"run took more than #{amount}% longer than the previous run"
|
129
|
+
end
|
130
|
+
|
131
|
+
def max_percentage_of_change
|
132
|
+
Workarea.config.performance_test_max_percentage_of_change
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Workarea
|
2
|
+
module BreakpointHelpers
|
3
|
+
# Resizes the headless browser viewport width & height to a given breakpoint
|
4
|
+
# as defined in Workarea.config.storefront_break_points.
|
5
|
+
# Height is calculated as 16:9 aspect ratio.
|
6
|
+
#
|
7
|
+
def resize_window_to(breakpoint_name)
|
8
|
+
breakpoint = breakpoint_for(breakpoint_name)
|
9
|
+
return unless breakpoint.present?
|
10
|
+
resize_window_by(breakpoint, aspect_ratio_height(breakpoint))
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def resize_window_by(width, height)
|
16
|
+
page.driver.browser.manage.window.resize_to(width, height)
|
17
|
+
end
|
18
|
+
|
19
|
+
def breakpoint_for(size_name)
|
20
|
+
Workarea.config.storefront_break_points[size_name.to_sym]
|
21
|
+
end
|
22
|
+
|
23
|
+
def aspect_ratio_height(width)
|
24
|
+
width / (9 / 16.0)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Storefront
|
3
|
+
module CatalogCustomizationTestClass
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
setup :add_customization_class
|
8
|
+
teardown :remove_customization_class
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_customization_class
|
12
|
+
Workarea::Catalog::Customizations.const_set(
|
13
|
+
'FooCust',
|
14
|
+
Class.new(Catalog::Customizations) do
|
15
|
+
customized_fields :foo, :bar
|
16
|
+
|
17
|
+
validates :foo, presence: true
|
18
|
+
validates :bar, presence: true
|
19
|
+
end
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_customization_class
|
24
|
+
Workarea::Catalog::Customizations.send(:remove_const, 'FooCust')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|