|
| 1 | +describe('Flow-Playground frontend tests', () => { |
| 2 | + const DEPLOY_BUTTON = '[data-test="deploy-button"]'; |
| 3 | + const EXECUTE = '[data-test="execute-button"]'; |
| 4 | + const SEND_BUTTON = '[data-test="send-button"]'; |
| 5 | + const ACCOUNTS_LIST = '[data-test="account-list"]'; |
| 6 | + const MONACO_EDITOR = '.monaco-editor textarea:first'; |
| 7 | + const STATUS_MESSAGE = '[data-test="control-panel-status-message"]'; |
| 8 | + const selectAllKeys = Cypress.platform == 'darwin' ? '{cmd}a' : '{ctrl}a'; |
| 9 | + |
| 10 | + beforeEach(() => { |
| 11 | + cy.visit('/'); |
| 12 | + }); |
| 13 | + |
| 14 | + it('deploys a contract', () => { |
| 15 | + cy.get(ACCOUNTS_LIST).children().should('have.length', 5).first().click(); |
| 16 | + cy.get(DEPLOY_BUTTON).should('have.text', 'Deploy').click(); |
| 17 | + cy.get(STATUS_MESSAGE).should('have.text', 'Please wait...'); |
| 18 | + cy.get(DEPLOY_BUTTON).should('have.text', 'Redeploy'); |
| 19 | + cy.get('[data-test="CONTRACT-response"]').should( |
| 20 | + 'include.text', |
| 21 | + 'Deployed Contract To: 0x01', |
| 22 | + ); |
| 23 | + }); |
| 24 | + |
| 25 | + it('sends a transaction', () => { |
| 26 | + cy.get('[data-test="sidebar-Transaction"]').click(); |
| 27 | + cy.get('[data-test="editor-heading"]').should( |
| 28 | + 'include.text', |
| 29 | + 'Transaction Template', |
| 30 | + ); |
| 31 | + // Ensure action button is disabled when contract not deployed yet |
| 32 | + cy.get(SEND_BUTTON).should('be.disabled'); |
| 33 | + |
| 34 | + // deploy contract |
| 35 | + cy.get(ACCOUNTS_LIST).children().first().click(); |
| 36 | + cy.get(DEPLOY_BUTTON).should('have.text', 'Deploy').click(); |
| 37 | + cy.get(DEPLOY_BUTTON).should('have.text', 'Redeploy'); |
| 38 | + |
| 39 | + // open transaction template and successfully send transaction |
| 40 | + cy.get('[data-test="sidebar-Transaction"]').click(); |
| 41 | + cy.get(SEND_BUTTON) |
| 42 | + .should('have.text', 'Send') |
| 43 | + .should('be.enabled') |
| 44 | + .click(); |
| 45 | + cy.get('[data-test="TRANSACTION-response"]').should( |
| 46 | + 'include.text', |
| 47 | + 'Hello, World!', |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + it('executes a script', () => { |
| 52 | + cy.get('[data-test="sidebar-Script"]').click(); |
| 53 | + cy.get('[data-test="editor-heading"]').should( |
| 54 | + 'include.text', |
| 55 | + 'Script Template', |
| 56 | + ); |
| 57 | + cy.get(EXECUTE).should('have.text', 'Execute').click(); |
| 58 | + cy.get('[data-test="SCRIPT-response"]').should( |
| 59 | + 'include.text', |
| 60 | + '{"type":"Int","value":"1"}', |
| 61 | + ); |
| 62 | + }); |
| 63 | + |
| 64 | + it('reflects changes to imported contract after contract has been redeployed', () => { |
| 65 | + // deploy contract |
| 66 | + cy.get(ACCOUNTS_LIST).children().first().click(); |
| 67 | + cy.get(DEPLOY_BUTTON).should('have.text', 'Deploy').click(); |
| 68 | + cy.get(STATUS_MESSAGE).should('have.text', 'Please wait...'); |
| 69 | + cy.get(DEPLOY_BUTTON).should('have.text', 'Redeploy'); |
| 70 | + cy.get('[data-test="CONTRACT-response"]').should( |
| 71 | + 'include.text', |
| 72 | + 'Deployed Contract To: 0x01', |
| 73 | + ); |
| 74 | + |
| 75 | + // open transaction template and successfully send transaction |
| 76 | + cy.get('[data-test="sidebar-Transaction"]').click(); |
| 77 | + cy.get(SEND_BUTTON) |
| 78 | + .should('have.text', 'Send') |
| 79 | + .should('be.enabled') |
| 80 | + .click(); |
| 81 | + cy.get('[data-test="TRANSACTION-response"]').should( |
| 82 | + 'include.text', |
| 83 | + 'Hello, World!', |
| 84 | + ); |
| 85 | + |
| 86 | + // edit contract |
| 87 | + cy.get(ACCOUNTS_LIST).children().first().click(); |
| 88 | + cy.get(MONACO_EDITOR).click().focused().type(selectAllKeys).clear(); |
| 89 | + cy.get(MONACO_EDITOR).should('be.empty'); |
| 90 | + cy.get(DEPLOY_BUTTON).should('be.disabled'); |
| 91 | + cy.get(MONACO_EDITOR) |
| 92 | + .click() |
| 93 | + .focused() |
| 94 | + .type( |
| 95 | + 'access(all) contract HelloWorld { access(all) let greeting: String init() { self.greeting = "Hello, Other World!" } access(all) fun other_hello(): String {return self.greeting}}', |
| 96 | + { parseSpecialCharSequences: false }, |
| 97 | + ); |
| 98 | + cy.get(DEPLOY_BUTTON).should('be.enabled'); |
| 99 | + cy.get(DEPLOY_BUTTON).should('have.text', 'Redeploy').click(); |
| 100 | + cy.get('[data-test="redeploy-confirm-button"]').should('exist').click(); |
| 101 | + cy.get(STATUS_MESSAGE).should('have.text', 'Please wait...'); |
| 102 | + cy.get(DEPLOY_BUTTON).should('have.text', 'Redeploy'); |
| 103 | + cy.get(DEPLOY_BUTTON).should('be.enabled'); |
| 104 | + |
| 105 | + // select and edit transaction |
| 106 | + cy.get('[data-test="sidebar-Transaction"]').click(); |
| 107 | + cy.get(SEND_BUTTON).should('have.text', 'Send').should('be.disabled'); |
| 108 | + cy.get(MONACO_EDITOR) |
| 109 | + .click() |
| 110 | + .focused() |
| 111 | + .type(selectAllKeys) |
| 112 | + .type( |
| 113 | + 'import HelloWorld from 0x01 transaction { prepare(acct: AuthAccount) {} execute { log(HelloWorld.other_hello())}}', |
| 114 | + { parseSpecialCharSequences: false }, |
| 115 | + ); |
| 116 | + |
| 117 | + // successfully send transaction |
| 118 | + cy.get(SEND_BUTTON) |
| 119 | + .should('have.text', 'Send') |
| 120 | + .should('be.enabled') |
| 121 | + .click(); |
| 122 | + cy.get('[data-test="transaction-result"]').should( |
| 123 | + 'include.text', |
| 124 | + 'Hello, Other World!', |
| 125 | + ); |
| 126 | + }); |
| 127 | +}); |
0 commit comments