Merge branch '78-Add-tests-for-the-Favorite-projects-section' into 'main'
Add tests for the 'Favorite projects' section Closes #78 See merge request mvanremmerden/gitdock!81
This commit is contained in:
commit
0c4f8cc924
3
myApp.js
3
myApp.js
|
|
@ -2177,7 +2177,8 @@ function displayUsersProjects() {
|
|||
let favoriteProjectsString = '';
|
||||
let projects = store['favorite-projects'];
|
||||
if (projects && projects.length > 0) {
|
||||
favoriteProjectsString += '<ul id="projects" class="list-container clickable">';
|
||||
favoriteProjectsString +=
|
||||
'<ul class="list-container clickable" data-testid="favorite-projects">';
|
||||
let chevron = chevronLgRightIcon;
|
||||
for (let projectObject of projects) {
|
||||
let projectString = "'Project'";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,108 @@
|
|||
const assert = require('assert');
|
||||
const { newApp, stopAppAfterEach } = require('./util');
|
||||
|
||||
describe('Favorite projects', function () {
|
||||
this.timeout(25000);
|
||||
|
||||
const EXAMPLE_PROJECT = {
|
||||
added: Date.now(),
|
||||
type: 'projects',
|
||||
web_url: 'https://gitlab.com/mvanremmerden/gitdock',
|
||||
id: 28462485,
|
||||
visibility: 'public',
|
||||
name: 'GitDock ⚓️',
|
||||
title: 'GitDock ⚓️',
|
||||
namespace: { name: 'Marcel van Remmerden' },
|
||||
parent_name: 'Marcel van Remmerden / GitDock ⚓️',
|
||||
parent_url: 'https://gitlab.com/mvanremmerden',
|
||||
name_with_namespace: 'Marcel van Remmerden / GitDock ⚓️',
|
||||
open_issues_count: 52,
|
||||
last_activity_at: '2022-01-31T09:55:37.993Z',
|
||||
avatar_url: 'https://gitlab.com/uploads/-/system/project/avatar/28462485/gitlab.png',
|
||||
star_count: 124,
|
||||
forks_count: 17,
|
||||
};
|
||||
|
||||
const listFavoriteProjects = async (window) =>
|
||||
window.locator('[data-testid="favorite-projects"] li').allTextContents();
|
||||
|
||||
const openSettings = async (window) => {
|
||||
await window.click('#edit-favorite-projects');
|
||||
await window.waitForSelector('#favorite-projects');
|
||||
};
|
||||
|
||||
const addProject = async (window, url) => {
|
||||
await window.click('#add-project-dialog a');
|
||||
await window.fill('#project-settings-link', url);
|
||||
await window.click('#project-settings-add-button');
|
||||
await window.waitForSelector('#add-project-dialog a');
|
||||
};
|
||||
|
||||
beforeEach(async function () {
|
||||
await newApp(this, { loggedIn: true });
|
||||
});
|
||||
|
||||
stopAppAfterEach();
|
||||
|
||||
it('shows no favorite projects', async function () {
|
||||
assert.equal((await listFavoriteProjects(this.window)).length, 0);
|
||||
});
|
||||
|
||||
it('adds a new project', async function () {
|
||||
await openSettings(this.window);
|
||||
await addProject(this.window, EXAMPLE_PROJECT.web_url);
|
||||
|
||||
await this.window.click('#detail-header');
|
||||
await this.window.waitForSelector('[data-testid="favorite-projects"]');
|
||||
|
||||
const projects = await listFavoriteProjects(this.window);
|
||||
|
||||
assert.equal(projects.length, 1);
|
||||
assert.equal(projects[0].includes(EXAMPLE_PROJECT.name), true);
|
||||
assert.equal(projects[0].includes(EXAMPLE_PROJECT.namespace.name), true);
|
||||
});
|
||||
|
||||
it('shows the correct project link', async function () {
|
||||
await newApp(this, {
|
||||
loggedIn: true,
|
||||
favoriteProjects: [EXAMPLE_PROJECT],
|
||||
});
|
||||
|
||||
const onclick = await this.window
|
||||
.locator('[data-testid="favorite-projects"] li')
|
||||
.getAttribute('onclick');
|
||||
|
||||
assert.equal(onclick, `goToDetail('Project', '${JSON.stringify(EXAMPLE_PROJECT)}')`);
|
||||
});
|
||||
|
||||
it('deletes an existing project', async function () {
|
||||
await newApp(this, {
|
||||
loggedIn: true,
|
||||
favoriteProjects: [EXAMPLE_PROJECT],
|
||||
});
|
||||
|
||||
assert.equal((await listFavoriteProjects(this.window)).length, 1);
|
||||
|
||||
await this.window.click('#edit-favorite-projects');
|
||||
await this.window.waitForSelector('#favorite-projects');
|
||||
await this.window.click('#favorite-projects .bookmark-delete');
|
||||
|
||||
await this.window.click('#detail-header');
|
||||
await this.window.waitForTimeout(100);
|
||||
|
||||
assert.equal((await listFavoriteProjects(this.window)).length, 0);
|
||||
});
|
||||
|
||||
// Skipped due to https://gitlab.com/mvanremmerden/gitdock/-/issues/110
|
||||
it.skip('prevents adding a project twice', async function () {
|
||||
await openSettings(this.window);
|
||||
|
||||
await addProject(this.window, EXAMPLE_PROJECT.web_url);
|
||||
await addProject(this.window, EXAMPLE_PROJECT.web_url);
|
||||
|
||||
await this.window.click('#detail-header');
|
||||
await this.window.waitForTimeout(100);
|
||||
|
||||
assert.equal((await listFavoriteProjects(this.window)).length, 1);
|
||||
});
|
||||
});
|
||||
|
|
@ -12,24 +12,43 @@ const userDataIfLoggedIn = (loggedIn = false) => {
|
|||
};
|
||||
};
|
||||
|
||||
const stopAppIfStarted = async (thisValue) => {
|
||||
if (thisValue.app) {
|
||||
await thisValue.app.close();
|
||||
thisValue.app = null;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* @param {Object} thisValue
|
||||
* @param {{
|
||||
* theme?: 'dark' | 'light',
|
||||
* loggedIn?: boolean,
|
||||
* platform?: 'linux' | 'darwin' | 'win32',
|
||||
* browserHistory?: import('node-browser-history').BrowserHistory[],
|
||||
* bookmarks?: { title: string, type: string, web_url: string, parent_url: string, added: number, parent_name: string }[] },
|
||||
* bookmarks?: { title: string, type: string, web_url: string, parent_url: string, added: number, parent_name: string }[],
|
||||
* favoriteProjects?: { added: number, type: 'projects', web_url: string, id: number, visibility: 'public'|'internal'|'private', name: string, title: string, namespace: { name: string }, parent_name: string, parent_url: string, name_with_namespace: string, open_issues_count: number, last_activity_at: string, avatar_url: string, star_count: number, forks_count: number }[],
|
||||
* }
|
||||
*/
|
||||
async newApp(
|
||||
thisValue,
|
||||
{ theme, loggedIn, platform = process.platform, browserHistory, bookmarks = [] } = {},
|
||||
{
|
||||
theme,
|
||||
loggedIn,
|
||||
platform = process.platform,
|
||||
browserHistory,
|
||||
bookmarks = [],
|
||||
favoriteProjects = [],
|
||||
} = {},
|
||||
) {
|
||||
await stopAppIfStarted(thisValue);
|
||||
|
||||
const store = {
|
||||
theme,
|
||||
...userDataIfLoggedIn(loggedIn),
|
||||
bookmarks,
|
||||
'favorite-projects': favoriteProjects,
|
||||
};
|
||||
|
||||
const app = await electron.launch({
|
||||
|
|
@ -56,10 +75,7 @@ module.exports = {
|
|||
},
|
||||
stopAppAfterEach() {
|
||||
afterEach(async function () {
|
||||
if (this.app) {
|
||||
await this.app.close();
|
||||
this.app = null;
|
||||
}
|
||||
await stopAppIfStarted(this);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue