diff --git a/cypress/fixtures/test.png b/cypress/fixtures/test.png new file mode 100644 index 0000000..d05e470 Binary files /dev/null and b/cypress/fixtures/test.png differ diff --git a/cypress/integration/menus/image.spec.ts b/cypress/integration/menus/image.spec.ts new file mode 100644 index 0000000..f335d85 --- /dev/null +++ b/cypress/integration/menus/image.spec.ts @@ -0,0 +1,28 @@ +import Editor from '../../../src/editor' + +describe('菜单-图片', () => { + + beforeEach(() => { + cy.visit('http://localhost:3000/canvas-editor/') + + cy.get('canvas').first().as('canvas').should('have.length', 1) + }) + + it('图片', () => { + cy.getEditor().then((editor: Editor) => { + editor.listener.saved = function (payload) { + const data = payload.data + expect(data[0].type).to.eq('image') + } + + editor.command.executeSelectAll() + + editor.command.executeBackspace() + + cy.get('#image').attachFile('test.png') + + cy.get('@canvas').type('{ctrl}s') + }) + }) + +}) diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index f3ce3ab..7750cea 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -1,3 +1,5 @@ +import 'cypress-file-upload' + Cypress.Commands.add('getEditor', () => { return cy.window().its('editor') }) \ No newline at end of file diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json index 7416749..3ec51fd 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "es5", "lib": ["es2015", "dom", "esnext"], - "types": ["cypress"], + "types": ["cypress", "cypress-file-upload"], "isolatedModules": false, "allowJs": true, "noEmit": true, diff --git a/package.json b/package.json index 7867601..3a71a2c 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "@types/node": "^16.11.12", "@types/prismjs": "^1.26.0", "cypress": "^9.5.1", + "cypress-file-upload": "^5.0.8", "typescript": "^4.3.2", "vite": "^2.4.2" }, diff --git a/yarn.lock b/yarn.lock index f79deb9..cddcca7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -313,6 +313,11 @@ cross-spawn@^7.0.0: shebang-command "^2.0.0" which "^2.0.1" +cypress-file-upload@^5.0.8: + version "5.0.8" + resolved "https://registry.yarnpkg.com/cypress-file-upload/-/cypress-file-upload-5.0.8.tgz#d8824cbeaab798e44be8009769f9a6c9daa1b4a1" + integrity sha512-+8VzNabRk3zG6x8f8BWArF/xA/W0VK4IZNx3MV0jFWrJS/qKn8eHfa5nU73P9fOQAgwHFJx7zjg4lwOnljMO8g== + cypress@^9.5.1: version "9.5.1" resolved "https://registry.yarnpkg.com/cypress/-/cypress-9.5.1.tgz#51162f3688cedf5ffce311b914ef49a7c1ece076"