use randomly generated names for users, nodes

This commit is contained in:
Adina Parpalita 2017-11-10 15:42:10 +02:00
parent dab38d5a47
commit cef78c3713
8 changed files with 70 additions and 104 deletions

View File

@ -24,21 +24,20 @@ import { Utils } from '../../utilities/utils';
import { RepoClient, NodeContentTree } from '../../utilities/repo-client/repo-client'; import { RepoClient, NodeContentTree } from '../../utilities/repo-client/repo-client';
describe('Create folder', () => { describe('Create folder', () => {
const username = 'jane.doe'; const username = `user-${Utils.random()}`;
const password = 'jane.doe';
const parent = 'parent-folder'; const parent = `parent-${Utils.random()}`;
const folderName1 = 'my-folder1'; const folderName1 = `folder-${Utils.random()}`;
const folderName2 = 'my-folder2'; const folderName2 = `folder-${Utils.random()}`;
const folderDescription = 'description of my folder'; const folderDescription = 'description of my folder';
const duplicateFolderName = 'duplicate-folder-name'; const duplicateFolderName = `folder-${Utils.random()}`;
const nameWithSpaces = ' folder-name '; const nameWithSpaces = ` folder-${Utils.random()} `;
const siteName = 'site-private'; const siteName = `site-private-${Utils.random()}`;
const apis = { const apis = {
admin: new RepoClient(), admin: new RepoClient(),
user: new RepoClient(username, password) user: new RepoClient(username, username)
}; };
const loginPage = new LoginPage(); const loginPage = new LoginPage();
@ -57,14 +56,14 @@ describe('Create folder', () => {
} }
beforeAll(done => { beforeAll(done => {
apis.admin.people.createUser(username, password) apis.admin.people.createUser(username)
.then(() => apis.admin.sites.createSite(siteName, SITE_VISIBILITY.PRIVATE)) .then(() => apis.admin.sites.createSite(siteName, SITE_VISIBILITY.PRIVATE))
.then(() => apis.admin.nodes.createFolders([ folderName1 ], `Sites/${siteName}/documentLibrary`)) .then(() => apis.admin.nodes.createFolders([ folderName1 ], `Sites/${siteName}/documentLibrary`))
.then(() => apis.admin.sites.addSiteMember(siteName, username, SITE_ROLES.SITE_CONSUMER)) .then(() => apis.admin.sites.addSiteMember(siteName, username, SITE_ROLES.SITE_CONSUMER))
.then(() => apis.user.nodes.createFolders([ duplicateFolderName ], parent)) .then(() => apis.user.nodes.createFolders([ duplicateFolderName ], parent))
.then(() => loginPage.load()) .then(() => loginPage.load()
.then(() => loginPage.loginWith(username, password)) .then(() => loginPage.loginWith(username))
.then(done); .then(done));
}); });
beforeEach(done => { beforeEach(done => {
@ -80,9 +79,9 @@ describe('Create folder', () => {
afterAll(done => { afterAll(done => {
Promise Promise
.all([ .all([
apis.admin.sites.deleteSite(siteName, true),
apis.user.nodes.deleteNodes([ parent ]), apis.user.nodes.deleteNodes([ parent ]),
logoutPage.load() logoutPage.load()
.then(() => Utils.clearLocalStorage())
]) ])
.then(done); .then(done);
}); });
@ -128,9 +127,7 @@ describe('Create folder', () => {
}) })
.then(() => { .then(() => {
apis.user.nodes.getNodeDescription(folderName2) apis.user.nodes.getNodeDescription(folderName2)
.then((description) => { .then((description) => expect(description).toEqual(folderDescription));
expect(description).toEqual(folderDescription, 'Description is not correct');
});
}) })
); );
}); });

View File

@ -23,24 +23,23 @@ import { CreateOrEditFolderDialog } from '../../components/dialog/create-edit-fo
import { Utils } from '../../utilities/utils'; import { Utils } from '../../utilities/utils';
describe('Edit folder', () => { describe('Edit folder', () => {
const username = 'john.doe'; const username = `user-${Utils.random()}`;
const password = 'john.doe';
const parent = 'parent-folder'; const parent = `parent-${Utils.random()}`;
const folderName = 'my-folder'; const folderName = `folder-${Utils.random()}`;
const folderDescription = 'my folder description'; const folderDescription = 'my folder description';
const folderNameToEdit = 'folder-to-be-edited'; const folderNameToEdit = `folder-${Utils.random()}`;
const duplicateFolderName = 'duplicate-folder-name'; const duplicateFolderName = `folder-${Utils.random()}`;
const folderNameEdited = 'edited-folder'; const folderNameEdited = `folder-${Utils.random()}`;
const folderDescriptionEdited = 'my folder description edited'; const folderDescriptionEdited = 'my folder description edited';
const siteName = 'site-private'; const siteName = `site-private-${Utils.random()}`;
const apis = { const apis = {
admin: new RepoClient(), admin: new RepoClient(),
user: new RepoClient(username, password) user: new RepoClient(username, username)
}; };
const loginPage = new LoginPage(); const loginPage = new LoginPage();
@ -53,18 +52,18 @@ describe('Edit folder', () => {
beforeAll(done => { beforeAll(done => {
Promise Promise
.all([ .all([
apis.admin.people.createUser(username, password), apis.admin.people.createUser(username),
apis.admin.sites.createSite(siteName, SITE_VISIBILITY.PRIVATE) apis.admin.sites.createSite(siteName, SITE_VISIBILITY.PRIVATE)
.then(() => apis.admin.nodes.createFolders([ folderName ], `Sites/${siteName}/documentLibrary`)) .then(() => apis.admin.nodes.createFolders([ folderName ], `Sites/${siteName}/documentLibrary`))
]) ])
.then(() => apis.admin.sites.addSiteMember(siteName, username, SITE_ROLES.SITE_CONSUMER)) .then(() => apis.admin.sites.addSiteMember(siteName, username, SITE_ROLES.SITE_CONSUMER))
.then(() => Promise.all([ .then(() => Promise.all([
apis.user.nodes.createNodeWithProperties( folderName, '', folderDescription, parent ), apis.user.nodes.createNodeWithProperties( folderName, '', folderDescription, parent ),
apis.user.nodes.createFolders([ folderNameToEdit, duplicateFolderName ], parent), apis.user.nodes.createFolders([ folderNameToEdit, duplicateFolderName ], parent)
loginPage.load()
])) ]))
.then(() => loginPage.loginWith(username, password)) .then(() => loginPage.load()
.then(done); .then(() => loginPage.loginWith(username))
.then(done));
}); });
beforeEach(done => { beforeEach(done => {
@ -83,7 +82,6 @@ describe('Edit folder', () => {
apis.admin.sites.deleteSite(siteName, true), apis.admin.sites.deleteSite(siteName, true),
apis.user.nodes.deleteNodes([ parent ]), apis.user.nodes.deleteNodes([ parent ]),
logoutPage.load() logoutPage.load()
.then(() => Utils.clearLocalStorage())
]) ])
.then(done); .then(done);
}); });
@ -111,7 +109,7 @@ describe('Edit folder', () => {
); );
}); });
it('folder properties are modified when pressing OK', () => { it('properties are modified when pressing OK', () => {
personalFilesPage.dataTable.doubleClickOnRowByContainingText(parent) personalFilesPage.dataTable.doubleClickOnRowByContainingText(parent)
.then(() => dataTable.clickOnRowByContainingText(folderNameToEdit) .then(() => dataTable.clickOnRowByContainingText(folderNameToEdit)
.then(() => editButton.click()) .then(() => editButton.click())

View File

@ -65,7 +65,6 @@ describe('Page titles', () => {
afterAll(done => { afterAll(done => {
logoutPage.load() logoutPage.load()
.then(() => Utils.clearLocalStorage())
.then(done); .then(done);
}); });

View File

@ -27,19 +27,16 @@ describe('Login', () => {
const loginPage = new LoginPage(); const loginPage = new LoginPage();
const logoutPage = new LogoutPage(); const logoutPage = new LogoutPage();
const testUser = { const testUser = `user-${Utils.random()}@alfness`;
username: 'test.user@alfness',
password: 'test.user'
};
const russianUser = { const russianUser = {
username: 'пользователь', username: `пользвате${Utils.random()}`,
password: '密碼中國' password: '密碼中國'
}; };
const johnDoe = { const johnDoe = {
username: 'john.doe', username: `user-${Utils.random()}`,
password: 'john.doe', get password() { return this.username; },
firstName: 'John', firstName: 'John',
lastName: 'Doe' lastName: 'Doe'
}; };
@ -47,7 +44,7 @@ describe('Login', () => {
beforeAll(done => { beforeAll(done => {
Promise Promise
.all([ .all([
peopleApi.createUser(testUser.username, testUser.password), peopleApi.createUser(testUser),
peopleApi.createUser(russianUser.username, russianUser.password), peopleApi.createUser(russianUser.username, russianUser.password),
peopleApi.createUser(johnDoe.username, johnDoe.password, { peopleApi.createUser(johnDoe.username, johnDoe.password, {
firstName: johnDoe.firstName, firstName: johnDoe.firstName,
@ -71,10 +68,9 @@ describe('Login', () => {
describe('with valid credentials', () => { describe('with valid credentials', () => {
it('navigate to "Personal Files"', () => { it('navigate to "Personal Files"', () => {
const { username, password } = johnDoe; const { username } = johnDoe;
loginPage loginPage.loginWith(username)
.loginWith(username, password)
.then(() => { .then(() => {
expect(browser.getCurrentUrl()).toContain(APP_ROUTES.PERSONAL_FILES); expect(browser.getCurrentUrl()).toContain(APP_ROUTES.PERSONAL_FILES);
}); });
@ -82,20 +78,17 @@ describe('Login', () => {
it(`displays user's name in header`, () => { it(`displays user's name in header`, () => {
const { userInfo } = new BrowsingPage(APP_ROUTES.PERSONAL_FILES).header; const { userInfo } = new BrowsingPage(APP_ROUTES.PERSONAL_FILES).header;
const { username, password, firstName, lastName } = johnDoe; const { username, firstName, lastName } = johnDoe;
loginPage loginPage.loginWith(username)
.loginWith(username, password)
.then(() => { .then(() => {
expect(userInfo.name).toEqual(`${firstName} ${lastName}`); expect(userInfo.name).toEqual(`${firstName} ${lastName}`);
}); });
}); });
it(`logs in with user having username containing "@"`, () => { it(`logs in with user having username containing "@"`, () => {
const { username, password } = testUser;
loginPage loginPage
.loginWith(username, password) .loginWith(testUser)
.then(() => { .then(() => {
expect(browser.getCurrentUrl()).toContain(APP_ROUTES.PERSONAL_FILES); expect(browser.getCurrentUrl()).toContain(APP_ROUTES.PERSONAL_FILES);
}); });
@ -112,10 +105,10 @@ describe('Login', () => {
}); });
it('redirects to Home Page when navigating to the Login page while already logged in', () => { it('redirects to Home Page when navigating to the Login page while already logged in', () => {
const { username, password } = johnDoe; const { username } = johnDoe;
loginPage loginPage
.loginWith(username, password) .loginWith(username)
.then(() => browser.get(APP_ROUTES.LOGIN) .then(() => browser.get(APP_ROUTES.LOGIN)
.then(() => { .then(() => {
expect(browser.getCurrentUrl()).toContain(APP_ROUTES.PERSONAL_FILES); expect(browser.getCurrentUrl()).toContain(APP_ROUTES.PERSONAL_FILES);
@ -124,10 +117,10 @@ describe('Login', () => {
}); });
it('redirects to Personal Files when pressing browser Back while already logged in ', () => { it('redirects to Personal Files when pressing browser Back while already logged in ', () => {
const { username, password } = johnDoe; const { username } = johnDoe;
loginPage loginPage
.loginWith(username, password) .loginWith(username)
.then(() => browser.driver.navigate().back()) .then(() => browser.driver.navigate().back())
.then(() => { .then(() => {
expect(browser.getCurrentUrl()).toContain(APP_ROUTES.PERSONAL_FILES); expect(browser.getCurrentUrl()).toContain(APP_ROUTES.PERSONAL_FILES);

View File

@ -29,20 +29,17 @@ describe('Logout', () => {
const peopleApi = new RepoClient().people; const peopleApi = new RepoClient().people;
const johnDoe = { const johnDoe = `user-${Utils.random()}`;
username: 'john.doe',
password: 'john.doe'
};
beforeAll((done) => { beforeAll((done) => {
peopleApi peopleApi
.createUser(johnDoe.username, johnDoe.password) .createUser(johnDoe)
.then(done); .then(done);
}); });
beforeEach((done) => { beforeEach((done) => {
loginPage.load() loginPage.load()
.then(() => loginPage.loginWith(johnDoe.username, johnDoe.password)) .then(() => loginPage.loginWith(johnDoe))
.then(done); .then(done);
}); });
@ -59,13 +56,6 @@ describe('Logout', () => {
}); });
}); });
xit('redirects to Login page when logging out by URL', () => {
browser.get(APP_ROUTES.LOGOUT)
.then(() => {
expect(browser.getCurrentUrl()).toContain(APP_ROUTES.LOGIN);
});
});
it('redirects to Login page when pressing browser Back after logout', () => { it('redirects to Login page when pressing browser Back after logout', () => {
page.signOut() page.signOut()
.then(() => browser.driver.navigate().back()) .then(() => browser.driver.navigate().back())

View File

@ -23,8 +23,8 @@ import { Utils } from '../../utilities/utils';
import { RepoClient, NodeContentTree } from '../../utilities/repo-client/repo-client'; import { RepoClient, NodeContentTree } from '../../utilities/repo-client/repo-client';
describe('Personal Files', () => { describe('Personal Files', () => {
const username = 'jane.doe'; const username = `user-${Utils.random()}`;
const password = 'jane.doe'; const password = username;
const apis = { const apis = {
admin: new RepoClient(), admin: new RepoClient(),
@ -36,30 +36,27 @@ describe('Personal Files', () => {
const personalFilesPage = new BrowsingPage(APP_ROUTES.PERSONAL_FILES); const personalFilesPage = new BrowsingPage(APP_ROUTES.PERSONAL_FILES);
const dataTable = personalFilesPage.dataTable; const dataTable = personalFilesPage.dataTable;
const adminContent: NodeContentTree = { const adminFolder = `admin-folder-${Utils.random()}`;
name: 'admin-folder'
};
const userContent: NodeContentTree = { const userFolder = `user-folder-${Utils.random()}`;
name: 'user-folder', const userFile = `file-${Utils.random()}.txt`;
files: [ 'user-file.txt' ]
};
beforeAll(done => { beforeAll(done => {
Promise Promise
.all([ .all([
apis.admin.people.createUser(username, password), apis.admin.people.createUser(username, password),
apis.admin.nodes.createContent(adminContent) apis.admin.nodes.createFolders([ adminFolder ])
]) ])
.then(() => apis.user.nodes.createContent(userContent)) .then(() => apis.user.nodes.createFolders([ userFolder ]))
.then(() => apis.user.nodes.createFiles([ userFile ], userFolder))
.then(done); .then(done);
}); });
afterAll(done => { afterAll(done => {
Promise Promise
.all([ .all([
apis.admin.nodes.deleteNodes([ adminContent.name ]), apis.admin.nodes.deleteNodes([ adminFolder ]),
apis.user.nodes.deleteNodes([ userContent.name ]) apis.user.nodes.deleteNodes([ userFolder ])
]) ])
.then(done); .then(done);
}); });
@ -81,7 +78,6 @@ describe('Personal Files', () => {
afterAll(done => { afterAll(done => {
logoutPage.load() logoutPage.load()
.then(() => Utils.clearLocalStorage())
.then(done); .then(done);
}); });
@ -109,7 +105,6 @@ describe('Personal Files', () => {
afterAll(done => { afterAll(done => {
logoutPage.load() logoutPage.load()
.then(() => Utils.clearLocalStorage())
.then(done); .then(done);
}); });
@ -131,17 +126,17 @@ describe('Personal Files', () => {
}); });
it('has user created content', () => { it('has user created content', () => {
expect(dataTable.getRowByContainingText('user-folder').isPresent()) expect(dataTable.getRowByContainingText(userFolder).isPresent())
.toBe(true); .toBe(true);
}); });
it('navigates to folder', () => { it('navigates to folder', () => {
const getNodeIdPromise = apis.user.nodes const getNodeIdPromise = apis.user.nodes
.getNodeByPath('/user-folder') .getNodeByPath(`/${userFolder}`)
.then(response => response.data.entry.id); .then(response => response.data.entry.id);
const navigatePromise = dataTable const navigatePromise = dataTable
.doubleClickOnRowByContainingText('user-folder') .doubleClickOnRowByContainingText(userFolder)
.then(() => dataTable.waitForHeader()); .then(() => dataTable.waitForHeader());
Promise Promise
@ -153,8 +148,8 @@ describe('Personal Files', () => {
expect(browser.getCurrentUrl()) expect(browser.getCurrentUrl())
.toContain(nodeId, 'Node ID is not in the URL'); .toContain(nodeId, 'Node ID is not in the URL');
expect(dataTable.getRowByContainingText('user-file.txt').isPresent()) expect(dataTable.getRowByContainingText(userFile).isPresent())
.toBe(true, '"user-file.txt" is missing'); .toBe(true, 'user file is missing');
}); });
}); });
@ -165,7 +160,7 @@ describe('Personal Files', () => {
const { actions } = personalFilesPage.toolbar; const { actions } = personalFilesPage.toolbar;
dataTable dataTable
.clickOnRowByContainingText('user-folder') .clickOnRowByContainingText(userFolder)
.then(() => { .then(() => {
expect(actions.isEmpty()).toBe(false, 'Toolbar to be present'); expect(actions.isEmpty()).toBe(false, 'Toolbar to be present');
}) })

View File

@ -19,7 +19,6 @@ import { browser } from 'protractor';
import { APP_ROUTES, SIDEBAR_LABELS } from '../../configs'; import { APP_ROUTES, SIDEBAR_LABELS } from '../../configs';
import { LoginPage, LogoutPage, BrowsingPage } from '../../pages/pages'; import { LoginPage, LogoutPage, BrowsingPage } from '../../pages/pages';
import { Utils } from '../../utilities/utils';
describe('Side navigation', () => { describe('Side navigation', () => {
const loginPage = new LoginPage(); const loginPage = new LoginPage();
@ -38,7 +37,6 @@ describe('Side navigation', () => {
afterAll(done => { afterAll(done => {
logoutPage.load() logoutPage.load()
.then(() => Utils.clearLocalStorage())
.then(done); .then(done);
}); });

View File

@ -23,12 +23,11 @@ import { Utils } from '../../utilities/utils';
import { RepoClient, NodeContentTree } from '../../utilities/repo-client/repo-client'; import { RepoClient, NodeContentTree } from '../../utilities/repo-client/repo-client';
describe('Pagination', () => { describe('Pagination', () => {
const username = 'jane.doe'; const username = `user-${Utils.random()}`;
const password = 'jane.doe';
const apis = { const apis = {
admin: new RepoClient(), admin: new RepoClient(),
user: new RepoClient(username, password) user: new RepoClient(username, username)
}; };
const loginPage = new LoginPage(); const loginPage = new LoginPage();
@ -36,7 +35,7 @@ describe('Pagination', () => {
beforeAll(done => { beforeAll(done => {
apis.admin.people apis.admin.people
.createUser(username, password) .createUser(username)
.then(done); .then(done);
}); });
@ -48,7 +47,7 @@ describe('Pagination', () => {
// Generate files // Generate files
const content: NodeContentTree = { const content: NodeContentTree = {
name: 'user-folder', name: `user-folder-${Utils.random()}`,
files: Array(101) files: Array(101)
.fill('file') .fill('file')
.map((name, index): string => `${name}-${index + 1}.txt`) .map((name, index): string => `${name}-${index + 1}.txt`)
@ -58,14 +57,13 @@ describe('Pagination', () => {
beforeAll(done => { beforeAll(done => {
nodesApi.createContent(content) nodesApi.createContent(content)
.then(() => loginPage.load()) .then(() => loginPage.load()
.then(() => loginPage.loginWith(username, password)) .then(() => loginPage.loginWith(username))
.then(done); .then(done));
}); });
beforeEach(done => { beforeEach(done => {
personalFilesPage personalFilesPage.load()
.load()
.then(() => dataTable.waitForHeader()) .then(() => dataTable.waitForHeader())
.then(() => dataTable.doubleClickOnRowByContainingText(content.name)) .then(() => dataTable.doubleClickOnRowByContainingText(content.name))
.then(() => dataTable.sortByColumn('Name')) .then(() => dataTable.sortByColumn('Name'))
@ -73,9 +71,7 @@ describe('Pagination', () => {
}); });
afterAll(done => { afterAll(done => {
logoutPage logoutPage.load()
.load()
.then(() => Utils.clearLocalStorage())
.then(() => nodesApi.deleteNodes([ content.name ])) .then(() => nodesApi.deleteNodes([ content.name ]))
.then(done); .then(done);
}); });