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

feat: 990 - new knowledge panel "halfWidthOnMobile" field #992

Merged
merged 1 commit into from
Nov 14, 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
4 changes: 4 additions & 0 deletions lib/src/model/knowledge_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class KnowledgePanel extends JsonObject {
@JsonKey(unknownEnumValue: KnowledgePanelSize.UNKNOWN)
final KnowledgePanelSize? size;

@JsonKey(name: 'half_width_on_mobile')
final bool? halfWidthOnMobile;

const KnowledgePanel({
this.titleElement,
this.level,
Expand All @@ -113,6 +116,7 @@ class KnowledgePanel extends JsonObject {
this.topics,
this.evaluation,
this.size,
this.halfWidthOnMobile,
});

factory KnowledgePanel.fromJson(Map<String, dynamic> json) =>
Expand Down
2 changes: 2 additions & 0 deletions lib/src/model/knowledge_panel.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions test/api_get_product_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ void main() {
}

group('$OpenFoodAPIClient get products', () {
test('get KP halfWidthOnMobile', () async {
const String barcode = '737628064502';

final ProductQueryConfiguration configurations =
ProductQueryConfiguration(
barcode,
language: OpenFoodFactsLanguage.ENGLISH,
fields: [ProductField.KNOWLEDGE_PANELS],
version: ProductQueryVersion.v3,
);
final ProductResultV3 result = await getProductV3InProd(
configurations,
);
expect(result.status, ProductResultV3.statusSuccess);
expect(result.barcode, barcode);
expect(result.product, isNotNull);
bool found = false;
for (final KnowledgePanel panel
in result.product!.knowledgePanels!.panelIdToPanelMap.values) {
if (panel.halfWidthOnMobile == true) {
found = true;
}
}
expect(found, isTrue);
});

test('get product tiny twists - Rold Gold Pretzels - 16 OZ. (1 LB) 453.6g',
() async {
//Refactor the test once the issue #48 is fixed
Expand Down
Loading