2018-02-10 10:43:14 -05:00
|
|
|
const publishMetadata = require('../unit/partials/publish-api');
|
|
|
|
|
2018-02-09 02:42:34 -05:00
|
|
|
describe('/ (Verdaccio Page)', () => {
|
2018-02-08 16:24:34 -05:00
|
|
|
let page;
|
2018-02-10 03:16:24 -05:00
|
|
|
// this might be increased based on the delays included in all test
|
2018-02-10 11:09:02 -05:00
|
|
|
jest.setTimeout(20000);
|
2018-02-08 16:24:34 -05:00
|
|
|
|
2018-02-10 11:09:02 -05:00
|
|
|
const clickElement = async function(selector, options = {button: 'middle', delay: 100}) {
|
2018-02-10 07:20:17 -05:00
|
|
|
const button = await page.$(selector);
|
|
|
|
await button.focus();
|
|
|
|
await button.click(options);
|
|
|
|
};
|
|
|
|
|
|
|
|
const evaluateSignIn = async function() {
|
|
|
|
const text = await page.evaluate(() => document.querySelector('header button > span').textContent);
|
|
|
|
expect(text).toMatch('Login');
|
|
|
|
};
|
|
|
|
|
2018-02-10 10:43:14 -05:00
|
|
|
const getPackages = async function() {
|
|
|
|
return await page.$$('.package-list-items > div');
|
|
|
|
}
|
|
|
|
|
2018-02-10 07:20:17 -05:00
|
|
|
const logIn = async function() {
|
2018-02-10 11:09:02 -05:00
|
|
|
await clickElement('header button');
|
2018-02-10 07:20:17 -05:00
|
|
|
await page.waitFor(500);
|
|
|
|
// we fill the sign in form
|
|
|
|
const signInDialog = await page.$('.el-dialog');
|
|
|
|
const userInput = await signInDialog.$('input[type=text]');
|
|
|
|
expect(userInput).not.toBeNull();
|
|
|
|
const passInput = await signInDialog.$('input[type=password]');
|
|
|
|
expect(passInput).not.toBeNull();
|
|
|
|
await userInput.type('test', {delay: 100});
|
|
|
|
await passInput.type('test', {delay: 100});
|
|
|
|
await passInput.dispose();
|
|
|
|
// click on log in
|
|
|
|
const loginButton = await page.$('.login-button');
|
|
|
|
expect(loginButton).toBeDefined();
|
|
|
|
await loginButton.focus();
|
|
|
|
await loginButton.click({delay: 100});
|
|
|
|
await page.waitFor(500);
|
|
|
|
};
|
|
|
|
|
2018-02-08 16:24:34 -05:00
|
|
|
beforeAll(async () => {
|
|
|
|
page = await global.__BROWSER__.newPage();
|
2018-02-09 02:42:34 -05:00
|
|
|
await page.goto('http://0.0.0.0:55558');
|
2018-02-10 03:16:24 -05:00
|
|
|
page.on('console', msg => console.log('PAGE LOG:', msg.text()));
|
|
|
|
});
|
2018-02-08 16:24:34 -05:00
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await page.close()
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should load without error', async () => {
|
|
|
|
let text = await page.evaluate(() => document.body.textContent);
|
|
|
|
|
2018-02-09 02:42:34 -05:00
|
|
|
expect(text).toContain('adduser');
|
2018-02-08 16:24:34 -05:00
|
|
|
})
|
2018-02-10 03:16:24 -05:00
|
|
|
|
|
|
|
it('should match npm adduser and set registry on header', async () => {
|
|
|
|
let text = await page.evaluate(() => document.querySelector('figure').textContent);
|
|
|
|
expect(text).toMatch('npm set registry http://0.0.0.0:55558');
|
|
|
|
expect(text).toMatch('npm adduser --registry http://0.0.0.0:55558');
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('should match title with no packages published', async () => {
|
|
|
|
let text = await page.evaluate(() => document.querySelector('.container h1').textContent);
|
|
|
|
expect(text).toMatch('No Package Published Yet');
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should match title with first step', async () => {
|
|
|
|
let text = await page.evaluate(() => document.querySelector('#adduser code').textContent);
|
|
|
|
expect(text).toMatch('npm adduser --registry http://0.0.0.0:55558');
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should match title with second step', async () => {
|
|
|
|
let text = await page.evaluate(() => document.querySelector('#publish code').textContent);
|
|
|
|
expect(text).toMatch('npm publish --registry http://0.0.0.0:55558');
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should match button Login to sign in', async () => {
|
2018-02-10 07:20:17 -05:00
|
|
|
await evaluateSignIn();
|
2018-02-10 03:16:24 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should click on sign in button', async () => {
|
|
|
|
const signInButton = await page.$('header button');
|
|
|
|
await signInButton.click();
|
|
|
|
const signInDialog = await page.$('header .el-dialog__wrapper');
|
|
|
|
|
|
|
|
expect(signInDialog).not.toBeNull();
|
|
|
|
})
|
|
|
|
|
2018-02-10 07:20:17 -05:00
|
|
|
it('should log in an user', async () => {
|
2018-02-10 03:16:24 -05:00
|
|
|
// we open the dialog
|
2018-02-10 07:20:17 -05:00
|
|
|
await logIn();
|
2018-02-10 03:16:24 -05:00
|
|
|
// check whether user is logged
|
|
|
|
const greetings = await page.evaluate(() => document.querySelector('.user-logged-greetings').textContent);
|
|
|
|
const buttonLogout = await page.$('.header-button-logout');
|
|
|
|
expect(greetings).toMatch('Hi, test');
|
|
|
|
expect(buttonLogout).toBeDefined();
|
2018-02-10 07:20:17 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should logout an user', async () => {
|
|
|
|
// we asume the user is logged already
|
2018-02-10 11:09:02 -05:00
|
|
|
await clickElement('.header-button-logout', {clickCount: 1, delay: 200});
|
2018-02-10 07:20:17 -05:00
|
|
|
await page.waitFor(1000);
|
|
|
|
await evaluateSignIn();
|
|
|
|
})
|
2018-02-10 10:43:14 -05:00
|
|
|
|
|
|
|
it('should publish a package', async () => {
|
|
|
|
await global.__SERVER__.putPackage(publishMetadata.name, publishMetadata);
|
|
|
|
await page.waitFor(1000);
|
|
|
|
await page.reload();
|
|
|
|
await page.waitFor(1000);
|
|
|
|
const packagesList = await getPackages();
|
2018-02-10 11:09:02 -05:00
|
|
|
|
2018-02-10 10:43:14 -05:00
|
|
|
expect(packagesList).toHaveLength(1);
|
|
|
|
});
|
2018-02-10 11:09:02 -05:00
|
|
|
|
|
|
|
it('should navigate to the package detail', async () => {
|
|
|
|
const packagesList = await getPackages();
|
|
|
|
const packageItem = packagesList[0];
|
|
|
|
await packageItem.focus();
|
|
|
|
await packageItem.click({clickCount: 1, delay: 200});
|
|
|
|
await page.waitFor(1000);
|
|
|
|
const readmeText = await page.evaluate(() => document.querySelector('.markdown-body').textContent);
|
|
|
|
|
|
|
|
expect(readmeText).toMatch('test');
|
|
|
|
});
|
|
|
|
|
2018-02-10 18:02:14 -05:00
|
|
|
it('should contains last sync information', async () => {
|
|
|
|
const versionList = await page.$$('.sidebar-info .last-sync-item');
|
|
|
|
expect(versionList).toHaveLength(3);
|
|
|
|
});
|
|
|
|
|
2018-02-10 07:20:17 -05:00
|
|
|
});
|