File size: 4,568 Bytes
f2bee8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import path from 'path';
import SeleniumHelper from '../helpers/selenium-helper';

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

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

let driver;

describe('Loading scratch gui', () => {
    beforeAll(() => {
        driver = getDriver();
    });

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

    test('Loading project file from computer succeeds, without opening failure alert', async () => {
        await loadUri(uri);
        await clickText('File');
        await clickText('Load from your computer');
        const input = await findByXpath('//input[@accept=".sb,.sb2,.sb3"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/project1.sb3'));
        await findByText('project1-sprite');
        // this test will fail if an alert appears, e.g. in SBFileUploaderHOC's onload() function
    });

    test('Loading project file from computer gives project the filename from file', async () => {
        await loadUri(uri);
        await clickText('File');
        await clickText('Load from your computer');
        const input = await findByXpath('//input[@accept=".sb,.sb2,.sb3"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/project1.sb3'));
        await findByText('project1-sprite');
        await clickXpath('//input[@value="project1"]');
    });

    test('Load sb3 project with a missing svg costume', async () => {
        await loadUri(uri);
        await clickText('File');
        await clickText('Load from your computer');
        const input = await findByXpath('//input[@accept=".sb,.sb2,.sb3"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/missing-sprite-svg.sb3'));
        const spriteTile = await findByText('Blue Square Guy');
        const tileVisible = await spriteTile.isDisplayed();
        expect(tileVisible).toBe(true);
    });

    test('Load sb3 project with an invalid svg costume', async () => {
        await loadUri(uri);
        await clickText('File');
        await clickText('Load from your computer');
        const input = await findByXpath('//input[@accept=".sb,.sb2,.sb3"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/corrupt-svg.sb3'));
        const spriteTile = await findByText('Blue Square Guy');
        const tileVisible = await spriteTile.isDisplayed();
        expect(tileVisible).toBe(true);
    });

    test('Load sb2 project with a missing svg costume', async () => {
        await loadUri(uri);
        await clickText('File');
        await clickText('Load from your computer');
        const input = await findByXpath('//input[@accept=".sb,.sb2,.sb3"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/missing-svg.sb2'));
        const spriteTile = await findByText('Blue Guy');
        const tileVisible = await spriteTile.isDisplayed();
        expect(tileVisible).toBe(true);
    });

    test('Load sb2 project with an invalid svg costume', async () => {
        await loadUri(uri);
        await clickText('File');
        await clickText('Load from your computer');
        const input = await findByXpath('//input[@accept=".sb,.sb2,.sb3"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/corrupt-svg.sb2'));
        const spriteTile = await findByText('Blue Guy');
        const tileVisible = await spriteTile.isDisplayed();
        expect(tileVisible).toBe(true);
    });

    test('Load sb3 project with a missing bmp costume', async () => {
        await loadUri(uri);
        await clickText('File');
        await clickText('Load from your computer');
        const input = await findByXpath('//input[@accept=".sb,.sb2,.sb3"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/missing-bmp.sb3'));
        const spriteTile = await findByText('green-bmp-guy');
        const tileVisible = await spriteTile.isDisplayed();
        expect(tileVisible).toBe(true);
    });

    test('Load sb3 project with an invalid bmp costume', async () => {
        await loadUri(uri);
        await clickText('File');
        await clickText('Load from your computer');
        const input = await findByXpath('//input[@accept=".sb,.sb2,.sb3"]');
        await input.sendKeys(path.resolve(__dirname, '../fixtures/corrupt-bmp.sb3'));
        const spriteTile = await findByText('green-bmp-guy');
        const tileVisible = await spriteTile.isDisplayed();
        expect(tileVisible).toBe(true);
    });
});