Skip to content

Commit

Permalink
Update "removed" definition
Browse files Browse the repository at this point in the history
We'll say that an item is only removed if it (1) has an "in_source"
annotation and it is false. This annotation should always be present
for metrics, but is not currently set for any other object.
  • Loading branch information
wlach committed Sep 13, 2021
1 parent 12068e5 commit 9185a12
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/components/ItemList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import Label from "./Label.svelte";
import { filterUncollectedItems } from "../state/filter";
import { isExpired } from "../state/metrics";
import { isExpired, isRemoved } from "../state/items";
import { pageState, updateURLState } from "../state/stores";
let DEFAULT_ITEMS_PER_PAGE = 20;
Expand Down Expand Up @@ -189,7 +189,7 @@
/>
{/each}
{/if}
{#if !item.in_source}
{#if isRemoved(item)}
<Label text="removed" />
{:else if isExpired(item.expires)}
<Label text="expired" />
Expand Down
2 changes: 1 addition & 1 deletion src/pages/MetricDetail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { pageTitle, pageState, updateURLState } from "../state/stores";
import { getBigQueryURL } from "../state/urls";
import { isExpired } from "../state/metrics";
import { isExpired } from "../state/items";
export let params;
Expand Down
2 changes: 1 addition & 1 deletion src/state/filter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isExpired } from "./metrics";
import { isExpired } from "./items";

export const filterUncollectedItems = (items, showUncollected) =>
items.filter(
Expand Down
6 changes: 6 additions & 0 deletions src/state/metrics.js → src/state/items.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export const isRemoved = (item) => {
// only consider an item expired if it has an in_source property
// and it is false
return item.in_source === false;
};

export const isExpired = (expiryDate) => {
if (expiryDate === "never" || expiryDate === undefined) {
return false;
Expand Down
25 changes: 25 additions & 0 deletions tests/state.items.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { isExpired, isRemoved } from "../src/state/items";

describe("checking if a date has expired", () => {
it("returns True if input is 'never' or undefined", () => {
expect(isExpired("never") || isExpired(undefined)).toEqual(false);
});
it("returns True if input is a date from the past", () => {
expect(isExpired("2021-01-01")).toEqual(true);
});
it("returns False if input is a date from the future", () => {
expect(isExpired("3021-01-01")).toEqual(false);
});
});

describe("isRemoved works as expected", () => {
it("returns true if in_source is false", () => {
expect(isRemoved({ in_source: false })).toEqual(true);
});
it("returns false if in_source is undefined", () => {
expect(isRemoved({})).toEqual(false);
});
it("returns false if in_source is true", () => {
expect(isRemoved({ in_source: true })).toEqual(false);
});
});
13 changes: 0 additions & 13 deletions tests/state.metrics.test.js

This file was deleted.

0 comments on commit 9185a12

Please sign in to comment.