Skip to content

Commit a5b133a

Browse files
committed
Supports icons dependent on theme
1 parent 8bd7ba4 commit a5b133a

File tree

8 files changed

+258
-90
lines changed

8 files changed

+258
-90
lines changed

components/suggest/src/rs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,10 @@ pub(crate) struct DownloadedYelpSuggestion {
461461
pub location_signs: Vec<DownloadedYelpLocationSign>,
462462
#[serde(rename = "yelpModifiers")]
463463
pub yelp_modifiers: Vec<String>,
464-
#[serde(rename = "icon")]
465-
pub icon_id: String,
464+
#[serde(rename = "iconLightTheme")]
465+
pub icon_light_theme_id: String,
466+
#[serde(rename = "iconDarkTheme")]
467+
pub icon_dark_theme_id: String,
466468
pub score: f64,
467469
}
468470

components/suggest/src/schema.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ CREATE TABLE yelp_location_signs(
113113
) WITHOUT ROWID;
114114
115115
CREATE TABLE yelp_custom_details(
116-
icon_id TEXT PRIMARY KEY,
116+
icon_light_theme_id TEXT NOT NULL,
117+
icon_dark_theme_id TEXT NOT NULL,
117118
score REAL NOT NULL,
118-
record_id TEXT NOT NULL
119+
record_id TEXT NOT NULL,
120+
PRIMARY KEY (icon_light_theme_id, icon_dark_theme_id)
119121
) WITHOUT ROWID;
120122
121123
CREATE TABLE mdn_custom_details(

components/suggest/src/store.rs

Lines changed: 149 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,12 +1259,12 @@ mod tests {
12591259
json!([burnout_pocket(), multimatch_pocket(),]),
12601260
)
12611261
.with_record("yelp-suggestions", "data-4", json!([ramen_yelp(),]))
1262-
.with_record("yeld-suggestions", "data-4", json!([ramen_yelp(),]))
12631262
.with_record("mdn-suggestions", "data-5", json!([array_mdn(),]))
12641263
.with_icon(good_place_eats_icon())
12651264
.with_icon(california_icon())
12661265
.with_icon(caltech_icon())
1267-
.with_icon(yelp_favicon())
1266+
.with_icon(yelp_light_theme_icon())
1267+
.with_icon(yelp_dark_theme_icon())
12681268
.with_icon(multimatch_wiki_icon()),
12691269
);
12701270

