Skip to content

Commit

Permalink
simplify website
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Mar 4, 2024
1 parent 69a3d9c commit 6874620
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 33 deletions.
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
};
use tera::{Context, Tera};

use crate::percy::ScreenshotData;
use crate::percy::{ScreenshotData, ScreenshotState};

mod percy;

Expand Down Expand Up @@ -39,7 +39,7 @@ struct Run {
date: String,
commit: String,
results: HashMap<String, HashMap<String, String>>,
screenshots: HashMap<String, HashMap<String, (String, String, String)>>,
screenshots: HashMap<String, HashMap<String, (String, ScreenshotState, String)>>,
logs: HashMap<String, HashMap<String, String>>,
}

Expand All @@ -58,7 +58,7 @@ fn main() {
folders.sort();
folders.reverse();

for (i, run_path) in folders.iter().take(40).enumerate() {
for (i, run_path) in folders.iter().take(30).enumerate() {
let file_name = run_path.file_name().unwrap().to_str().unwrap();
if file_name.starts_with(".") {
continue;
Expand Down Expand Up @@ -110,7 +110,7 @@ fn main() {
let screenshots =
read_percy_results(fs::read_to_string(file.as_ref().unwrap().path()).unwrap());
// sleep to limit how hard Percy API are used
thread::sleep(Duration::from_secs(3));
thread::sleep(Duration::from_secs(1));
for ScreenshotData {
example,
screenshot,
Expand All @@ -137,19 +137,19 @@ fn main() {
name,
flaky: false,
};
if changed != "no_diffs" {
if changed == ScreenshotState::Changed {
let previous = all_examples.take(&example).unwrap_or(example.clone());
all_examples.insert(Example {
flaky: true,
..previous
});
}
if diff_ratio == 0.0 && changed != "no_diffs" {
if diff_ratio == 0.0 && changed == ScreenshotState::Changed {
println!(
" - setting {} / {} ({:?}) as unchanged",
example.category, example.name, tag
);
changed = "no_diffs".to_string();
changed = ScreenshotState::Similar;
}
// If there is a screenshot but no results, mark as success
run.results
Expand Down
45 changes: 36 additions & 9 deletions src/percy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{thread, time::Duration};

use serde::Deserialize;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Debug)]
#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -99,7 +99,7 @@ fn snapshots_to_images(snapshots: SnapshotsData, build_url: &str) -> Vec<Screens
comparison_tag.os_name, comparison_tag.os_version, comparison_tag.name
))
}
let image_id = if attributes.review_state_reason == "no_diffs" {
let image_id = if attributes.review_state_reason == ReviewStateReason::NoDiffs {
let base_screenshot_id = comparison_relationship
.base_screenshot
.data
Expand All @@ -120,8 +120,11 @@ fn snapshots_to_images(snapshots: SnapshotsData, build_url: &str) -> Vec<Screens
})
.unwrap();
base_screenshot.image.data.as_ref().unwrap().id.clone()
} else if ["unreviewed_comparisons", "user_approved"]
.contains(&attributes.review_state_reason.as_str())
} else if [
ReviewStateReason::UnreviewedComparisons,
ReviewStateReason::UserApproved,
]
.contains(&attributes.review_state_reason)
{
let head_screenshot_id = comparison_relationship
.head_screenshot
Expand Down Expand Up @@ -160,7 +163,7 @@ fn snapshots_to_images(snapshots: SnapshotsData, build_url: &str) -> Vec<Screens
let snapshot_url = format!(
"{}/{}/{}",
build_url,
if attributes.review_state_reason == "no_diffs" {
if attributes.review_state_reason == ReviewStateReason::NoDiffs {
"unchanged"
} else {
"changed"
Expand All @@ -171,7 +174,7 @@ fn snapshots_to_images(snapshots: SnapshotsData, build_url: &str) -> Vec<Screens
images.push(ScreenshotData {
example: attributes.name.clone(),
screenshot: image.url.clone(),
changed: attributes.review_state_reason.clone(),
changed: (&attributes.review_state_reason).into(),
diff_ratio: comparison_attributes.diff_ratio.unwrap_or(9999.99),
tag,
snapshot_url: snapshot_url.to_owned(),
Expand Down Expand Up @@ -244,8 +247,17 @@ struct RelationshipData {
#[serde(rename_all = "kebab-case")]
struct SnapshotAttributes {
name: String,
review_state_reason: String,
review_state_reason: ReviewStateReason,
}

#[derive(Debug, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ReviewStateReason {
NoDiffs,
UnreviewedComparisons,
UserApproved,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "kebab-case")]
struct SnapshotRelationship {
Expand Down Expand Up @@ -312,16 +324,31 @@ mod tests {
dbg!(read.included.len());
dbg!(&read.data[0]);
dbg!(snapshots_to_images(read, ""));
assert!(false);
// assert!(false);
}
}

#[derive(Debug)]
pub struct ScreenshotData {
pub example: String,
pub screenshot: String,
pub changed: String,
pub changed: ScreenshotState,
pub tag: Option<String>,
pub diff_ratio: f32,
pub snapshot_url: String,
}

impl From<&ReviewStateReason> for ScreenshotState {
fn from(reason: &ReviewStateReason) -> Self {
match reason {
ReviewStateReason::NoDiffs => ScreenshotState::Similar,
_ => ScreenshotState::Changed,
}
}
}

#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Copy, Serialize)]
pub enum ScreenshotState {
Similar,
Changed,
}
17 changes: 4 additions & 13 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,7 @@
color: var(--bs-success-text-emphasis);
}

.changed-approved::before {
content: '\f005';
font: var(--fa-font-regular);
color: var(--bs-info-text-emphasis);
}

.changed-new::before {
.changed::before {
content: '\f005';
font: var(--fa-font-solid);
color: var(--bs-warning-text-emphasis);
Expand Down Expand Up @@ -244,20 +238,17 @@
<tr>
<th class="no-border" style="min-width: 35em;">
<div style="padding: 3px;">
<span class="success"></span> Example ran successfully, screenshot available
</div>
<div style="padding: 3px;">
<span class="fail"></span> Error running the example
<span class="success"></span> Example ran successfully, screenshot didn't change
</div>
<div style="padding: 3px;">
<span class="missing-screenshot"></span> Example ran successfully, but couldn't capture a
screenshot
</div>
<div style="padding: 3px;">
<span class="changed-approved"></span> Screenshot changed and has been approved
<span class="changed"></span> Example ran successfully, screenshot changed
</div>
<div style="padding: 3px;">
<span class="changed-new"></span> Screenshot changed and has not been approved yet
<span class="fail"></span> Error running the example
</div>
<br />
<div class="form-check form-switch form-check-reverse">
Expand Down
7 changes: 3 additions & 4 deletions templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
<div data-bs-toggle="popover" data-bs-trigger="hover" data-bs-html=true data-bs-custom-class="image-popover"
data-bs-content='<img class="img-fluid" src="{{ run.screenshots[example_name][platform].0 }}" />'>
<a href="{{ run.screenshots[example_name][platform].2 }}" target="_blank">
{% if run.screenshots[example_name][platform].1 == "Similar" -%}
<span class="success"></span>
{% if run.screenshots[example_name][platform].1 == "user_approved" -%}
<span class="changed-approved"></span>
{% elif run.screenshots[example_name][platform].1 == "unreviewed_comparisons" -%}
<span class="changed-new"></span>
{% else -%}
<span class="changed"></span>
{% endif -%}
</a>
</div>
Expand Down

0 comments on commit 6874620

Please sign in to comment.