Skip to content

Commit

Permalink
tests: add test to check for buttons only visible to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalinDe committed Nov 24, 2023
1 parent a15b2e3 commit cc91b4c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions web/frontend/tests/integration/homepage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ async function login (page: any) {
await login.click();
}

async function assertOnlyVisibleToAdmin(page: any, key: string) {
const element = page.getByRole('link', { name: i18n.t(key) });
await expect(element).toBeHidden();
await login(page);
await expect(element).toBeVisible();
}

test('Assert homepage title', async({ page }) => {
await page.goto(process.env.FRONT_END_URL);
await expect(page).toHaveTitle(/D-Voting/);
Expand All @@ -31,8 +38,10 @@ test('Assert login button', async({ page }) => {

test('Assert create form button', async({ page }) => {
await page.goto(process.env.FRONT_END_URL);
const createForm = page.getByRole('link', { name: i18n.t('navBarCreateForm') });
await expect(createForm).toBeHidden();
await login(page);
await expect(createForm).toBeVisible();
await assertOnlyVisibleToAdmin(page, 'navBarCreateForm');
});

test('Assert admin button', async({ page }) => {
await page.goto(process.env.FRONT_END_URL);
await assertOnlyVisibleToAdmin(page, 'navBarAdmin');
});

0 comments on commit cc91b4c

Please sign in to comment.