describe('findTopLevel', () => { test('should return level 1', () => { expect(findTopLevel([{ level: 1 }, { level: 2 }])).toBe(1); }); test('should be undefined', () => { expect(findTopLevel([])).toBeUndefined(); }); });
describe('options.initial', () => { it('should use value defined on options.initial', () => { prompt = new Prompt({ message: 'Favorite color?', initial: 'blue', show: false }); prompt.once('run', () => prompt.submit()); return prompt.run() .then(value => { assert.equal(value, 'blue'); }); }); });
describe( 'Can Log Out', function () { this.timeout( 30000 ); step( 'Can view profile to log out', async function () { const navbarComponent = await NavBarComponent.Expect( driver ); return await navbarComponent.clickProfileLink(); } ); step( 'Can logout from profile page', async function () { const profilePage = await ProfilePage.Expect( driver ); return await profilePage.clickSignOut(); } ); step( 'Can see app login page after logging out', async function () { return await LoginPage.Expect( driver ); } ); } );
describe('prompts', function() { it('should export prompts', () => { assert.equal(typeof prompts.AutoComplete, 'function'); assert.equal(typeof prompts.Confirm, 'function'); assert.equal(typeof prompts.Input, 'function'); assert.equal(typeof prompts.Invisible, 'function'); assert.equal(typeof prompts.List, 'function'); assert.equal(typeof prompts.MultiSelect, 'function'); assert.equal(typeof prompts.Numeral, 'function'); assert.equal(typeof prompts.Password, 'function'); assert.equal(typeof prompts.Select, 'function'); assert.equal(typeof prompts.Text, 'function'); }); it('should export types', () => { assert.equal(typeof types.ArrayPrompt, 'function'); assert.equal(typeof types.BooleanPrompt, 'function'); assert.equal(typeof types.NumberPrompt, 'function'); assert.equal(typeof types.StringPrompt, 'function'); }); });
describe('Scroll Test', () => { sizes.forEach(size => { it(`scroll to top when accessing new page on ${size}`, () => { cy.viewport(size); cy.visit('/guides/getting-started'); // scroll to Contributors section cy.get('.contributors__section').scrollIntoView(); cy.isNotInViewport('#basic-setup'); cy.visit('/guides/build-performance/'); cy.isNotInViewport('.contributors__section'); }); it(`scroll to fragment when accessing new page with fragment on ${size}`, () => { cy.viewport(size); cy.visit('/guides/getting-started'); cy.get('.contributors__section').scrollIntoView(); cy.visit('/guides/build-performance/#development'); cy.isInViewport('#development'); cy.isNotInViewport('#general'); }); }); });
describe( 'check app loads', function () { it( 'should have calypso in DOM', function () { return new Promise( ( done ) => { // eslint-disable-line jest/no-test-callback boot( function ( mainWindow ) { // We need to wait for the page to load before sending the request mainWindow.webContents.on( 'did-finish-load', function () { mainWindow.webContents.send( 'is-calypso' ); } ); ipcMain.on( 'is-calypso-response', function ( ev, value ) { expect( value ).to.be.true; done(); } ); } ); } ); } ); } );
describe( 'User Can log in', function () { this.timeout( 30000 ); step( 'Clear local storage', async function () { await driver.executeScript( 'window.localStorage.clear();' ); return await driver.sleep( 3000 ); } ); step( 'Can log in', async function () { const loginPage = await LoginPage.Expect( driver ); return await loginPage.login( process.env.E2EGUTENBERGUSER, process.env.E2EPASSWORD ); } ); step( 'Can see Reader Page after logging in', async function () { await ReaderPage.Expect( driver ); return ( loggedInUrl = await driver.getCurrentUrl() ); } ); } );
describe('child_process', function() { it('should works in child_process', cb => { let cmd = fork(path.resolve(__dirname, './support/child_process.js'), [], { silent: true, }); let stdout = ''; let stderr = ''; cmd.stdout.on('data', buf => { let data = buf.toString(); stdout += data; if (data.includes('color')) cmd.stdin.write('orange\n'); }); cmd.stderr.on('data', buf => { stderr += buf.toString(); }); cmd.on('close', () => { assert(!stderr); assert(stdout.includes('color: \'orange\'')); cb(); }); }); });
describe('options.min', () => { it('should set prompt.min with options.min', () => { prompt = new Prompt({ message: 'prompt-number', initial: 15, min: 10 }); assert.equal(prompt.min, 10); prompt.once('run', () => prompt.submit()); return prompt.run() .then(answer => { assert.equal(answer, 15); }); }); });
describe('prompt.reset', () => { it('should reset to initial state', () => { prompt = new Prompt({ message: 'Favorite flavor?', choices: fixtures.slice(), suggest(typed, choices = []) { return choices.filter(choice => choice.message.includes(typed)); } }); prompt.once('run', async() => { await prompt.keypress('b'); await prompt.keypress('e'); await prompt.keypress('r'); await prompt.keypress('r'); await prompt.keypress('y'); await prompt.submit(); }); return prompt.run() .then(answer => { assert.equal(answer, 'strawberry'); }); }); });
describe('inheritance', () => { it('should support inheritance', cb => { class Custom extends Enquirer {} const { prompt } = Custom; prompt.on('prompt', p => { p.value = 'orange'; p.submit(); }); prompt({ type: 'input', name: 'color', message: 'Favorite color?', show: false }) .then(answers => { assert.equal(answers.color, 'orange'); cb(); }); }); });
describe('options.autofill', () => { it('should autofill answers', () => { enquirer = new Enquirer({ show: false, autofill: true }, { color: 'orange' }); return enquirer.prompt({ type: 'input', name: 'color', message: 'Favorite color?' }) .then(answers => { assert.equal(answers.color, 'orange'); }); }); });
describe('options.result', () => { it('should support options.result', () => { prompt = new Prompt({ message: 'Favorite color?', show: false, initial: 'blue', result(value) { return value.toUpperCase(); } }); prompt.once('run', () => prompt.submit()); return prompt.run() .then(value => { assert.equal(value, 'BLUE'); }); }); });
describe('options.hint', () => { it('should render a hint', () => { let buffer; prompt = new Prompt({ message: 'Favorite color?', hint: 'Start typing', show: false }); prompt.once('run', async () => { buffer = prompt.state.buffer; await prompt.submit(); }); return prompt.run() .then(() => { assert(/Start typing/.test(buffer)); }); }); });
describe('options.max', () => { it('should set prompt.max with options.max', () => { prompt = new Prompt({ message: 'prompt-number', max: 10, initial: 5 }); assert.equal(prompt.max, 10); prompt.once('run', () => prompt.submit()); return prompt.run() .then(answer => { assert.equal(answer, 5); }); }); });