From fc41ea7a4381274d99cd051761ac7fa9e721222d Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Mon, 23 Dec 2019 18:34:28 +0800 Subject: [PATCH] - Testing: Separate tests into unit/ui; split UI tests by specific domain; setup browser-bug folder and ui issues folder - Testing: Create test utilities for selecting English and visiting and approving storage - Testing: Add test for tool selection --- CHANGES.md | 4 +++ badges/coverage-badge.svg | 12 ++++----- cypress/integration/{ => ui}/accessibility.js | 2 +- .../{ui.js => ui/control-points.js} | 25 +++---------------- cypress/integration/ui/export.js | 20 +++++++++++++++ cypress/integration/ui/issues/issue-364.js | 19 ++++++++++++++ cypress/integration/ui/tool-selection.js | 18 +++++++++++++ .../browser-bugs/removeItem-setAttribute.js} | 0 cypress/integration/{ => unit}/contextmenu.js | 4 +-- cypress/integration/{ => unit}/coords.js | 8 +++--- cypress/integration/{ => unit}/draw.js | 8 +++--- cypress/integration/{ => unit}/history.js | 10 ++++---- cypress/integration/{ => unit}/math.js | 6 ++--- cypress/integration/{ => unit}/path.js | 10 ++++---- cypress/integration/{ => unit}/recalculate.js | 10 ++++---- cypress/integration/{ => unit}/sanitize.js | 6 ++--- cypress/integration/{ => unit}/select.js | 6 ++--- .../{ => unit}/svgtransformlist.js | 12 ++++----- cypress/integration/{ => unit}/test1.js | 8 +++--- cypress/integration/{ => unit}/units.js | 4 +-- .../integration/{ => unit}/utilities-bbox.js | 16 ++++++------ .../{ => unit}/utilities-performance.js | 12 ++++----- cypress/integration/{ => unit}/utilities.js | 8 +++--- cypress/support/ui-test-helper.js | 11 ++++++++ 24 files changed, 147 insertions(+), 92 deletions(-) rename cypress/integration/{ => ui}/accessibility.js (94%) rename cypress/integration/{ui.js => ui/control-points.js} (61%) create mode 100644 cypress/integration/ui/export.js create mode 100644 cypress/integration/ui/issues/issue-364.js create mode 100644 cypress/integration/ui/tool-selection.js rename cypress/integration/{browser-bugs.js => unit/browser-bugs/removeItem-setAttribute.js} (100%) rename cypress/integration/{ => unit}/contextmenu.js (94%) rename cypress/integration/{ => unit}/coords.js (97%) rename cypress/integration/{ => unit}/draw.js (99%) rename cypress/integration/{ => unit}/history.js (98%) rename cypress/integration/{ => unit}/math.js (95%) rename cypress/integration/{ => unit}/path.js (95%) rename cypress/integration/{ => unit}/recalculate.js (93%) rename cypress/integration/{ => unit}/sanitize.js (76%) rename cypress/integration/{ => unit}/select.js (95%) rename cypress/integration/{ => unit}/svgtransformlist.js (95%) rename cypress/integration/{ => unit}/test1.js (98%) rename cypress/integration/{ => unit}/units.js (96%) rename cypress/integration/{ => unit}/utilities-bbox.js (97%) rename cypress/integration/{ => unit}/utilities-performance.js (96%) rename cypress/integration/{ => unit}/utilities.js (98%) diff --git a/CHANGES.md b/CHANGES.md index a05b688a..50df8c8b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,10 @@ - Testing: Switch to Cypress with code coverage for UI testing; use ESM version for faster debugging - Testing: Add map file for underscore +- Testing: Separate tests into unit/ui; split UI tests by specific domain; + setup browser-bug folder and ui issues folder +- Testing: Create test utilities for selecting English and visiting and + approving storage - npm: Update scripts to reflect removal of `all_tests.html`; remove `browser-test` script - npm: Update devDeps, peerDeps diff --git a/badges/coverage-badge.svg b/badges/coverage-badge.svg index 00fb81e1..f2f4c84a 100644 --- a/badges/coverage-badge.svg +++ b/badges/coverage-badge.svg @@ -1,17 +1,17 @@ - + - + - - + + @@ -20,8 +20,8 @@ Coverage Coverage - 40.9% - 40.9% + 22.02% + 22.02% diff --git a/cypress/integration/accessibility.js b/cypress/integration/ui/accessibility.js similarity index 94% rename from cypress/integration/accessibility.js rename to cypress/integration/ui/accessibility.js index 448c5935..3baa23b5 100644 --- a/cypress/integration/accessibility.js +++ b/cypress/integration/ui/accessibility.js @@ -1,4 +1,4 @@ -describe('Accessibility', function () { +describe('UI - Accessibility', function () { beforeEach(() => { cy.visit('/instrumented/svg-editor-es.html'); cy.injectAxe(); diff --git a/cypress/integration/ui.js b/cypress/integration/ui/control-points.js similarity index 61% rename from cypress/integration/ui.js rename to cypress/integration/ui/control-points.js index 1cfbfd9c..2d8ad8d3 100644 --- a/cypress/integration/ui.js +++ b/cypress/integration/ui/control-points.js @@ -1,27 +1,10 @@ import { - approveStorage, openMainMenu, - openEditorPreferences -} from '../support/ui-test-helper.js'; + visitAndApproveStorage +} from '../../support/ui-test-helper.js'; -describe('UI tests', function () { +describe('UI - Control Points', function () { beforeEach(() => { - cy.visit('/instrumented/svg-editor-es.html'); - // Ensure we test against English regardless of the original locale - approveStorage(); - openEditorPreferences(); - cy.get('#lang_select').select('en'); - cy.get('#tool_prefs_save').click(); - }); - - it('Editor - No parameters: Has export button', () => { - openMainMenu(); - cy.get('#tool_export'); - }); - - it('Editor - No parameters: Export button clicking; dialog opens', () => { - openMainMenu(); - cy.get('#tool_export').click(); - cy.get('#dialog_content select'); + visitAndApproveStorage(); }); it('Editor - No parameters: Drag control point of arc path', () => { diff --git a/cypress/integration/ui/export.js b/cypress/integration/ui/export.js new file mode 100644 index 00000000..23fe4fb7 --- /dev/null +++ b/cypress/integration/ui/export.js @@ -0,0 +1,20 @@ +import { + visitAndApproveStorage, openMainMenu +} from '../../support/ui-test-helper.js'; + +describe('UI - Export tests', function () { + beforeEach(() => { + visitAndApproveStorage(); + }); + + it('Editor - No parameters: Has export button', () => { + openMainMenu(); + cy.get('#tool_export'); + }); + + it('Editor - No parameters: Export button clicking; dialog opens', () => { + openMainMenu(); + cy.get('#tool_export').click(); + cy.get('#dialog_content select'); + }); +}); diff --git a/cypress/integration/ui/issues/issue-364.js b/cypress/integration/ui/issues/issue-364.js new file mode 100644 index 00000000..b2039918 --- /dev/null +++ b/cypress/integration/ui/issues/issue-364.js @@ -0,0 +1,19 @@ +import { + visitAndApproveStorage +} from '../../../support/ui-test-helper.js'; + +// See https://github.com/SVG-Edit/svgedit/issues/364 +describe('Issue 364; IE errorwith rectangle selection by click', function () { + beforeEach(() => { + visitAndApproveStorage(); + }); + + it('should set rectangle selection after click', function () { + cy.get('#tools_rect_show') + .trigger('mousedown', {force: true}) + .trigger('mouseup', {force: true}) + .should((button) => { + expect(button).to.have.class('tool_button_current'); + }); + }); +}); diff --git a/cypress/integration/ui/tool-selection.js b/cypress/integration/ui/tool-selection.js new file mode 100644 index 00000000..d6be103d --- /dev/null +++ b/cypress/integration/ui/tool-selection.js @@ -0,0 +1,18 @@ +import { + visitAndApproveStorage +} from '../../support/ui-test-helper.js'; + +describe('UI - Tool selection', function () { + beforeEach(() => { + visitAndApproveStorage(); + }); + + it('should set rectangle selection by click', function () { + cy.get('#tools_rect_show') + .trigger('mousedown', {force: true}) + .trigger('mouseup', {force: true}) + .should((button) => { + expect(button).to.have.class('tool_button_current'); + }); + }); +}); diff --git a/cypress/integration/browser-bugs.js b/cypress/integration/unit/browser-bugs/removeItem-setAttribute.js similarity index 100% rename from cypress/integration/browser-bugs.js rename to cypress/integration/unit/browser-bugs/removeItem-setAttribute.js diff --git a/cypress/integration/contextmenu.js b/cypress/integration/unit/contextmenu.js similarity index 94% rename from cypress/integration/contextmenu.js rename to cypress/integration/unit/contextmenu.js index 0e1a2643..e851e8a7 100644 --- a/cypress/integration/contextmenu.js +++ b/cypress/integration/unit/contextmenu.js @@ -1,5 +1,5 @@ -import '../../instrumented/jquery.min.js'; -import * as contextmenu from '../../instrumented/contextmenu.js'; +import '../../../instrumented/jquery.min.js'; +import * as contextmenu from '../../../instrumented/contextmenu.js'; describe('contextmenu', function () { /** diff --git a/cypress/integration/coords.js b/cypress/integration/unit/coords.js similarity index 97% rename from cypress/integration/coords.js rename to cypress/integration/unit/coords.js index 94573927..d7388662 100644 --- a/cypress/integration/coords.js +++ b/cypress/integration/unit/coords.js @@ -1,8 +1,8 @@ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import {NS} from '../../instrumented/namespaces.js'; -import * as utilities from '../../instrumented/utilities.js'; -import * as coords from '../../instrumented/coords.js'; +import {NS} from '../../../instrumented/namespaces.js'; +import * as utilities from '../../../instrumented/utilities.js'; +import * as coords from '../../../instrumented/coords.js'; describe('coords', function () { let elemId = 1; diff --git a/cypress/integration/draw.js b/cypress/integration/unit/draw.js similarity index 99% rename from cypress/integration/draw.js rename to cypress/integration/unit/draw.js index 5d7703ca..232c6373 100644 --- a/cypress/integration/draw.js +++ b/cypress/integration/unit/draw.js @@ -1,8 +1,8 @@ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import {NS} from '../../instrumented/namespaces.js'; -import * as draw from '../../instrumented/draw.js'; -import * as units from '../../instrumented/units.js'; +import {NS} from '../../../instrumented/namespaces.js'; +import * as draw from '../../../instrumented/draw.js'; +import * as units from '../../../instrumented/units.js'; describe('draw.Drawing', function () { const addOwnSpies = (obj) => { diff --git a/cypress/integration/history.js b/cypress/integration/unit/history.js similarity index 98% rename from cypress/integration/history.js rename to cypress/integration/unit/history.js index a6398f7d..8a66401d 100644 --- a/cypress/integration/history.js +++ b/cypress/integration/unit/history.js @@ -1,9 +1,9 @@ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import {NS} from '../../instrumented/namespaces.js'; -import * as transformlist from '../../instrumented/svgtransformlist.js'; -import * as utilities from '../../instrumented/utilities.js'; -import * as hstory from '../../instrumented/history.js'; +import {NS} from '../../../instrumented/namespaces.js'; +import * as transformlist from '../../../instrumented/svgtransformlist.js'; +import * as utilities from '../../../instrumented/utilities.js'; +import * as hstory from '../../../instrumented/history.js'; describe('history', function () { // TODO(codedread): Write tests for handling history events. diff --git a/cypress/integration/math.js b/cypress/integration/unit/math.js similarity index 95% rename from cypress/integration/math.js rename to cypress/integration/unit/math.js index 62024313..2aacab41 100644 --- a/cypress/integration/math.js +++ b/cypress/integration/unit/math.js @@ -1,7 +1,7 @@ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import {NS} from '../../instrumented/namespaces.js'; -import * as math from '../../instrumented/math.js'; +import {NS} from '../../../instrumented/namespaces.js'; +import * as math from '../../../instrumented/math.js'; describe('math', function () { const svg = document.createElementNS(NS.SVG, 'svg'); diff --git a/cypress/integration/path.js b/cypress/integration/unit/path.js similarity index 95% rename from cypress/integration/path.js rename to cypress/integration/unit/path.js index e3a7ff4f..82249691 100644 --- a/cypress/integration/path.js +++ b/cypress/integration/unit/path.js @@ -1,10 +1,10 @@ /* globals SVGPathSeg */ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import '../../instrumented/svgpathseg.js'; -import {NS} from '../../instrumented/namespaces.js'; -import * as utilities from '../../instrumented/utilities.js'; -import * as pathModule from '../../instrumented/path.js'; +import '../../../instrumented/svgpathseg.js'; +import {NS} from '../../../instrumented/namespaces.js'; +import * as utilities from '../../../instrumented/utilities.js'; +import * as pathModule from '../../../instrumented/path.js'; describe('path', function () { /** diff --git a/cypress/integration/recalculate.js b/cypress/integration/unit/recalculate.js similarity index 93% rename from cypress/integration/recalculate.js rename to cypress/integration/unit/recalculate.js index adc37f38..1b98400b 100644 --- a/cypress/integration/recalculate.js +++ b/cypress/integration/unit/recalculate.js @@ -1,9 +1,9 @@ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import {NS} from '../../instrumented/namespaces.js'; -import * as utilities from '../../instrumented/utilities.js'; -import * as coords from '../../instrumented/coords.js'; -import * as recalculate from '../../instrumented/recalculate.js'; +import {NS} from '../../../instrumented/namespaces.js'; +import * as utilities from '../../../instrumented/utilities.js'; +import * as coords from '../../../instrumented/coords.js'; +import * as recalculate from '../../../instrumented/recalculate.js'; describe('recalculate', function () { // eslint-disable-next-line no-shadow diff --git a/cypress/integration/sanitize.js b/cypress/integration/unit/sanitize.js similarity index 76% rename from cypress/integration/sanitize.js rename to cypress/integration/unit/sanitize.js index 1f65d7be..f2c1a887 100644 --- a/cypress/integration/sanitize.js +++ b/cypress/integration/unit/sanitize.js @@ -1,7 +1,7 @@ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import {NS} from '../../instrumented/namespaces.js'; -import * as sanitize from '../../instrumented/sanitize.js'; +import {NS} from '../../../instrumented/namespaces.js'; +import * as sanitize from '../../../instrumented/sanitize.js'; describe('sanitize', function () { const svg = document.createElementNS(NS.SVG, 'svg'); diff --git a/cypress/integration/select.js b/cypress/integration/unit/select.js similarity index 95% rename from cypress/integration/select.js rename to cypress/integration/unit/select.js index 6912b852..0b025720 100644 --- a/cypress/integration/select.js +++ b/cypress/integration/unit/select.js @@ -1,7 +1,7 @@ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import * as select from '../../instrumented/select.js'; -import {NS} from '../../instrumented/namespaces.js'; +import * as select from '../../../instrumented/select.js'; +import {NS} from '../../../instrumented/namespaces.js'; describe('select', function () { const sandbox = document.createElement('div'); diff --git a/cypress/integration/svgtransformlist.js b/cypress/integration/unit/svgtransformlist.js similarity index 95% rename from cypress/integration/svgtransformlist.js rename to cypress/integration/unit/svgtransformlist.js index dc61ac3b..7072c080 100644 --- a/cypress/integration/svgtransformlist.js +++ b/cypress/integration/unit/svgtransformlist.js @@ -1,11 +1,11 @@ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import {NS} from '../../instrumented/namespaces.js'; -import * as transformlist from '../../instrumented/svgtransformlist.js'; -import {disableSupportsNativeTransformLists} from '../../instrumented/browser.js'; +import {NS} from '../../../instrumented/namespaces.js'; +import * as transformlist from '../../../instrumented/svgtransformlist.js'; +import {disableSupportsNativeTransformLists} from '../../../instrumented/browser.js'; -import almostEqualsPlugin from '../support/assert-almostEquals.js'; -import expectOutOfBoundsExceptionPlugin from '../support/assert-expectOutOfBoundsException.js'; +import almostEqualsPlugin from '../../support/assert-almostEquals.js'; +import expectOutOfBoundsExceptionPlugin from '../../support/assert-expectOutOfBoundsException.js'; chai.use(almostEqualsPlugin); chai.use(expectOutOfBoundsExceptionPlugin); diff --git a/cypress/integration/test1.js b/cypress/integration/unit/test1.js similarity index 98% rename from cypress/integration/test1.js rename to cypress/integration/unit/test1.js index 2909dc9b..9ba41d3b 100644 --- a/cypress/integration/test1.js +++ b/cypress/integration/unit/test1.js @@ -1,8 +1,8 @@ -import '../../instrumented/jquery.min.js'; -import '../../instrumented/jquery-ui/jquery-ui-1.8.17.custom.min.js'; +import '../../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery-ui/jquery-ui-1.8.17.custom.min.js'; -import '../../instrumented/svgpathseg.js'; -import SvgCanvas from '../../instrumented/svgcanvas.js'; +import '../../../instrumented/svgpathseg.js'; +import SvgCanvas from '../../../instrumented/svgcanvas.js'; describe('Basic Module', function () { // helper functions diff --git a/cypress/integration/units.js b/cypress/integration/unit/units.js similarity index 96% rename from cypress/integration/units.js rename to cypress/integration/unit/units.js index 340f2a64..c626e1e7 100644 --- a/cypress/integration/units.js +++ b/cypress/integration/unit/units.js @@ -1,6 +1,6 @@ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import * as units from '../../instrumented/units.js'; +import * as units from '../../../instrumented/units.js'; describe('units', function () { /** diff --git a/cypress/integration/utilities-bbox.js b/cypress/integration/unit/utilities-bbox.js similarity index 97% rename from cypress/integration/utilities-bbox.js rename to cypress/integration/unit/utilities-bbox.js index 6ff5f494..bc5b5b6b 100644 --- a/cypress/integration/utilities-bbox.js +++ b/cypress/integration/unit/utilities-bbox.js @@ -1,12 +1,12 @@ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import '../../instrumented/svgpathseg.js'; -import {NS} from '../../instrumented/namespaces.js'; -import * as utilities from '../../instrumented/utilities.js'; -import * as transformlist from '../../instrumented/svgtransformlist.js'; -import * as math from '../../instrumented/math.js'; -import * as path from '../../instrumented/path.js'; -import setAssertionMethods from '../support/assert-close.js'; +import '../../../instrumented/svgpathseg.js'; +import {NS} from '../../../instrumented/namespaces.js'; +import * as utilities from '../../../instrumented/utilities.js'; +import * as transformlist from '../../../instrumented/svgtransformlist.js'; +import * as math from '../../../instrumented/math.js'; +import * as path from '../../../instrumented/path.js'; +import setAssertionMethods from '../../support/assert-close.js'; chai.use(setAssertionMethods); diff --git a/cypress/integration/utilities-performance.js b/cypress/integration/unit/utilities-performance.js similarity index 96% rename from cypress/integration/utilities-performance.js rename to cypress/integration/unit/utilities-performance.js index 0f811498..a23e20ba 100644 --- a/cypress/integration/utilities-performance.js +++ b/cypress/integration/unit/utilities-performance.js @@ -1,10 +1,10 @@ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import '../../instrumented/svgpathseg.js'; -import {NS} from '../../instrumented/namespaces.js'; -import * as utilities from '../../instrumented/utilities.js'; -import * as transformlist from '../../instrumented/svgtransformlist.js'; -import * as math from '../../instrumented/math.js'; +import '../../../instrumented/svgpathseg.js'; +import {NS} from '../../../instrumented/namespaces.js'; +import * as utilities from '../../../instrumented/utilities.js'; +import * as transformlist from '../../../instrumented/svgtransformlist.js'; +import * as math from '../../../instrumented/math.js'; describe('utilities performance', function () { let currentLayer, groupWithMatrixTransform, textWithMatrixTransform; diff --git a/cypress/integration/utilities.js b/cypress/integration/unit/utilities.js similarity index 98% rename from cypress/integration/utilities.js rename to cypress/integration/unit/utilities.js index 69aafd13..417103b7 100644 --- a/cypress/integration/utilities.js +++ b/cypress/integration/unit/utilities.js @@ -1,8 +1,8 @@ -import '../../instrumented/jquery.min.js'; +import '../../../instrumented/jquery.min.js'; -import * as browser from '../../instrumented/browser.js'; -import * as utilities from '../../instrumented/utilities.js'; -import {NS} from '../../instrumented/namespaces.js'; +import * as browser from '../../../instrumented/browser.js'; +import * as utilities from '../../../instrumented/utilities.js'; +import {NS} from '../../../instrumented/namespaces.js'; describe('utilities', function () { /** diff --git a/cypress/support/ui-test-helper.js b/cypress/support/ui-test-helper.js index da1083e5..157a76e1 100644 --- a/cypress/support/ui-test-helper.js +++ b/cypress/support/ui-test-helper.js @@ -3,6 +3,11 @@ export const approveStorage = () => { .click(); }; +export const visitAndApproveStorage = () => { + cy.visit('/instrumented/svg-editor-es.html'); + approveStorage(); +}; + export const openMainMenu = () => { return cy.get('#main_icon').click(); }; @@ -11,3 +16,9 @@ export const openEditorPreferences = () => { openMainMenu(); return cy.get('#tool_prefs_option').click(); }; + +export const selectEnglish = () => { + openEditorPreferences(); + cy.get('#lang_select').select('en'); + cy.get('#tool_prefs_save').click(); +};