diff options
-rw-r--r-- | .cypress/cypress/integration/duplicates.js | 80 | ||||
-rw-r--r-- | .cypress/cypress/integration/regressions.js | 34 | ||||
-rw-r--r-- | templates/web/base/common_scripts.html | 2 | ||||
-rw-r--r-- | web/js/duplicates.js | 9 |
4 files changed, 87 insertions, 38 deletions
diff --git a/.cypress/cypress/integration/duplicates.js b/.cypress/cypress/integration/duplicates.js new file mode 100644 index 000000000..406b3fb67 --- /dev/null +++ b/.cypress/cypress/integration/duplicates.js @@ -0,0 +1,80 @@ +describe('Duplicate tests', function() { + it('does not try and fetch duplicates which will not get shown', function() { + cy.server(); + cy.route('/report/new/ajax*').as('report-ajax'); + cy.request({ + method: 'POST', + url: '/auth?r=/', + form: true, + body: { username: 'admin@example.org', password_sign_in: 'password' } + }); + cy.visit('http://fixmystreet.localhost:3001/report/1'); + cy.contains('Report another problem here').click(); + cy.wait('@report-ajax'); + cy.get('[id=category_group]').select('Potholes'); + cy.wait(500); + cy.get('[name=title').should('be.visible'); + }); + + it('hides everything when duplicate suggestions are shown', function() { + cy.server(); + cy.route('/report/new/ajax*').as('report-ajax'); + cy.visit('http://borsetshire.localhost:3001/_test/setup/regression-duplicate-hide'); // Server-side setup + cy.visit('http://borsetshire.localhost:3001/report/1'); + cy.contains('Report another problem here').click(); + cy.wait('@report-ajax'); + cy.get('[id=category_group]').select('Licensing'); + cy.get('[id=subcategory_Licensing]').select('Skips'); + cy.get('.extra-category-questions').should('not.be.visible'); + cy.visit('http://borsetshire.localhost:3001/_test/teardown/regression-duplicate-hide'); + }); + + it('does not show duplicate suggestions when signing in during reporting', function() { + cy.server(); + cy.route('/report/new/ajax*').as('report-ajax'); + cy.route('/around/nearby*').as('nearby-ajax'); + cy.visit('http://borsetshire.localhost:3001/report/1'); + cy.contains('Report another problem here').click(); + cy.wait('@report-ajax'); + cy.get('[id=category_group]').select('Potholes'); + cy.wait('@nearby-ajax'); + cy.get('.js-hide-duplicate-suggestions:first').should('be.visible').click(); + cy.get('[name=title]').type('Title'); + cy.get('[name=detail]').type('Detail'); + cy.get('.js-new-report-user-show').click(); + cy.get('.js-new-report-show-sign-in').should('be.visible').click(); + cy.get('#form_username_sign_in').type('user@example.org'); + cy.get('[name=password_sign_in]').type('password'); + cy.get('[name=password_sign_in]').parents('form').submit(); + cy.get('#map_sidebar').should('contain', 'check and confirm your details'); + cy.get('#js-duplicate-reports').should('not.exist'); + }); + + it('lets an inspector see duplicate reports coming from /reports', function() { + cy.request({ + method: 'POST', + url: 'http://borsetshire.localhost:3001/auth?r=/reports', + form: true, + body: { username: 'admin@example.org', password_sign_in: 'password' } + }); + cy.visit('http://borsetshire.localhost:3001/reports'); + cy.get('[href$="/report/1"]:last').click(); + cy.get('#report_inspect_form #state').select('Duplicate'); + cy.get('#js-duplicate-reports li h3 a').should('have.attr', 'href', '/report/1'); + }); + + it('lets an inspector see duplicate reports coming from /around', function() { + cy.request({ + method: 'POST', + url: 'http://borsetshire.localhost:3001/auth?r=/reports', + form: true, + body: { username: 'admin@example.org', password_sign_in: 'password' } + }); + cy.visit('http://borsetshire.localhost:3001/report/1'); + cy.contains('Back to all').click(); + cy.get('[href$="/report/1"]:last').click(); + cy.get('#report_inspect_form #state').select('Duplicate'); + cy.get('#js-duplicate-reports li h3 a').should('have.attr', 'href', '/report/1'); + }); + +}); diff --git a/.cypress/cypress/integration/regressions.js b/.cypress/cypress/integration/regressions.js index 73f6900a6..f9fedc3eb 100644 --- a/.cypress/cypress/integration/regressions.js +++ b/.cypress/cypress/integration/regressions.js @@ -92,38 +92,4 @@ describe('Regression tests', function() { cy.get('#form_start_date').should('have.value', '2019-01-01'); }); - it('hides everything when duplicate suggestions are shown', function() { - cy.server(); - cy.route('/report/new/ajax*').as('report-ajax'); - cy.visit('http://borsetshire.localhost:3001/_test/setup/regression-duplicate-hide'); // Server-side setup - cy.visit('http://borsetshire.localhost:3001/report/1'); - cy.contains('Report another problem here').click(); - cy.wait('@report-ajax'); - cy.get('[id=category_group]').select('Licensing'); - cy.get('[id=subcategory_Licensing]').select('Skips'); - cy.get('.extra-category-questions').should('not.be.visible'); - cy.visit('http://borsetshire.localhost:3001/_test/teardown/regression-duplicate-hide'); - }); - - it('does not show duplicate suggestions when signing in during reporting', function() { - cy.server(); - cy.route('/report/new/ajax*').as('report-ajax'); - cy.route('/around/nearby*').as('nearby-ajax'); - cy.visit('http://borsetshire.localhost:3001/report/1'); - cy.contains('Report another problem here').click(); - cy.wait('@report-ajax'); - cy.get('[id=category_group]').select('Potholes'); - cy.wait('@nearby-ajax'); - cy.get('.js-hide-duplicate-suggestions:first').should('be.visible').click(); - cy.get('[name=title]').type('Title'); - cy.get('[name=detail]').type('Detail'); - cy.get('.js-new-report-user-show').click(); - cy.get('.js-new-report-show-sign-in').should('be.visible').click(); - cy.get('#form_username_sign_in').type('user@example.org'); - cy.get('[name=password_sign_in]').type('password'); - cy.get('[name=password_sign_in]').parents('form').submit(); - cy.get('#map_sidebar').should('contain', 'check and confirm your details'); - cy.get('#js-duplicate-reports').should('not.exist'); - }); - }); diff --git a/templates/web/base/common_scripts.html b/templates/web/base/common_scripts.html index 56b2e6d2e..7df8feaa0 100644 --- a/templates/web/base/common_scripts.html +++ b/templates/web/base/common_scripts.html @@ -39,7 +39,7 @@ IF c.user_exists AND (c.user.from_body OR c.user.is_superuser); version('/jslib/jquery-1.7.2.min.js'), version('/cobrands/fixmystreet/staff.js') ); - IF bodyclass.match('mappage'); + IF bodyclass.match('mappage') AND c.cobrand.suggest_duplicates AND NOT login_success AND NOT oauth_need_email; scripts.push( version('/js/duplicates.js') ); diff --git a/web/js/duplicates.js b/web/js/duplicates.js index a8aceb9e3..ede22dc18 100644 --- a/web/js/duplicates.js +++ b/web/js/duplicates.js @@ -13,12 +13,14 @@ // but undefined on new report page. var report_id = $("#report_inspect_form .js-report-id").text() || undefined; - function refresh_duplicate_list(evt, params) { + function refresh_duplicate_list(evt, params, category) { if (params && params.skip_duplicates) { return; } - var category = $('select[name="category"]').val(); + if (!category) { + category = $('select[name="category"]').val(); + } if (category === '-- Pick a category --') { return; } @@ -195,7 +197,8 @@ if (!!duplicate_of) { return; } - refresh_duplicate_list(); + var category = $("#report_inspect_form [name=category]").val(); + refresh_duplicate_list(undefined, {}, category); } function take_effect() { |