Skip to content

Commit

Permalink
Add create user with invoice permission test (#27)
Browse files Browse the repository at this point in the history
* OBPIH-6883 add fixtures for invoice pages

* OBPIH-6883 add invoice pages

* OBPIH-6883 add test for user with invoice permission
  • Loading branch information
kkrawczyk123 authored Dec 18, 2024
1 parent d4f961c commit 21b4082
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/fixtures/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import UserListPage from '@/pages/user/UserListPage';
import LocationData from '@/utils/LocationData';
import ProductData from '@/utils/ProductData';
import UserData from '@/utils/UserData';
import CreateInvoicePage from '@/pages/invoice/CreateInvoicePage';
import InvoiceListPage from '@/pages/invoice/InvoiceListPage';

type Fixtures = {
// PAGES
Expand All @@ -54,6 +56,8 @@ type Fixtures = {
createInboundPage: CreateInbound;
inboundListPage: InboundListPage;
receivingPage: ReceivingPage;
createInvoicePage: CreateInvoicePage;
invoiceListPage: InvoiceListPage;
// COMPONENTS
navbar: Navbar;
locationChooser: LocationChooser;
Expand Down Expand Up @@ -111,6 +115,8 @@ export const test = baseTest.extend<Fixtures>({
use(new StockMovementShowPage(page)),
createProductPage: async ({ page }, use) => use(new CreateProductPage(page)),
productShowPage: async ({ page }, use) => use(new ProductShowPage(page)),
createInvoicePage: async ({ page }, use) => use(new CreateInvoicePage(page)),
invoiceListPage: async ({ page }, use) => use(new InvoiceListPage(page)),
// COMPONENTS
navbar: async ({ page }, use) => use(new Navbar(page)),
locationChooser: async ({ page }, use) => use(new LocationChooser(page)),
Expand Down
14 changes: 14 additions & 0 deletions src/pages/invoice/CreateInvoicePage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect } from '@/fixtures/fixtures';
import BasePageModel from '@/pages/BasePageModel';

class CreateInvoicePage extends BasePageModel {
async isLoaded() {
await expect(this.page.getByText('Vendor Invoice Number')).toBeVisible();
}

async goToPage() {
await this.page.goto('./invoice/create');
}
}

export default CreateInvoicePage;
18 changes: 18 additions & 0 deletions src/pages/invoice/InvoiceListPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect } from '@/fixtures/fixtures';
import BasePageModel from '@/pages/BasePageModel';

class InvoiceListPage extends BasePageModel {
async isLoaded() {
await expect(this.page.getByText('List Invoices')).toBeVisible();
}

async goToPage() {
await this.page.goto('./invoice/list');
}

get invoiceListHeader() {
return this.page.locator('.list-page-header').getByText('List Invoices');
}
}

export default InvoiceListPage;
45 changes: 45 additions & 0 deletions src/tests/users/userSettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import LocationChooser from '@/components/LocationChooser';
import Navbar from '@/components/Navbar';
import { expect, test } from '@/fixtures/fixtures';
import CreateInvoicePage from '@/pages/invoice/CreateInvoicePage';
import InvoiceListPage from '@/pages/invoice/InvoiceListPage';
import LoginPage from '@/pages/LoginPage';
import { CreateUserType } from '@/types';
import UniqueIdentifier from '@/utils/UniqueIdentifier';
Expand Down Expand Up @@ -152,3 +155,45 @@ test('Add requestor permission to non manage inventory depot', async ({
await expect(newUserLocationChooser.getLocation(location.name)).toBeVisible();
await newUserLocationChooser.getLocation(location.name).click();
});

test('Add new user with invoice permission', async ({
editUserPage,
mainLocationService,
emptyUserContext,
}) => {
await test.step('Select role "Admin"', async () => {
await editUserPage.authorizationTabSection.defaultRoleSelect.click();
await editUserPage.authorizationTabSection.getUserRole('Admin').click();
await editUserPage.authorizationTabSection.defaultRoleSelect.click();
await editUserPage.authorizationTabSection
.getUserRole('Invoice user')
.click();
await editUserPage.authorizationTabSection.saveButton.click();
});

const location = await mainLocationService.getLocation();
const newUserPage = await emptyUserContext.newPage();
const newUserLoginPage = new LoginPage(newUserPage);
const newUserLocationChooser = new LocationChooser(newUserPage);
const newUserCreateInvoicePage = new CreateInvoicePage(newUserPage);
const newUserListInvoicePage = new InvoiceListPage(newUserPage);

await test.step('Login as new user', async () => {
await newUserLoginPage.goToPage();
await newUserLoginPage.fillLoginForm(formData.username, formData.password);
await newUserLoginPage.loginButton.click();
});

await newUserLocationChooser
.getOrganization(location.organization?.name)
.click();
await expect(newUserLocationChooser.getLocation(location.name)).toBeVisible();
await newUserLocationChooser.getLocation(location.name).click();

await test.step('Assert access to invoice pages', async () => {
await newUserCreateInvoicePage.goToPage();
await expect(newUserPage.getByText('Vendor Invoice Number')).toBeVisible();
await newUserListInvoicePage.goToPage();
await expect(newUserListInvoicePage.invoiceListHeader).toBeVisible();
});
});

0 comments on commit 21b4082

Please sign in to comment.