Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create user with invoice permission test #27

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
Loading