@@ -2758,68 +2758,165 @@ mod tests {
27582758
fn query_no_yelp_icon_data() -> anyhow::Result<()> {
27592759
before_each();
27602760

2761-
let snapshot = Snapshot::with_records(json!([{
2762-
"id": "data-1",
2763-
"type": "yelp-suggestions",
2764-
"last_modified": 15,
2765-
"attachment": {
2766-
"filename": "data-1.json",
2767-
"mimetype": "application/json",
2768-
"location": "data-1.json",
2769-
"hash": "",
2770-
"size": 0,
2771-
},
2772-
}]))?
2773-
.with_data(
2774-
"data-1.json",
2775-
json!([
2776-
{
2761+
let store = TestStore::new(
2762+
MockRemoteSettingsClient::default()
2763+
.with_record("yelp-suggestions", "data-1", json!([{
2764+
"subjects": ["ramen"],
2765+
"preModifiers": [],
2766+
"postModifiers": [],
2767+
"locationSigns": [],
2768+
"yelpModifiers": [],
2769+
"iconLightTheme": "yelp-light-theme-icon",
2770+
"iconDarkTheme": "yelp-dark-theme-icon",
2771+
"score": 0.5
2772+
}]))
2773+
);
2774+
2775+
store.ingest(SuggestIngestionConstraints::default());
2776+
2777+
assert_eq!(
2778+
store.fetch_suggestions(SuggestionQuery::yelp("ramen")),
2779+
vec![
2780+
Suggestion::Yelp {
2781+
title: "ramen".into(),
2782+
url: "https://www.yelp.com/search?find_desc=ramen".into(),
2783+
icon_light_theme: None,
2784+
icon_light_theme_mimetype: None,
2785+
icon_dark_theme: None,
2786+
icon_dark_theme_mimetype: None,
2787+
score: 0.5,
2788+
has_location_sign: false,
2789+
subject_exact_match: true,
2790+
location_param: "find_loc".into(),
2791+
}
2792+
],
2793+
);
2794+
Ok(())
2795+
}
2796+
2797+
#[test]
2798+
fn query_full_yelp_icon_data() -> anyhow::Result<()> {
2799+
before_each();
2800+
2801+
let store = TestStore::new(
2802+
MockRemoteSettingsClient::default()
2803+
.with_record("yelp-suggestions", "data-1", json!([{
27772804
"subjects": ["ramen"],
27782805
"preModifiers": [],
27792806
"postModifiers": [],
27802807
"locationSigns": [],
27812808
"yelpModifiers": [],
27822809
"icon": "yelp-favicon",
2810+
"iconLightTheme": "yelp-light-theme-icon",
2811+
"iconDarkTheme": "yelp-dark-theme-icon",
27832812
"score": 0.5
2784-
},
2785-
]),
2786-
)?;
2813+
}]))
2814+
.with_icon(yelp_favicon())
2815+
.with_icon(yelp_light_theme_icon())
2816+
.with_icon(yelp_dark_theme_icon())
2817+
);
27872818

2788-
let store = unique_test_store(SnapshotSettingsClient::with_snapshot(snapshot));
2819+
store.ingest(SuggestIngestionConstraints::default());
27892820

2790-
store.ingest(SuggestIngestionConstraints::default())?;
2821+
assert_eq!(
2822+
store.fetch_suggestions(SuggestionQuery::yelp("ramen")),
2823+
vec![
2824+
Suggestion::Yelp {
2825+
title: "ramen".into(),
2826+
url: "https://www.yelp.com/search?find_desc=ramen".into(),
2827+
icon_light_theme: Some("yelp-light-theme-icon-data".into()),
2828+
icon_light_theme_mimetype: Some("image/svg+xml".into()),
2829+
icon_dark_theme: Some("yelp-dark-theme-icon-data".into()),
2830+
icon_dark_theme_mimetype: Some("image/svg+xml".into()),
2831+
score: 0.5,
2832+
has_location_sign: false,
2833+
subject_exact_match: true,
2834+
location_param: "find_loc".into(),
2835+
}
2836+
],
2837+
);
2838+
Ok(())
2839+
}
27912840

2792-
let table = [(
2793-
"keyword = ramen; Yelp only",
2794-
SuggestionQuery {
2795-
keyword: "ramen".into(),
2796-
providers: vec![SuggestionProvider::Yelp],
2797-
limit: None,
2798-
},
2799-
expect![[r#"
2800-
[
2801-
Yelp {
2802-
url: "https://www.yelp.com/search?find_desc=ramen",
2803-
title: "ramen",
2804-
icon: None,
2805-
icon_mimetype: None,
2806-
score: 0.5,
2807-
has_location_sign: false,
2808-
subject_exact_match: true,
2809-
location_param: "find_loc",
2810-
},
2811-
]
2812-
"#]],
2813-
)];
2841+
#[test]
2842+
fn query_only_light_theme_yelp_icon_data() -> anyhow::Result<()> {
2843+
before_each();
28142844

2815-
for (what, query, expect) in table {
2816-
expect.assert_debug_eq(
2817-
&store
2818-
.query(query)
2819-
.with_context(|| format!("Couldn't query store for {}", what))?,
2820-
);
2821-
}
2845+
let store = TestStore::new(
2846+
MockRemoteSettingsClient::default()
2847+
.with_record("yelp-suggestions", "data-1", json!([{
2848+
"subjects": ["ramen"],
2849+
"preModifiers": [],
2850+
"postModifiers": [],
2851+
"locationSigns": [],
2852+
"yelpModifiers": [],
2853+
"iconLightTheme": "yelp-light-theme-icon",
2854+
"iconDarkTheme": "yelp-dark-theme-icon",
2855+
"score": 0.5
2856+
}]))
2857+
.with_icon(yelp_light_theme_icon())
2858+
);
2859+
2860+
store.ingest(SuggestIngestionConstraints::default());
2861+
2862+
assert_eq!(
2863+
store.fetch_suggestions(SuggestionQuery::yelp("ramen")),
2864+
vec![
2865+
Suggestion::Yelp {
2866+
title: "ramen".into(),
2867+
url: "https://www.yelp.com/search?find_desc=ramen".into(),
2868+
icon_light_theme: Some("yelp-light-theme-icon-data".into()),
2869+
icon_light_theme_mimetype: Some("image/svg+xml".into()),
2870+
icon_dark_theme: None,
2871+
icon_dark_theme_mimetype: None,
2872+
score: 0.5,
2873+
has_location_sign: false,
2874+
subject_exact_match: true,
2875+
location_param: "find_loc".into(),
2876+
}
2877+
],
2878+
);
2879+
Ok(())
2880+
}
28222881

2882+
#[test]
2883+
fn query_only_dark_theme_yelp_icon_data() -> anyhow::Result<()> {
2884+
before_each();
2885+
2886+
let store = TestStore::new(
2887+
MockRemoteSettingsClient::default()
2888+
.with_record("yelp-suggestions", "data-1", json!([{
2889+
"subjects": ["ramen"],
2890+
"preModifiers": [],
2891+
"postModifiers": [],
2892+
"locationSigns": [],
2893+
"yelpModifiers": [],
2894+
"iconLightTheme": "yelp-light-theme-icon",
2895+
"iconDarkTheme": "yelp-dark-theme-icon",
2896+
"score": 0.5
2897+
}]))
2898+
.with_icon(yelp_dark_theme_icon())
2899+
);
2900+
2901+
store.ingest(SuggestIngestionConstraints::default());
2902+
2903+
assert_eq!(
2904+
store.fetch_suggestions(SuggestionQuery::yelp("ramen")),
2905+
vec![
2906+
Suggestion::Yelp {
2907+
title: "ramen".into(),
2908+
url: "https://www.yelp.com/search?find_desc=ramen".into(),
2909+
icon_light_theme: None,
2910+
icon_light_theme_mimetype: None,
2911+
icon_dark_theme: Some("yelp-dark-theme-icon-data".into()),
2912+
icon_dark_theme_mimetype: Some("image/svg+xml".into()),
2913+
score: 0.5,
2914+
has_location_sign: false,
2915+
subject_exact_match: true,
2916+
location_param: "find_loc".into(),
2917+
}
2918+
],
2919+
);
28232920
Ok(())
28242921
}
28252922

components/suggest/src/suggest.udl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ interface Suggestion {
7979
Yelp(
8080
string url,
8181
string title,
82-
sequence<u8>? icon,
83-
string? icon_mimetype,
82+
sequence<u8>? icon_light_theme,
83+
string? icon_light_theme_mimetype,
84+
sequence<u8>? icon_dark_theme,
85+
string? icon_dark_theme_mimetype,
8486
f64 score,
8587
boolean has_location_sign,
8688
boolean subject_exact_match,

components/suggest/src/suggestion.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ pub enum Suggestion {
6565
Yelp {
6666
url: String,
6767
title: String,
68-
icon: Option<Vec<u8>>,
69-
icon_mimetype: Option<String>,
68+
icon_light_theme: Option<Vec<u8>>,
69+
icon_light_theme_mimetype: Option<String>,
70+
icon_dark_theme: Option<Vec<u8>>,
71+
icon_dark_theme_mimetype: Option<String>,
7072
score: f64,
7173
has_location_sign: bool,
7274
subject_exact_match: bool,

components/suggest/src/testing/data.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ pub fn ramen_yelp() -> JsonValue {
326326
{ "keyword": "near me", "needLocation": false },
327327
],
328328
"yelpModifiers": ["yelp", "yelp keyword"],
329-
"icon": "yelp-favicon",
329+
"iconLightTheme": "yelp-light-theme-icon",
330+
"iconDarkTheme": "yelp-dark-theme-icon",
330331
"score": 0.5
331332
})
332333
}
@@ -335,8 +336,10 @@ pub fn ramen_suggestion(title: &str, url: &str) -> Suggestion {
335336
Suggestion::Yelp {
336337
title: title.into(),
337338
url: url.into(),
338-
icon: Some("yelp-favicon-data".into()),
339-
icon_mimetype: Some("image/svg+xml".into()),
339+
icon_light_theme: Some("yelp-light-theme-icon-data".into()),
340+
icon_light_theme_mimetype: Some("image/svg+xml".into()),
341+
icon_dark_theme: Some("yelp-dark-theme-icon-data".into()),
342+
icon_dark_theme_mimetype: Some("image/svg+xml".into()),
340343
score: 0.5,
341344
has_location_sign: true,
342345
subject_exact_match: true,
@@ -352,6 +355,22 @@ pub fn yelp_favicon() -> MockIcon {
352355
}
353356
}
354357

358+
pub fn yelp_light_theme_icon() -> MockIcon {
359+
MockIcon {
360+
id: "yelp-light-theme-icon",
361+
data: "yelp-light-theme-icon-data",
362+
mimetype: "image/svg+xml",
363+
}
364+
}
365+
366+
pub fn yelp_dark_theme_icon() -> MockIcon {
367+
MockIcon {
368+
id: "yelp-dark-theme-icon",
369+
data: "yelp-dark-theme-icon-data",
370+
mimetype: "image/svg+xml",
371+
}
372+
}
373+
355374
pub fn array_mdn() -> JsonValue {
356375
json!({
357376
"description": "Javascript Array",

components/suggest/src/testing/mod.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,21 @@ impl Suggestion {
4646
Self::Yelp {
4747
title,
4848
url,
49-
icon,
50-
icon_mimetype,
49+
icon_light_theme,
50+
icon_light_theme_mimetype,
51+
icon_dark_theme,
52+
icon_dark_theme_mimetype,
5153
score,
5254
subject_exact_match,
5355
location_param,
5456
..
5557
} => Self::Yelp {
5658
title,
5759
url,
58-
icon,
59-
icon_mimetype,
60+
icon_light_theme,
61+
icon_light_theme_mimetype,
62+
icon_dark_theme,
63+
icon_dark_theme_mimetype,
6064
score,
6165
subject_exact_match,
6266
location_param,
@@ -71,17 +75,21 @@ impl Suggestion {
7175
Self::Yelp {
7276
title,
7377
url,
74-
icon,
75-
icon_mimetype,
78+
icon_light_theme,
79+
icon_light_theme_mimetype,
80+
icon_dark_theme,
81+
icon_dark_theme_mimetype,
7682
score,
7783
has_location_sign,
7884
location_param,
7985
..
8086
} => Self::Yelp {
8187
title,
8288
url,
83-
icon,
84-
icon_mimetype,
89+
icon_light_theme,
90+
icon_light_theme_mimetype,
91+
icon_dark_theme,
92+
icon_dark_theme_mimetype,
8593
score,
8694
subject_exact_match,
8795
location_param,

0 commit comments

Comments
 (0)