Skip to content

Commit

Permalink
feat: 990 - new knowledge panel "halfWidthOnMobile" field (#992)
Browse files Browse the repository at this point in the history
Impacted files:
* `api_get_product_test.dart`: added a test for the new KP `halfWidthOnMobile` field
* `knowledge_panel.dart`: added `halfWidthOnMobile` field
* `knowledge_panel.g.dart`: wtf
  • Loading branch information
monsieurtanuki authored Nov 14, 2024
1 parent 78c1dd9 commit 09d203a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
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

0 comments on commit 09d203a

Please sign in to comment.