|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2025 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +import * as chai from 'chai'; |
| 8 | +import { |
| 9 | + blockIsPresent, |
| 10 | + currentFocusIsMainWorkspace, |
| 11 | + setCurrentCursorNodeById, |
| 12 | + getCurrentFocusNodeId, |
| 13 | + getFocusedBlockType, |
| 14 | + moveToToolboxCategory, |
| 15 | + testSetup, |
| 16 | + testFileLocations, |
| 17 | + PAUSE_TIME, |
| 18 | + tabNavigateToWorkspace, |
| 19 | +} from './test_setup.js'; |
| 20 | +import {Key} from 'webdriverio'; |
| 21 | + |
| 22 | +suite('Deleting Blocks', function () { |
| 23 | + // Setting timeout to unlimited as these tests take a longer time to run than most mocha test |
| 24 | + this.timeout(0); |
| 25 | + |
| 26 | + setup(async function () { |
| 27 | + this.browser = await testSetup(testFileLocations.NAVIGATION_TEST_BLOCKS); |
| 28 | + await this.browser.pause(PAUSE_TIME); |
| 29 | + }); |
| 30 | + |
| 31 | + test('Deleting block selects previous connection', async function () { |
| 32 | + await tabNavigateToWorkspace(this.browser); |
| 33 | + await this.browser.pause(PAUSE_TIME); |
| 34 | + await setCurrentCursorNodeById(this.browser, 'controls_if_2'); |
| 35 | + await this.browser.pause(PAUSE_TIME); |
| 36 | + |
| 37 | + chai |
| 38 | + .expect(await blockIsPresent(this.browser, 'controls_if_2')) |
| 39 | + .equal(true); |
| 40 | + |
| 41 | + await this.browser.keys(Key.Backspace); |
| 42 | + await this.browser.pause(PAUSE_TIME); |
| 43 | + |
| 44 | + chai |
| 45 | + .expect(await blockIsPresent(this.browser, 'controls_if_2')) |
| 46 | + .equal(false); |
| 47 | + |
| 48 | + chai |
| 49 | + .expect(await getCurrentFocusNodeId(this.browser)) |
| 50 | + .to.include('controls_if_1_connection_'); |
| 51 | + }); |
| 52 | + |
| 53 | + test('Cutting block selects previous connection', async function () { |
| 54 | + await tabNavigateToWorkspace(this.browser); |
| 55 | + await this.browser.pause(PAUSE_TIME); |
| 56 | + await setCurrentCursorNodeById(this.browser, 'controls_if_2'); |
| 57 | + await this.browser.pause(PAUSE_TIME); |
| 58 | + |
| 59 | + chai |
| 60 | + .expect(await blockIsPresent(this.browser, 'controls_if_2')) |
| 61 | + .equal(true); |
| 62 | + |
| 63 | + await this.browser.keys([Key.Ctrl, 'x']); |
| 64 | + await this.browser.pause(PAUSE_TIME); |
| 65 | + |
| 66 | + chai |
| 67 | + .expect(await blockIsPresent(this.browser, 'controls_if_2')) |
| 68 | + .equal(false); |
| 69 | + |
| 70 | + chai |
| 71 | + .expect(await getCurrentFocusNodeId(this.browser)) |
| 72 | + .to.include('controls_if_1_connection_'); |
| 73 | + }); |
| 74 | + |
| 75 | + test('Deleting block also deletes children and inputs', async function () { |
| 76 | + await tabNavigateToWorkspace(this.browser); |
| 77 | + await this.browser.pause(PAUSE_TIME); |
| 78 | + await setCurrentCursorNodeById(this.browser, 'controls_if_2'); |
| 79 | + await this.browser.pause(PAUSE_TIME); |
| 80 | + |
| 81 | + chai |
| 82 | + .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) |
| 83 | + .equal(true); |
| 84 | + chai.expect(await blockIsPresent(this.browser, 'text_print_1')).equal(true); |
| 85 | + |
| 86 | + await this.browser.keys(Key.Backspace); |
| 87 | + await this.browser.pause(PAUSE_TIME); |
| 88 | + |
| 89 | + chai |
| 90 | + .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) |
| 91 | + .equal(false); |
| 92 | + chai |
| 93 | + .expect(await blockIsPresent(this.browser, 'text_print_1')) |
| 94 | + .equal(false); |
| 95 | + }); |
| 96 | + |
| 97 | + test('Cutting block also removes children and inputs', async function () { |
| 98 | + await tabNavigateToWorkspace(this.browser); |
| 99 | + await this.browser.pause(PAUSE_TIME); |
| 100 | + await setCurrentCursorNodeById(this.browser, 'controls_if_2'); |
| 101 | + await this.browser.pause(PAUSE_TIME); |
| 102 | + |
| 103 | + chai |
| 104 | + .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) |
| 105 | + .equal(true); |
| 106 | + chai.expect(await blockIsPresent(this.browser, 'text_print_1')).equal(true); |
| 107 | + |
| 108 | + await this.browser.keys([Key.Ctrl, 'x']); |
| 109 | + await this.browser.pause(PAUSE_TIME); |
| 110 | + |
| 111 | + chai |
| 112 | + .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) |
| 113 | + .equal(false); |
| 114 | + chai |
| 115 | + .expect(await blockIsPresent(this.browser, 'text_print_1')) |
| 116 | + .equal(false); |
| 117 | + }); |
| 118 | + |
| 119 | + test('Deleting inline input selects parent connection', async function () { |
| 120 | + await tabNavigateToWorkspace(this.browser); |
| 121 | + await this.browser.pause(PAUSE_TIME); |
| 122 | + await setCurrentCursorNodeById(this.browser, 'logic_boolean_1'); |
| 123 | + await this.browser.pause(PAUSE_TIME); |
| 124 | + |
| 125 | + chai |
| 126 | + .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) |
| 127 | + .equal(true); |
| 128 | + |
| 129 | + await this.browser.keys(Key.Backspace); |
| 130 | + await this.browser.pause(PAUSE_TIME); |
| 131 | + |
| 132 | + chai |
| 133 | + .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) |
| 134 | + .equal(false); |
| 135 | + |
| 136 | + chai |
| 137 | + .expect(await getCurrentFocusNodeId(this.browser)) |
| 138 | + .to.include('controls_if_2_connection_'); |
| 139 | + }); |
| 140 | + |
| 141 | + test('Cutting inline input selects parent connection', async function () { |
| 142 | + await tabNavigateToWorkspace(this.browser); |
| 143 | + await this.browser.pause(PAUSE_TIME); |
| 144 | + await setCurrentCursorNodeById(this.browser, 'logic_boolean_1'); |
| 145 | + await this.browser.pause(PAUSE_TIME); |
| 146 | + |
| 147 | + chai |
| 148 | + .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) |
| 149 | + .equal(true); |
| 150 | + |
| 151 | + await this.browser.keys([Key.Ctrl, 'x']); |
| 152 | + await this.browser.pause(PAUSE_TIME); |
| 153 | + |
| 154 | + chai |
| 155 | + .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) |
| 156 | + .equal(false); |
| 157 | + |
| 158 | + chai |
| 159 | + .expect(await getCurrentFocusNodeId(this.browser)) |
| 160 | + .to.include('controls_if_2_connection_'); |
| 161 | + }); |
| 162 | + |
| 163 | + test('Deleting stranded block selects workspace', async function () { |
| 164 | + await tabNavigateToWorkspace(this.browser); |
| 165 | + await this.browser.pause(PAUSE_TIME); |
| 166 | + |
| 167 | + // The test workspace doesn't already contain a stranded block, so add one. |
| 168 | + await moveToToolboxCategory(this.browser, 'Math'); |
| 169 | + await this.browser.pause(PAUSE_TIME); |
| 170 | + // Move to flyout. |
| 171 | + await this.browser.keys(Key.ArrowRight); |
| 172 | + await this.browser.pause(PAUSE_TIME); |
| 173 | + // Select number block. |
| 174 | + await this.browser.keys(Key.Enter); |
| 175 | + await this.browser.pause(PAUSE_TIME); |
| 176 | + // Confirm move. |
| 177 | + await this.browser.keys(Key.Enter); |
| 178 | + await this.browser.pause(PAUSE_TIME); |
| 179 | + |
| 180 | + chai.assert.equal('math_number', await getFocusedBlockType(this.browser)); |
| 181 | + |
| 182 | + await this.browser.keys(Key.Backspace); |
| 183 | + await this.browser.pause(PAUSE_TIME); |
| 184 | + |
| 185 | + chai.expect(await currentFocusIsMainWorkspace(this.browser)).equal(true); |
| 186 | + }); |
| 187 | + |
| 188 | + test('Cutting stranded block selects workspace', async function () { |
| 189 | + await tabNavigateToWorkspace(this.browser); |
| 190 | + await this.browser.pause(PAUSE_TIME); |
| 191 | + |
| 192 | + // The test workspace doesn't already contain a stranded block, so add one. |
| 193 | + await moveToToolboxCategory(this.browser, 'Math'); |
| 194 | + await this.browser.pause(PAUSE_TIME); |
| 195 | + // Move to flyout. |
| 196 | + await this.browser.keys(Key.ArrowRight); |
| 197 | + await this.browser.pause(PAUSE_TIME); |
| 198 | + // Select number block. |
| 199 | + await this.browser.keys(Key.Enter); |
| 200 | + await this.browser.pause(PAUSE_TIME); |
| 201 | + // Confirm move. |
| 202 | + await this.browser.keys(Key.Enter); |
| 203 | + await this.browser.pause(PAUSE_TIME); |
| 204 | + |
| 205 | + chai.assert.equal('math_number', await getFocusedBlockType(this.browser)); |
| 206 | + |
| 207 | + await this.browser.keys([Key.Ctrl, 'x']); |
| 208 | + await this.browser.pause(PAUSE_TIME); |
| 209 | + |
| 210 | + chai.expect(await currentFocusIsMainWorkspace(this.browser)).equal(true); |
| 211 | + }); |
| 212 | +}); |
0 commit comments