Skip to content

Commit

Permalink
test: added first query-generation test using jest's snapshot functio…
Browse files Browse the repository at this point in the history
…nality
  • Loading branch information
ErikBjare committed Mar 17, 2022
1 parent 9d6b4b1 commit 3db99c7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import _ from 'lodash';
function querystr_to_array(querystr: string): string[] {
return querystr
.split(';')
.filter(l => l)
.map(l => l + ';');
.map(s => s.trim())
.filter(s => s)
.map(s => s + ';');
}

function escape_doublequote(s: string) {
Expand Down
41 changes: 41 additions & 0 deletions test/unit/__snapshots__/queries.test.node.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generate fullDesktopQuery 1`] = `
"events = flood(query_bucket(\\"\\"));
not_afk = flood(query_bucket(\\"\\"));
not_afk = filter_keyvals(not_afk, \\"status\\", [\\"not-afk\\"]);
browser_events = [];
audible_events = filter_keyvals(browser_events, \\"audible\\", [true]);
not_afk = period_union(not_afk, audible_events);
events = filter_period_intersect(events, not_afk);
events = categorize(events, []);
events = filter_keyvals(events, \\"$category\\", true);
title_events = sort_by_duration(merge_events_by_keys(events, [\\"app\\", \\"title\\"]));
app_events = sort_by_duration(merge_events_by_keys(title_events, [\\"app\\"]));
cat_events = sort_by_duration(merge_events_by_keys(events, [\\"$category\\"]));
app_events = limit_events(app_events, 100);
title_events = limit_events(title_events, 100);
duration = sum_durations(events);
browser_events = split_url_events(browser_events);
browser_urls = merge_events_by_keys(browser_events, [\\"url\\"]);
browser_urls = sort_by_duration(browser_urls);
browser_urls = limit_events(browser_urls, 100);
browser_domains = merge_events_by_keys(browser_events, [\\"$domain\\"]);
browser_domains = sort_by_duration(browser_domains);
browser_domains = limit_events(browser_domains, 100);
browser_duration = sum_durations(browser_events);
RETURN = {
\\"window\\": {
\\"app_events\\": app_events,
\\"title_events\\": title_events,
\\"cat_events\\": cat_events,
\\"active_events\\": not_afk,
\\"duration\\": duration
},
\\"browser\\": {
\\"domains\\": browser_domains,
\\"urls\\": browser_urls,
\\"duration\\": browser_duration
}
};"
`;
26 changes: 26 additions & 0 deletions test/unit/queries.test.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const queries = require('~/queries');

test('generate fullDesktopQuery', () => {
const browserbuckets = [];
const windowbucket = '';
const afkbucket = '';
const filterAFK = true;
const classes = [];
const filterCategories = true;
const include_audible = true;
const query_lines = queries.fullDesktopQuery(
browserbuckets,
windowbucket,
afkbucket,
filterAFK,
classes,
filterCategories,
include_audible
);

// join query lines into a single string
const query = query_lines.join('\n');

// check that query_str is well formatted
expect(query).toMatchSnapshot();
});

1 comment on commit 3db99c7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are screenshots of this commit:

Screenshots using aw-server v0.11.0 (click to expand)

Screenshots using aw-server-rust master (click to expand)

Screenshots using aw-server-rust v0.11.0 (click to expand)

CML watermark

Please sign in to comment.