File size: 13,500 Bytes
6bcb42f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
import path from 'path';
import SeleniumHelper from '../helpers/selenium-helper';

const {
    clickText,
    clickXpath,
    elementIsVisible,
    findByText,
    findByXpath,
    getDriver,
    getLogs,
    loadUri,
    rightClickText,
    scope
} = new SeleniumHelper();

const uri = path.resolve(__dirname, '../../build/index.html');

let driver;

describe('Working with sprites', () => {
    beforeAll(() => {
        driver = getDriver();
    });

    afterAll(async () => {
        await driver.quit();
    });

    test('Adding a sprite through the library', async () => {
        await loadUri(uri);
        await clickText('Costumes');
        await clickXpath('//button[@aria-label="Choose a Sprite"]');
        await clickText('Apple', scope.modal); // Closes modal
        await rightClickText('Apple', scope.spriteTile); // Make sure it is there
        await clickText('Motion'); // Make sure we are back to the code tab
        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });

    test('Adding a sprite by surprise button', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        await clickXpath('//button[@aria-label="Surprise"]');
        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });

    test('Adding a sprite by paint button', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        await clickXpath('//button[@aria-label="Paint"]');
        await findByText('Convert to Bitmap'); // Make sure we are on the paint editor
        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });

    test('Deleting only sprite does not crash', async () => {
        await loadUri(uri);
        await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
        await rightClickText('Sprite1', scope.spriteTile);
        await clickText('delete', scope.spriteTile);
        // Confirm that the stage has been switched to
        await findByText('Stage selected: no motion blocks');
        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });

    test('Deleting by x button on sprite tile', async () => {
        await loadUri(uri);
        await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
        await clickXpath('//*[@aria-label="Delete"]'); // Only visible close button is on the sprite
        // Confirm that the stage has been switched to
        await findByText('Stage selected: no motion blocks');
        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });

    test('Adding a sprite by uploading a png', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        const input = await findByXpath('//input[@type="file"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/gh-3582-png.png'));
        await clickText('gh-3582-png', scope.spriteTile);
        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });

    // This test fails because uploading an SVG as a sprite changes the scaling
    // Enable when this is fixed issues/3608
    test('Adding a sprite by uploading an svg (gh-3608)', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        const input = await findByXpath('//input[@type="file"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/100-100.svg'));
        await clickText('100-100', scope.spriteTile); // Sprite is named for costume filename

        // Check to make sure the size is right
        await clickText('Costumes');
        await clickText('100-100', scope.costumesTab); // The name of the costume
        await clickText('100 x 100', scope.costumesTab); // The size of the costume
        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });

    test('Adding a sprite by uploading a gif', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        const input = await findByXpath('//input[@type="file"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/paddleball.gif'));
        await clickText('paddleball', scope.spriteTile); // Sprite is named for costume filename

        await clickText('Costumes');
        await findByText('paddleball', scope.costumesTab);
        await findByText('paddleball2', scope.costumesTab);
        await findByText('paddleball3', scope.costumesTab);
        await findByText('paddleball4', scope.costumesTab);
        await findByText('paddleball5', scope.costumesTab);
        await findByText('paddleball6', scope.costumesTab);

        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });

    test('Adding a letter sprite through the Letters filter in the library', async () => {
        await loadUri(uri);
        await driver.manage()
            .window()
            .setSize(1244, 768); // Letters filter not visible at 1024 width
        await clickText('Costumes');
        await clickXpath('//button[@aria-label="Choose a Sprite"]');
        await clickText('Letters');
        await clickText('Block-B', scope.modal); // Closes modal
        await rightClickText('Block-B', scope.spriteTile); // Make sure it is there
        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });

    test('Use browser back button to close library', async () => {
        await driver.get('https://www.google.com');
        await loadUri(uri);
        await clickText('Costumes');
        await clickXpath('//button[@aria-label="Choose a Sprite"]');
        const abbyElement = await findByText('Abby'); // Should show editor for new costume
        await elementIsVisible(abbyElement);
        await driver.navigate().back();
        try {
            // should throw error because library is no longer visible
            await elementIsVisible(abbyElement);
            throw 'ShouldNotGetHere'; // eslint-disable-line no-throw-literal
        } catch (e) {
            expect(e.constructor.name).toEqual('StaleElementReferenceError');
        }
        const costumesElement = await findByText('Costumes'); // Should show editor for new costume
        await elementIsVisible(costumesElement);
        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });

    test('Adding multiple sprites at the same time', async () => {
        const files = [
            path.resolve(__dirname, '../fixtures/gh-3582-png.png'),
            path.resolve(__dirname, '../fixtures/100-100.svg')
        ];
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        const input = await findByXpath('//input[@type="file"]');
        await input.sendKeys(files.join('\n'));

        await findByText('gh-3582-png', scope.spriteTile);
        await findByText('100-100', scope.spriteTile);

        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });

    test('Load a sprite3 with a missing svg costume', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        const input = await findByXpath('//input[@type="file"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/missing-svg.sprite3'));
        const tile = await findByText('Blue Square Guy', scope.spriteTile);
        const tileVisible = await tile.isDisplayed();
        await expect(tileVisible).toBe(true);
    });

    test('Load a sprite3 with a currupt svg costume', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        const input = await findByXpath('//input[@type="file"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/corrupt-svg.sprite3'));
        const tile = await findByText('Blue Square Guy', scope.spriteTile);
        const tileVisible = await tile.isDisplayed();
        await expect(tileVisible).toBe(true);
    });

    test('Load a scratch3 corrupt svg as a sprite', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        const input = await findByXpath('//input[@type="file"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/corrupt-from-scratch3.svg'));
        const tile = await findByText('corrupt-from-scratch3', scope.spriteTile);
        const tileVisible = await tile.isDisplayed();
        await expect(tileVisible).toBe(true);
    });

    test('Load a sprite2 with a missing svg costume', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        const input = await findByXpath('//input[@type="file"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/missing-svg.sprite2'));
        const tile = await findByText('Blue Guy', scope.spriteTile);
        const tileVisible = await tile.isDisplayed();
        await expect(tileVisible).toBe(true);
    });

    test('Load a sprite2 with a currupt svg costume', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        const input = await findByXpath('//input[@type="file"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/corrupted-svg.sprite2'));
        const tile = await findByText('Blue Guy', scope.spriteTile);
        const tileVisible = await tile.isDisplayed();
        await expect(tileVisible).toBe(true);
    });

    test('Load a corrupt scratch2 svg as a sprite', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        const input = await findByXpath('//input[@type="file"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/scratch2-corrupted.svg'));
        const tile = await findByText('scratch2-corrupted', scope.spriteTile);
        const tileVisible = await tile.isDisplayed();
        await expect(tileVisible).toBe(true);
    });

    test('Load a sprite3 with a missing bmp costume', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        const input = await findByXpath('//input[@type="file"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/missing-bmp.sprite3'));
        const tile = await findByText('green-bmp-guy', scope.spriteTile);
        const tileVisible = await tile.isDisplayed();
        await expect(tileVisible).toBe(true);
    });

    test('Load a sprite3 with a currupt bmp costume', async () => {
        await loadUri(uri);
        const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
        await driver.actions().mouseMove(el)
            .perform();
        await driver.sleep(500); // Wait for thermometer menu to come up
        const input = await findByXpath('//input[@type="file"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/corrupt-bmp.sprite3'));
        const tile = await findByText('green-bmp-guy', scope.spriteTile);
        const tileVisible = await tile.isDisplayed();
        await expect(tileVisible).toBe(true);
    });

    // TODO: uploading a corrupt bmp as a sprite should throw an error and not add a gray question mark

});