File size: 6,832 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
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
import path from 'path';
import SeleniumHelper from '../helpers/selenium-helper';
import {Key} from 'selenium-webdriver';

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

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

let driver;

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

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

    test('Adding a sound through the library', async () => {
        await loadUri(uri);
        await clickText('Sounds');

        // Delete the sound
        await rightClickText('Meow', scope.soundsTab);
        await driver.sleep(500); // Wait a moment for context menu; only needed for local testing
        await clickText('delete', scope.soundsTab);

        // Add it back
        await clickXpath('//button[@aria-label="Choose a Sound"]');
        let el = await findByXpath("//input[@placeholder='Search']");
        await el.sendKeys('meow');
        await clickText('Meow', scope.modal); // Should close the modal

        // Add a new sound
        await clickXpath('//button[@aria-label="Choose a Sound"]');
        el = await findByXpath("//input[@placeholder='Search']");
        await el.sendKeys('chom');
        await clickText('Chomp'); // Should close the modal, then click the sounds in the selector
        await findByXpath("//input[@value='Chomp']"); // Should show editor for new sound

        await clickXpath('//button[@title="Play"]');

        await clickText('Louder');
        await clickText('Softer');
        await clickText('Faster');
        await clickText('Slower');
        await clickText('Robot');
        await clickText('Reverse');

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

    test('Adding a sound by surprise button', async () => {
        await loadUri(uri);
        await clickText('Sounds');
        const el = await findByXpath('//button[@aria-label="Choose a Sound"]');
        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('Duplicating a sound', async () => {
        await loadUri(uri);
        await clickText('Sounds');

        await rightClickText('Meow', scope.soundsTab);
        await clickText('duplicate', scope.soundsTab);
        await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for error

        // Make sure the duplicated sound is named correctly.
        await clickText('Meow2', scope.soundsTab);

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

    // Regression test for gui issue #1320
    test('Switching sprites with different numbers of sounds', async () => {
        await loadUri(uri);

        // Add a sound so this sprite has 2 sounds.
        await clickText('Sounds');
        await clickXpath('//button[@aria-label="Choose a Sound"]');
        await clickText('A Bass'); // Closes the modal

        // Now add a sprite with only one sound.
        await clickXpath('//button[@aria-label="Choose a Sprite"]');
        await clickText('Abby'); // Doing this used to crash the editor.

        await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for error

        // Make sure the 'Oops' screen is not visible
        const content = await driver.getPageSource();
        expect(content.indexOf('Oops')).toEqual(-1);

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

    test('Adding multiple sounds at the same time', async () => {
        const files = [
            path.resolve(__dirname, '../fixtures/movie.wav'),
            path.resolve(__dirname, '../fixtures/sneaker.wav')
        ];
        await loadUri(uri);
        await clickText('Sounds');
        const el = await findByXpath('//button[@aria-label="Choose a Sound"]');
        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('movie', scope.soundsTab);
        await findByText('sneaker', scope.soundsTab);

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

    test('Copy to new button adds a new sound', async () => {
        await loadUri(uri);
        await clickText('Sounds');
        await clickText('Copy to New', scope.soundsTab);
        await clickText('Meow2', scope.soundsTab);

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

    test('Copy and pasting within a sound changes its duration', async () => {
        await loadUri(uri);
        await clickText('Sounds');
        await findByText('0.85', scope.soundsTab); // Original meow sound duration
        await clickText('Copy', scope.soundsTab);
        await clickText('Paste', scope.soundsTab);
        await findByText('1.70', scope.soundsTab); // Sound has doubled in duration

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

    test('Can copy a sound from a sprite and paste into a sound on the stage', async () => {
        await loadUri(uri);
        await clickText('Sounds');
        await clickText('Copy', scope.soundsTab); // Copy the meow sound
        await clickXpath('//span[text()="Stage"]');
        await findByText('0.02', scope.soundsTab); // Original pop sound duration
        await clickText('Paste', scope.soundsTab);
        await findByText('0.87', scope.soundsTab); // Duration of pop + meow sound

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

    test('Keyboard shortcuts', async () => {
        await loadUri(uri);
        await clickText('Sounds');
        const el = await findByXpath('//button[@aria-label="Choose a Sound"]');
        await el.sendKeys(Key.chord(Key.COMMAND, 'a')); // Select all
        await findByText('0.85', scope.soundsTab); // Meow sound duration
        await el.sendKeys(Key.DELETE);
        await findByText('0.00', scope.soundsTab); // Sound is now empty
        await el.sendKeys(Key.chord(Key.COMMAND, 'z')); // undo
        await findByText('0.85', scope.soundsTab); // Meow sound is back
        await el.sendKeys(Key.chord(Key.COMMAND, Key.SHIFT, 'z')); // redo
        await findByText('0.00', scope.soundsTab); // Sound is empty again

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