diff --git a/test/test.js b/test/test.js index 5ce5e4b..019ae0c 100644 --- a/test/test.js +++ b/test/test.js @@ -3,7 +3,7 @@ import assert from 'node:assert/strict'; import superagent from '@cloudron/superagent'; -import { app, clearCache, click, cloudronCli, goto, loginOIDC, password, sendKeys, setupBrowser, takeScreenshot, teardownBrowser, username, waitFor } from '@cloudron/charlie'; +import { app, clearCache, click, cloudronCli, press, goto, loginOIDC, password, sendKeys, setupBrowser, takeScreenshot, teardownBrowser, username, waitFor } from '@cloudron/charlie'; /* global it, describe, before, after, afterEach */ @@ -24,11 +24,11 @@ describe('Application life cycle test', function () { } async function login(uname, pass) { - await goto(`https://${app.fqdn}`, 'css=#loginButton'); - await sendKeys('css=#username', uname); - await sendKeys('css=#passwordPlain', pass); - await click('css=#loginButton'); - await waitFor('css=#btn-subscription'); + await goto(`https://${app.fqdn}`, 'label=Username'); + await sendKeys('label=Username', uname); + await sendKeys('label=Password', pass); + await click('Login', { role: 'button' }); // there is a link at the top + await waitFor('Subscription management'); } async function loginViaOIDC() { @@ -37,30 +37,28 @@ describe('Application life cycle test', function () { } async function addSubscription() { - const url = 'https://blog.cloudron.io/rss/'; - const addUrl = app.manifest.version === '1.10.0' ? `${baseUrl()}/i/?c=subscription` : `${baseUrl()}/i/?c=subscription&a=add`; - - await goto(addUrl, 'xpath=//input[@name="url_rss"]'); - await sendKeys('xpath=//input[@name="url_rss"]', url); - await click('xpath=//form[@id="add_rss"]//button[text()="Add"]'); - await waitFor('xpath=//div[@id="notification" and contains(@class, "good")]'); + await goto(`${baseUrl()}/i/?c=subscription&a=add`, 'label=Feed URL'); + await sendKeys('label=Feed URL', 'https://blog.cloudron.io/rss/'); + await press('label=Feed URL', 'Enter'); // there are multiple "Add" buttons on that page + await waitFor('RSS feed Cloudron has been added'); } - async function enableApi(relogin = true) { + async function enableApi({ relogin = true } = {}) { await goto(`${baseUrl()}/i/?c=auth`); if (relogin) { - await sendKeys('css=#passwordPlain', admin_password); + await sendKeys('label=Password', admin_password); await click('Login'); } - await click('css=#api_enabled'); + await click(/Allow API access/); await click('Submit'); + await waitFor(/Configuration has been updated/); } async function checkApiConfiguration() { - await goto(`${baseUrl()}/api/`, 'xpath=//dd[@id="greaderOutput" and contains(text(), "PASS")]'); - await waitFor('xpath=//dd[@id="feverOutput" and contains(text(), "PASS")]'); + await goto(`${baseUrl()}/api/`, /PASS/); + await waitFor(/PASS/); } async function subscriptionExists() { @@ -68,11 +66,13 @@ describe('Application life cycle test', function () { } async function getStaticExtensionFile() { - const response = await superagent.get(`${baseUrl()}/ext.php?f=xExtension-StickyFeeds/static/script.js&t=js`) - .buffer(true) + const url = `${baseUrl()}/ext.php?f=xExtension-StickyFeeds/static/script.js&t=js`; + const response = await superagent.get(url) + .set('Cache-Control', 'no-store') + .set('Pragma', 'no-cache') .ok(() => true); assert.strictEqual(response.status, 200); - assert.ok(response.text.includes('sticky_feeds')); + assert.ok(response.body.toString('utf8').includes('sticky_feeds')); // content-type is application/javascript, so body is a buffer } // No SSO @@ -80,7 +80,7 @@ describe('Application life cycle test', function () { it('can login', login.bind(null, admin_username, admin_password)); it('can subscribe', addSubscription); - it('can enable API', enableApi.bind(null, true /* relogin */)); + it('can enable API', () => enableApi({ relogin: true })); it('can check configuration', checkApiConfiguration); it('subscription exists', subscriptionExists); it('can get static extension file', getStaticExtensionFile); @@ -93,7 +93,7 @@ describe('Application life cycle test', function () { it('can make user Administrator', () => cloudronCli.exec(`bash -c "php cli/reconfigure.php --default-user ${username}"`)); it('can login OIDC', () => loginViaOIDC(username, password)); it('can subscribe', addSubscription); - it('can enable API', enableApi.bind(null, false /* relogin */)); + it('can enable API', () => enableApi({ relogin: false })); it('can check configuration', checkApiConfiguration); it('subscription exists', subscriptionExists); it('can get static extension file', getStaticExtensionFile); @@ -124,6 +124,7 @@ describe('Application life cycle test', function () { it('can update', cloudronCli.update); + it('can login OIDC', loginViaOIDC); it('subscription exists', subscriptionExists); it('can get static extension file', getStaticExtensionFile);