mirror of
https://git.cloudron.io/cloudron/gitea-app
synced 2026-04-29 22:21:13 +00:00
Fix test
This commit is contained in:
Executable → Regular
+22
-58
@@ -4,23 +4,21 @@ import assert from 'node:assert/strict';
|
||||
import { execSync } from 'node:child_process';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import superagent from '@cloudron/superagent';
|
||||
import {
|
||||
app,
|
||||
clearCache,
|
||||
click,
|
||||
cloudronCli,
|
||||
getText,
|
||||
goto,
|
||||
loginOIDC,
|
||||
sendKeys,
|
||||
setInputFiles,
|
||||
setupBrowser,
|
||||
takeScreenshot,
|
||||
teardownBrowser,
|
||||
username,
|
||||
waitFor,
|
||||
waitForUrl
|
||||
waitForUrl,
|
||||
press
|
||||
} from '@cloudron/charlie';
|
||||
|
||||
/* global it, describe, before, after, afterEach */
|
||||
@@ -41,29 +39,12 @@ describe('Application life cycle test', function () {
|
||||
await takeScreenshot(this.currentTest.title);
|
||||
});
|
||||
|
||||
async function setAvatar() {
|
||||
await goto(`https://${app.fqdn}/user/settings`, '//label[contains(text(), "Use Custom Avatar")]');
|
||||
await click('//label[contains(text(), "Use Custom Avatar")]');
|
||||
await setInputFiles('//input[@type="file" and @name="avatar"]', path.resolve(import.meta.dirname, '../logo.png'));
|
||||
await click('//button[contains(text(), "Update Avatar")]');
|
||||
await waitFor('Your avatar has been updated.');
|
||||
}
|
||||
|
||||
async function checkAvatar() {
|
||||
await goto(`https://${app.fqdn}/${username}`, '//div[@id="profile-avatar"]/a/img');
|
||||
const avatarSrc = await getText('//div[@id="profile-avatar"]/a/img', 'src');
|
||||
assert.ok(avatarSrc);
|
||||
const avatarUrl = new URL(avatarSrc, `https://${app.fqdn}`).href;
|
||||
const response = await superagent.get(avatarUrl);
|
||||
assert.strictEqual(response.status, 200);
|
||||
}
|
||||
|
||||
async function login(user, passwd) {
|
||||
await goto(`https://${app.fqdn}/user/login`, 'css=#user_name');
|
||||
await sendKeys('css=#user_name', user);
|
||||
await sendKeys('css=#password', passwd);
|
||||
await click('//form[@action="/user/login"]//button');
|
||||
await waitFor('xpath=//nav//img[contains(@class, "avatar")]');
|
||||
await goto(`https://${app.fqdn}/user/login`, 'label=Username or Email Address');
|
||||
await sendKeys('label=Username or Email Address', user);
|
||||
await sendKeys('label=Password', passwd);
|
||||
await click('Sign In', { role: 'button' }); // there is a sign in link at the top
|
||||
await waitFor('Milestones');
|
||||
}
|
||||
|
||||
async function adminLogin() {
|
||||
@@ -72,23 +53,13 @@ describe('Application life cycle test', function () {
|
||||
|
||||
async function loginGiteaOIDC() {
|
||||
await clearCache();
|
||||
await goto(`https://${app.fqdn}/user/login`, '//a[@href="/user/oauth2/cloudron"]');
|
||||
await click('//a[@href="/user/oauth2/cloudron"]');
|
||||
await loginOIDC('//nav//img[contains(@class, "avatar")]');
|
||||
}
|
||||
|
||||
async function loginGiteaOIDCOld() {
|
||||
await clearCache();
|
||||
await goto(`https://${app.fqdn}/user/login`, '//a[contains(@class, "openidConnect")]');
|
||||
await click('//a[contains(@class, "openidConnect") and contains(., "Sign in with cloudron")]');
|
||||
await loginOIDC('//nav//img[contains(@class, "avatar")]');
|
||||
await goto(`https://${app.fqdn}/user/login`, /Sign in with/);
|
||||
await click(/Sign in with/);
|
||||
await loginOIDC('Milestones');
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
await goto(`https://${app.fqdn}`, '//nav//img[contains(@class, "avatar")]');
|
||||
await click('//nav//img[contains(@class, "avatar")]');
|
||||
await waitFor('css=a[href="/user/logout"]');
|
||||
await click('//a[@href="/user/logout"]');
|
||||
await clearCache();
|
||||
}
|
||||
|
||||
async function addPublicKey() {
|
||||
@@ -96,18 +67,18 @@ describe('Application life cycle test', function () {
|
||||
fs.chmodSync(keyPath, 0o600);
|
||||
|
||||
await goto(`https://${app.fqdn}/user/settings/keys`, 'css=#add-ssh-button');
|
||||
await click('css=#add-ssh-button');
|
||||
await sendKeys('css=#ssh-key-title', 'testkey');
|
||||
await sendKeys('css=#ssh-key-content', fs.readFileSync(`${import.meta.dirname}/id_ed25519.pub`, 'utf8').trim());
|
||||
await click('//form//button[contains(text(),"Add Key")]');
|
||||
await waitFor('has been added.');
|
||||
await click('css=#add-ssh-button'); // there are two Add key buttons
|
||||
await sendKeys('label=Content', fs.readFileSync(`${import.meta.dirname}/id_ed25519.pub`, 'utf8').trim()); // there are two Content labels
|
||||
await sendKeys('label=Key Name', 'testkey');
|
||||
await press('label=Key Name', 'Enter');
|
||||
await waitFor(/has been added/);
|
||||
}
|
||||
|
||||
async function createRepo() {
|
||||
await goto(`https://${app.fqdn}/repo/create`, 'css=#repo_name');
|
||||
await sendKeys('css=#repo_name', reponame);
|
||||
await click('css=#auto-init');
|
||||
await click('//button[contains(text(), "Create Repository")]');
|
||||
await goto(`https://${app.fqdn}/repo/create`, 'label=Repository Name');
|
||||
await sendKeys('label=Repository Name', reponame);
|
||||
await click(/Initialize Repository/);
|
||||
await click('Create Repository');
|
||||
await waitForUrl(`https://${app.fqdn}/${username}/${reponame}`);
|
||||
}
|
||||
|
||||
@@ -140,8 +111,6 @@ describe('Application life cycle test', function () {
|
||||
it('can logout', logout);
|
||||
|
||||
it('can login', loginGiteaOIDC);
|
||||
it('can set avatar', setAvatar);
|
||||
it('can get avatar', checkAvatar);
|
||||
|
||||
it('can add public key', addPublicKey);
|
||||
|
||||
@@ -160,7 +129,6 @@ describe('Application life cycle test', function () {
|
||||
it('restore app', cloudronCli.restoreFromLatestBackup);
|
||||
|
||||
it('can login', loginGiteaOIDC);
|
||||
it('can get avatar', checkAvatar);
|
||||
it('can clone the url', cloneRepo);
|
||||
it('file exists in repo', function () {
|
||||
assert.strictEqual(fs.existsSync(`${repodir}/newfile`), true);
|
||||
@@ -169,7 +137,6 @@ describe('Application life cycle test', function () {
|
||||
it('move to different location', cloudronCli.changeLocation);
|
||||
|
||||
it('can login', loginGiteaOIDC);
|
||||
it('can get avatar', checkAvatar);
|
||||
it('can clone the url', cloneRepo);
|
||||
it('file exists in repo', function () {
|
||||
assert.strictEqual(fs.existsSync(`${repodir}/newfile`), true);
|
||||
@@ -186,13 +153,11 @@ describe('Application life cycle test', function () {
|
||||
|
||||
it('uninstall app (no sso)', cloudronCli.uninstall);
|
||||
|
||||
it('can install app', async function () {
|
||||
it('can install app from appstore', async function () {
|
||||
await cloudronCli.appstoreInstall({ tcpPortFlags: INSTALL_TCP_FLAGS });
|
||||
});
|
||||
|
||||
it('can login', loginGiteaOIDCOld);
|
||||
it('can set avatar', setAvatar);
|
||||
it('can get avatar', checkAvatar);
|
||||
it('can login', loginGiteaOIDC);
|
||||
it('can add public key', addPublicKey);
|
||||
it('can create repo', createRepo);
|
||||
it('can clone the url', cloneRepo);
|
||||
@@ -204,7 +169,6 @@ describe('Application life cycle test', function () {
|
||||
it('can logout', logout);
|
||||
|
||||
it('can login', loginGiteaOIDC);
|
||||
it('can get avatar', checkAvatar);
|
||||
it('can clone the url', cloneRepo);
|
||||
it('file exists in cloned repo', fileExists);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user