Skip to content
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
1 change: 0 additions & 1 deletion src/app/ew/fabric/handlers/EpiHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Batch, Leaflet, Product, ProductMarket, ProductStrength } from '..';
import { CrudFieldComponent, FieldsetComponent, ListComponent } from 'src/lib/components';
import { OperationKeys, readonly } from '@decaf-ts/db-decorators';
import { DecafComponent } from '@decaf-ts/ui-decorators';
import { el } from '@faker-js/faker/.';

export async function renderMakets<C extends CrudFieldComponent>(instance: C): Promise<void> {
return await new EpiHandler().renderMakets(instance);
Expand Down
27 changes: 5 additions & 22 deletions src/app/pages/products/products.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,28 +146,6 @@ export class ProductsPage extends NgxModelPageDirective implements OnInit {
this.route = 'products';

await this.initialize();

function calculateGtinCheckSum(digits: string): string {
digits = '' + digits;
if (digits.length !== 13) throw new Error('needs to received 13 digits');
const multiplier = [3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3];
let sum = 0;
try {
// multiply each digit for its multiplier according to the table
for (let i = 0; i < 13; i++) sum += parseInt(digits.charAt(i)) * multiplier[i];

// Find the nearest equal or higher multiple of ten
const remainder = sum % 10;
let nearest;
if (remainder === 0) nearest = sum;
else nearest = sum - remainder + 10;

return nearest - sum + '';
} catch (e) {
throw new Error(`Did this received numbers? ${e}`);
}
}

// function generateGtin(): string {
// function pad(num: number, width: number, padding: string = '0') {
// const n = num + '';
Expand Down Expand Up @@ -208,4 +186,9 @@ export class ProductsPage extends NgxModelPageDirective implements OnInit {
// }
// console.log(this.model);
}

override async ionViewWillEnter(): Promise<void> {
await this.refresh(this.modelId);
console.log(this.model);
}
}
86 changes: 53 additions & 33 deletions src/app/utils/FakerRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { ProductStrength } from '../ew/fabric/ProductStrength';
import { getModelAndRepository } from 'src/lib/engine/helpers';
import { generate } from 'rxjs';
import { generateGtin } from '../ew/fabric/gtin';
import axios from 'axios';
import { ProductImage } from '../ew/fabric/ProductImage';
enum ProductNames {
aspirin = 'Aspirin',
ibuprofen = 'Ibuprofen',
Expand Down Expand Up @@ -64,6 +66,17 @@ async function getBatchs(): Promise<Batch[]> {
return [];
}

async function readProductFile(): Promise<string> {
const filePath = '/assets/images/ew/product.txt';
try {
const response = await axios.get(filePath);
return response.data || '';
} catch (error: unknown) {
console.error(`Error reading product.txt: ${(error as Error)?.message || (error as string)}`);
throw error;
}
}

export class FakerRepository<T extends Model> extends DecafFakerRepository<T> {
public override async initialize(): Promise<void> {
await super.initialize();
Expand All @@ -90,16 +103,23 @@ export class FakerRepository<T extends Model> extends DecafFakerRepository<T> {
break;
}
case Product.name: {
const image = await readProductFile();
this.limit = 2;
this.propFnMapper = {
productCode: () => generateGtin(),
};
data = (await this.generateData<T & Product>(ProductNames, 'inventedName', 'string')).map(
(item: Partial<Product>, index: number) => {
delete item?.['imageData'];
data = (await this.generateData(ProductNames, 'inventedName', 'string')).map(
(item: Partial<Product>) => {
const productCode = item.productCode;
// const imageData = {
// productCode,
// content: image,
// } as ProductImage;
// item.imageData = imageData;
delete item.imageData;
item.markets = [];
item.strengths = [];
return item as T;
return Model.build(item, Product.name) as T;
},
);
break;
Expand Down Expand Up @@ -131,37 +151,37 @@ export class FakerRepository<T extends Model> extends DecafFakerRepository<T> {
break;
}
case Leaflet.name: {
const products = await getProducts();
this.limit = 2;
this.propFnMapper = {
productCode: () => this.pickRandomValue(products.map((p) => p.productCode)),
lang: () => this.pickRandomValue(['en', 'pt-br']),
epiMarket: () => this.pickRandomValue(['al', 'br']),
};
let batches = await getBatchs();
data = (await this.generateData<Leaflet>()).map((item) => {
// item.epiMarket = this.pickRandomValue([... getMarkets().map(({value}) => value)]);
item.leafletType = this.pickRandomValue(LeafletType) as LeafletType;
item.otherFilesContent = [];
// item.productCode = this.pickRandomValue(products);
item.batchNumber = batches.find((b) => b.productCode === item.productCode)?.batchNumber;
item.createdAt = item.updatedAt = faker.date.past({ years: 10 });
return item;
});
break;
}
case ProductStrength.name: {
const products = await getProducts();
this.limit = 2;
data = await this.generateData<ProductStrength>();
data = data.map((item: Partial<ProductStrength>, index: number) => {
item['productCode'] =
index % 2 === 0 ? products[0].productCode : products[1].productCode;
item.substance = this.pickRandomValue(ProductNames);
return item as T;
}) as T[];
// const products = await getProducts();
// this.limit = 2;
// this.propFnMapper = {
// productCode: () => this.pickRandomValue(products.map((p) => p.productCode)),
// lang: () => this.pickRandomValue(['en', 'pt-br']),
// epiMarket: () => this.pickRandomValue(['al', 'br']),
// };
// let batches = await getBatchs();
// data = (await this.generateData<Leaflet>()).map((item) => {
// // item.epiMarket = this.pickRandomValue([... getMarkets().map(({value}) => value)]);
// item.leafletType = this.pickRandomValue(LeafletType) as LeafletType;
// item.otherFilesContent = [];
// // item.productCode = this.pickRandomValue(products);
// item.batchNumber = batches.find((b) => b.productCode === item.productCode)?.batchNumber;
// item.createdAt = item.updatedAt = faker.date.past({ years: 10 });
// return item;
// });
break;
}
// case ProductStrength.name: {
// const products = await getProducts();
// this.limit = 2;
// data = await this.generateData<ProductStrength>();
// data = data.map((item: Partial<ProductStrength>, index: number) => {
// item['productCode'] =
// index % 2 === 0 ? products[0].productCode : products[1].productCode;
// item.substance = this.pickRandomValue(ProductNames);
// return item as T;
// }) as T[];
// break;
// }
default:
data = [];
}
Expand Down
1 change: 1 addition & 0 deletions src/assets/images/ew/product.txt

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/lib/services/NgxTranslateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export class NgxTranslateService extends DecafTranslateService implements DecafT
return key;
}

use(lang: string): void {
this.translateService.use(lang);
}

setFallbackLang(lang: string): Observable<InterpolatableTranslationObject> {
return this.translateService.setFallbackLang(lang);
}
Expand Down
17 changes: 7 additions & 10 deletions tests/playwright/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@ const baseUrl = 'http://localhost:8110/login';

testWithVideo('Simulate Login', async ({ page, browser }) => {
await page.goto(baseUrl);
const username = "decaf";
const password = "Passd123-";
const username = 'decaf';
const password = 'Passd123-';
await page.locator('.native-wrapper').first().click();

// const usernameInput = page.getByRole('textbox', { name: 'Username' });
const usernameInput = page.locator('[id="username"] input') || page.getByRole('textbox', { name: 'Username' });
const usernameInput =
page.locator('[id="username"] input') || page.getByRole('textbox', { name: 'Username' });
await usernameInput.fill(username);

const usernameValue = await usernameInput.inputValue();
expect(usernameValue).toBe(username);

await page.waitForTimeout(500);

const passwordInput = page.locator('[id="password"] input') || page.getByRole('textbox', { name: 'Password' });
const passwordInput =
page.locator('[id="password"] input') || page.getByRole('textbox', { name: 'Password' });
await passwordInput.fill(password);
const passwordValue = await passwordInput.inputValue();

expect(passwordValue).toBe(password);

await page.waitForTimeout(500);


const button = page.getByRole('button', { name: 'login' });
await button.click();

Expand All @@ -35,8 +36,4 @@ testWithVideo('Simulate Login', async ({ page, browser }) => {
await expect(page).toHaveTitle(/Dashboard/i);

await page.waitForTimeout(1000);

})



});
Loading