aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2018-10-03 15:36:06 +0100
committerStruan Donald <struan@exo.org.uk>2018-10-09 11:16:40 +0100
commitb43277add3b4e04bf09e6f9cf640ef1d1d1d9b66 (patch)
tree23ef6b50de02abf2246c537960fc2cd50e2c0e71
parent675ec6e6d741be456b287479ea517cc46c4270be (diff)
front end category tests
Check selecting a category and selecting a sub category
-rw-r--r--.cypress/cypress/integration/category_tests.js41
-rwxr-xr-xbin/browser-tests3
-rwxr-xr-xbin/fixmystreet.com/fixture9
-rw-r--r--perllib/FixMyStreet/DB/Factories.pm8
-rw-r--r--t/Mock/MapIt.pm1
5 files changed, 59 insertions, 3 deletions
diff --git a/.cypress/cypress/integration/category_tests.js b/.cypress/cypress/integration/category_tests.js
new file mode 100644
index 000000000..5135ef842
--- /dev/null
+++ b/.cypress/cypress/integration/category_tests.js
@@ -0,0 +1,41 @@
+describe('Basic categories', function() {
+ before(function(){
+ cy.visit('/');
+ cy.contains('Go');
+ cy.get('[name=pc]').type(Cypress.env('postcode'));
+ cy.get('[name=pc]').parents('form').submit();
+ });
+
+ it('category dropdown contains the expected values', function() {
+ cy.server();
+ cy.route('/report/new/ajax*').as('report-ajax');
+ cy.url().should('include', '/around');
+ cy.get('#map_box').click(210, 200);
+ cy.wait('@report-ajax');
+ cy.get('[name=category]').should('not.be.visible');
+ var categories = ['-- Pick a category --', 'Graffiti', 'Potholes', 'Street lighting', 'Other', 'Bins' ];
+ cy.get('select:eq(3) option').each(function (obj, i) {
+ expect(obj[0].value).to.equal(categories[i]);
+ });
+ cy.get('#subcategory_Bins').should('not.be.visible');
+ cy.get('select:eq(3)').select('Bins');
+ cy.get('#subcategory_Bins').should('be.visible');
+ cy.get('select:eq(3)').select('Graffiti');
+ cy.get('#subcategory_Bins').should('not.be.visible');
+ });
+
+ it('category dropdown contains works from new page', function() {
+ cy.server();
+ cy.route('/report/new/ajax*').as('report-ajax');
+ cy.visit('/report/new?latitude=51.496194&longitude=-2.603482');
+ cy.get('[name=category]').should('not.be.visible');
+ var categories = ['-- Pick a category --', 'Graffiti', 'Potholes', 'Street lighting', 'Other', 'Bins' ];
+ cy.get('select:eq(1) option').each(function (obj, i) {
+ expect(obj[0].value).to.equal(categories[i]);
+ });
+ cy.get('#subcategory_Bins').should('not.be.visible');
+ cy.get('select:eq(1)').select('Bins');
+ cy.wait('@report-ajax');
+ cy.get('#subcategory_Bins').should('be.visible');
+ });
+});
diff --git a/bin/browser-tests b/bin/browser-tests
index 00cfbc346..d77894dcc 100755
--- a/bin/browser-tests
+++ b/bin/browser-tests
@@ -94,6 +94,9 @@ sub run {
kill 'TERM', $pid if $pid;
exit $exit >> 8;
} else {
+ use Test::MockModule;
+ my $c = Test::MockModule->new('FixMyStreet::Cobrand::FixMyStreet');
+ $c->mock('enable_category_groups', sub { 1 });
# Child, run the server on port 3001
local $ENV{FIXMYSTREET_APP_DEBUG} = 0;
require Plack::Runner;
diff --git a/bin/fixmystreet.com/fixture b/bin/fixmystreet.com/fixture
index ceefbcc9d..c6c9b558e 100755
--- a/bin/fixmystreet.com/fixture
+++ b/bin/fixmystreet.com/fixture
@@ -141,6 +141,15 @@ if ($opt->nonrandom) {
};
}
}
+
+ for my $cat (qw/Overflowing Broken Missing/) {
+ my $child_cat = FixMyStreet::DB::Factory::Contact->find_or_create({
+ body => $body,
+ category => $cat
+ });
+ $child_cat->set_extra_metadata( group => 'Bins' );
+ $child_cat->update;
+ }
} else {
for (1..$num) {
$confirmed->add(seconds => rand(7000));
diff --git a/perllib/FixMyStreet/DB/Factories.pm b/perllib/FixMyStreet/DB/Factories.pm
index db80773e7..b66b27c5d 100644
--- a/perllib/FixMyStreet/DB/Factories.pm
+++ b/perllib/FixMyStreet/DB/Factories.pm
@@ -212,7 +212,7 @@ sub key_field { 'id' }
package FixMyStreet::DB::Factory::Contact;
-use parent "DBIx::Class::Factory";
+use parent -norequire, "FixMyStreet::DB::Factory::Base";
__PACKAGE__->resultset(FixMyStreet::DB->resultset("Contact"));
@@ -224,8 +224,8 @@ __PACKAGE__->fields({
category => 'Other',
email => __PACKAGE__->callback(sub {
my $category = shift->get('category');
- (my $email = lc $_) =~ s/ /-/g;
- lc $category . '@example.org';
+ (my $email = lc $category) =~ s/ /-/g;
+ $email . '@example.org';
}),
state => 'confirmed',
editor => 'Factory',
@@ -233,6 +233,8 @@ __PACKAGE__->fields({
note => 'Created by factory',
});
+sub key_field { 'id' }
+
#######################
package FixMyStreet::DB::Factory::ResponseTemplate;
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm
index ea00a7ff0..dc23b9ae2 100644
--- a/t/Mock/MapIt.pm
+++ b/t/Mock/MapIt.pm
@@ -26,6 +26,7 @@ my @PLACES = (
[ '?', 53.387402, -2.943997, 2527, 'Liverpool City Council', 'MTD' ],
[ 'EH1 1BB', 55.952055, -3.189579, 2651, 'Edinburgh City Council', 'UTA', 20728, 'City Centre', 'UTE' ],
[ 'BS10 5EE', 51.494885, -2.602237, 2561, 'Bristol City Council', 'UTA', 148646, 'Bedminster', 'UTW' ],
+ [ 'BS20 5EE', 51.496194, -2.603482, 2608, 'Borsetshire County Council', 'CTY', 148646, 'Bedminster', 'UTW' ],
[ 'SL9 0NX', 51.615559, -0.556903, 2217, 'Buckinghamshire County Council', 'CTY', 2257, 'Chiltern District Council', 'DIS' ],
[ 'SW1A 1AA', 51.501009, -0.141588, 2504, 'Westminster City Council', 'LBO' ],
[ 'GL50 2PR', 51.896268, -2.093063, 2226, 'Gloucestershire County Council', 'CTY', 2326, 'Cheltenham Borough Council', 'DIS', 4544, 'Lansdown', 'DIW', 143641, 'Lansdown and Park', 'CED' ],