From 711c34b3dcb09fa5d515188311179f16b2a0b80c Mon Sep 17 00:00:00 2001 From: Theresa Gresch Date: Thu, 21 Nov 2019 18:56:11 +0100 Subject: [PATCH] Add acceptance test for login (#150) --- frontend/tests/acceptance/authentication.js | 39 +++++++++++++++++++++ frontend/tests/acceptance/page-model.js | 11 ++++++ 2 files changed, 50 insertions(+) create mode 100644 frontend/tests/acceptance/authentication.js diff --git a/frontend/tests/acceptance/authentication.js b/frontend/tests/acceptance/authentication.js new file mode 100644 index 000000000..147b27c44 --- /dev/null +++ b/frontend/tests/acceptance/authentication.js @@ -0,0 +1,39 @@ +import { Selector } from 'testcafe'; +import testcafeconfig from './testcafeconfig'; +import Page from "./page-model"; + +fixture`Test login and logout` + .page`${testcafeconfig.url}`; + +const page = new Page(); + +test('Login', async t => { + await page.openNav(); + await t + .expect(Selector('a[href="/library"]').exists, {timeout: 5000}).notOk() + .expect(Selector('a[href="/settings"]').exists, {timeout: 5000}).notOk() + .click(Selector('a[href="/login"]')); + await page.login('photoprism'); + await page.openNav(); + await t + .expect(Selector('a[href="/library"]').exists, {timeout: 5000}).ok() + .expect(Selector('a[href="/settings"]').exists, {timeout: 5000}).ok() + .expect(Selector('a[href="/login"]').exists, {timeout: 5000}).notOk(); +}), +test('Logout', async t => { + await page.openNav(); + await t + .click(Selector('a[href="/login"]')); + await page.login('photoprism'); + await page.openNav(); + await t + .expect(Selector('a[href="/library"]').exists, {timeout: 5000}).ok() + .expect(Selector('a[href="/settings"]').exists, {timeout: 5000}).ok() + .expect(Selector('a[href="/login"]').exists, {timeout: 5000}).notOk() + await page.logout(); + await page.openNav(); + await t + .expect(Selector('a[href="/library"]').exists, {timeout: 5000}).notOk() + .expect(Selector('a[href="/settings"]').exists, {timeout: 5000}).notOk() + .expect(Selector('a[href="/login"]').exists, {timeout: 5000}).ok() +}); \ No newline at end of file diff --git a/frontend/tests/acceptance/page-model.js b/frontend/tests/acceptance/page-model.js index 5f922bb6e..e7d072ea0 100644 --- a/frontend/tests/acceptance/page-model.js +++ b/frontend/tests/acceptance/page-model.js @@ -82,4 +82,15 @@ export default class Page { const countSelectedInt = (Number.isInteger(parseInt(countSelected))) ? parseInt(countSelected) : 0; return countSelectedInt; } + + async login(password) { + await t + .typeText(Selector('input[type="password"]'), password) + .pressKey('enter'); + } + + async logout() { + await t + .click(Selector('div.p-navigation-logout')); + } }