From 974ecba1b4bf88468c0a705389c3ab1881a97429 Mon Sep 17 00:00:00 2001 From: tams sokari Date: Fri, 3 Nov 2023 14:06:43 +0100 Subject: [PATCH] fix(SmartCameraWeb): add image test, show an error message when test fails (#120) * fix: count colors in images, and show an error message * build: add correct version * fix: fix lint errors * redesign: use `enable-image-tests` to configure tests * workflows: deploy files and not folders for smart-camera-web * lint: remove global rule and disable-next-line for no-bitwise * redesign: test by default, do not test on `disable-image-tests` attribute * tests: disable-image-tests on default test files * docs: update version in README.md * redesign: change error message for image tests * tests: add test for image-tests functionality * refactor: make hasMoreThanNColors a top level function * fix: fix lint errors * refactor: address PR feedback, use dedicated screen for failed-image-test * redesign: add image, copy for failed image test screen * copy: update failed-image-test copy * assets: change icon for failed-image-test * version: bump embed version * tests: disable image tests for smart-camera-web --- packages/components/README.md | 2 +- .../components/cypress/e2e/image-tests.cy.js | 51 ++++++++++ .../capture-back-of-id-hide-attribution.html | 1 + .../pages/capture-back-of-id-navigation.html | 2 +- .../pages/capture-back-of-id-portrait.html | 1 + .../cypress/pages/capture-back-of-id.html | 1 + .../pages/capture-id-hide-back-to-host.html | 1 + .../cypress/pages/capture-id-portrait.html | 1 + .../components/cypress/pages/capture-id.html | 1 + .../cypress/pages/document-upload.html | 1 + .../components/cypress/pages/image-tests.html | 73 ++++++++++++++ packages/components/cypress/pages/index.html | 2 +- packages/components/package.json | 2 +- packages/components/smart-camera-web.js | 98 +++++++++++++++---- packages/embed/cypress/support/commands.js | 6 ++ packages/embed/package.json | 2 +- 16 files changed, 220 insertions(+), 25 deletions(-) create mode 100644 packages/components/cypress/e2e/image-tests.cy.js create mode 100644 packages/components/cypress/pages/image-tests.html diff --git a/packages/components/README.md b/packages/components/README.md index d87b845d..1a693528 100644 --- a/packages/components/README.md +++ b/packages/components/README.md @@ -52,7 +52,7 @@ import '@smile_identity/smart-camera-web' For instance: ```html - + ``` ### Usage diff --git a/packages/components/cypress/e2e/image-tests.cy.js b/packages/components/cypress/e2e/image-tests.cy.js new file mode 100644 index 00000000..0fe4fac2 --- /dev/null +++ b/packages/components/cypress/e2e/image-tests.cy.js @@ -0,0 +1,51 @@ +// smart-camera-web.spec.js created with Cypress +// +// Start writing your Cypress tests below! +// If you're unfamiliar with how Cypress works, +// check out the link below and learn how to write your first test: +// https://on.cypress.io/writing-first-test +context('SmartCameraWeb - Image Tests', () => { + beforeEach(() => { + cy.visit('/image-tests'); + }); + + it('should show an error message when image is unusable', () => { + cy + .get('smart-camera-web') + .shadow() + .find('#request-camera-access') + .click(); + + cy + .get('smart-camera-web') + .shadow() + .find('#start-image-capture') + .click(); + + cy + .wait(8000); + + cy + .get('smart-camera-web') + .shadow() + .find('#camera-screen') + .should('not.be.visible'); + + cy + .get('smart-camera-web') + .shadow() + .find('#review-screen') + .should('not.be.visible'); + + cy + .get('smart-camera-web') + .shadow() + .find('#failed-image-test-screen') + .should('be.visible'); + + cy.get('smart-camera-web') + .shadow() + .find('#failed-image-test-screen p') + .should('contain.text', 'Device not supported'); + }); +}); diff --git a/packages/components/cypress/pages/capture-back-of-id-hide-attribution.html b/packages/components/cypress/pages/capture-back-of-id-hide-attribution.html index fe47ba35..a5c3afde 100644 --- a/packages/components/cypress/pages/capture-back-of-id-hide-attribution.html +++ b/packages/components/cypress/pages/capture-back-of-id-hide-attribution.html @@ -28,6 +28,7 @@ diff --git a/packages/components/cypress/pages/capture-back-of-id-navigation.html b/packages/components/cypress/pages/capture-back-of-id-navigation.html index 0805bcbb..06819973 100644 --- a/packages/components/cypress/pages/capture-back-of-id-navigation.html +++ b/packages/components/cypress/pages/capture-back-of-id-navigation.html @@ -51,7 +51,7 @@ - + diff --git a/packages/components/cypress/pages/capture-back-of-id-portrait.html b/packages/components/cypress/pages/capture-back-of-id-portrait.html index 201de117..4eed7a6f 100644 --- a/packages/components/cypress/pages/capture-back-of-id-portrait.html +++ b/packages/components/cypress/pages/capture-back-of-id-portrait.html @@ -28,6 +28,7 @@ diff --git a/packages/components/cypress/pages/capture-back-of-id.html b/packages/components/cypress/pages/capture-back-of-id.html index 821d0ff9..6a6528bd 100644 --- a/packages/components/cypress/pages/capture-back-of-id.html +++ b/packages/components/cypress/pages/capture-back-of-id.html @@ -27,6 +27,7 @@ diff --git a/packages/components/cypress/pages/capture-id-hide-back-to-host.html b/packages/components/cypress/pages/capture-id-hide-back-to-host.html index 3de1642d..4f7f01fd 100644 --- a/packages/components/cypress/pages/capture-id-hide-back-to-host.html +++ b/packages/components/cypress/pages/capture-id-hide-back-to-host.html @@ -28,6 +28,7 @@ diff --git a/packages/components/cypress/pages/capture-id-portrait.html b/packages/components/cypress/pages/capture-id-portrait.html index 57a92b0a..36fdf5f8 100644 --- a/packages/components/cypress/pages/capture-id-portrait.html +++ b/packages/components/cypress/pages/capture-id-portrait.html @@ -28,6 +28,7 @@ diff --git a/packages/components/cypress/pages/capture-id.html b/packages/components/cypress/pages/capture-id.html index f9fbef33..6c203ba5 100644 --- a/packages/components/cypress/pages/capture-id.html +++ b/packages/components/cypress/pages/capture-id.html @@ -27,6 +27,7 @@ diff --git a/packages/components/cypress/pages/document-upload.html b/packages/components/cypress/pages/document-upload.html index 821d0ff9..6a6528bd 100644 --- a/packages/components/cypress/pages/document-upload.html +++ b/packages/components/cypress/pages/document-upload.html @@ -27,6 +27,7 @@ diff --git a/packages/components/cypress/pages/image-tests.html b/packages/components/cypress/pages/image-tests.html new file mode 100644 index 00000000..624e6bb0 --- /dev/null +++ b/packages/components/cypress/pages/image-tests.html @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + diff --git a/packages/components/cypress/pages/index.html b/packages/components/cypress/pages/index.html index 624e6bb0..d50c65e3 100644 --- a/packages/components/cypress/pages/index.html +++ b/packages/components/cypress/pages/index.html @@ -51,7 +51,7 @@ - + diff --git a/packages/components/package.json b/packages/components/package.json index f00a4590..6e4bddee 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -1,6 +1,6 @@ { "name": "@smile_identity/smart-camera-web", - "version": "1.0.1", + "version": "1.0.2", "description": "WebComponent for smartly capturing images on the web, for use with SmileIdentity", "main": "smart-camera-web.js", "scripts": { diff --git a/packages/components/smart-camera-web.js b/packages/components/smart-camera-web.js index 4522809a..89b1957d 100644 --- a/packages/components/smart-camera-web.js +++ b/packages/components/smart-camera-web.js @@ -1,4 +1,4 @@ -const VERSION = '1.0.0-beta.23'; +const VERSION = '1.0.2'; const DEFAULT_NO_OF_LIVENESS_FRAMES = 8; const PORTRAIT_ID_PREVIEW_WIDTH = 396; const PORTRAIT_ID_PREVIEW_HEIGHT = 527; @@ -695,6 +695,28 @@ function scwTemplateString() { + + +