Adds manual, editable, auto-suggested filters, and negated&globbed path-based filters (#1121)
* Adds manual-filters + friends commit 308192044d726e9a6f7406e333048ab3407aa260 Merge:pull/1169/head39287aba299fabAuthor: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri Jun 11 03:40:55 2021 -0500 Merge branch 'manual-filters' into manual-filters-2 commita299fab1fbAuthor: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri Jun 11 02:20:26 2021 -0500 Changes to split and pattern matched function for time_on_page commit10f10c933aAuthor: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri Jun 11 01:53:18 2021 -0500 Fixes a couple of minor UX issues commitf2e5ce8eb3Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri Jun 11 01:49:10 2021 -0500 Fixes time on page for globbed and negated page paths commitbb18af6526Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu Jun 10 05:24:05 2021 -0500 Close to finalized version of updated version Just needs some additional testing + potentially code cleanup commitd0b7bfe3daAuthor: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 28 04:21:21 2021 -0500 Real Dialyzer Fix commit296a76af34Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 28 03:44:29 2021 -0500 Dialyzer fix commit91f3b44017Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 17:11:24 2021 -0500 Changelog commite041f75745Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 17:09:52 2021 -0500 Formatting commitf689642204Merge:e00929b4ff25f6Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 17:08:47 2021 -0500 Merge branch 'master' into manual-filters commite00929b1c5Merge:83887c4806975eAuthor: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 17:01:48 2021 -0500 Merge branch 'manual-filters' of github.com:Vigasaurus/plausible-analytics into manual-filters commit83887c49ccAuthor: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 16:59:32 2021 -0500 Adds tests for suggestions, formats goals suggestion query commit1cb7732a08Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 16:36:31 2021 -0500 Adds goals as auto-complete capable filter commit4ca39cc406Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 16:08:22 2021 -0500 95% completed auto-complete setup Still needs: - tests - goals added as filter commit22d38c4cd8Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 03:47:19 2021 -0500 80% of auto-complete filters progress Still needs - countries and screen into new format - re-style dropdown and background - drop debounce time - tests commit806975ede9Merge:81c5e051a93542Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Tue May 25 15:28:21 2021 -0500 Merge branch 'master' into manual-filters commit81c5e05760Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Tue May 25 15:21:03 2021 -0500 Makes colorings on top bar elements consistent commitfa7f6c2268Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Tue May 25 14:58:25 2021 -0500 Makes requested changes, adds different version of filter button commit7dc65b9b7aAuthor: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Sat May 22 04:29:01 2021 -0500 Changelog commitc684f1c76aAuthor: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Sat May 22 04:26:14 2021 -0500 Various UI Improvements - Makes edit buttons full-length & properly sized - Adds remove filter button in edit menu commita632e7a8eeAuthor: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Sat May 22 03:11:50 2021 -0500 Adds tests for exclusions and wildcards commiteb91a7942bAuthor: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Sat May 22 03:02:23 2021 -0500 Fixes editing UX on list view commit6209d72aeeAuthor: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 21 04:01:17 2021 -0500 Bugfix in realtime view, formatting commit007d44df38Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 21 03:23:16 2021 -0500 Second pass - mostly everything user-facing is done Still needs: - Tests - Potentially negating other filters - Potentially some code cleanup commitcb7b5b9fbdAuthor: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 21 01:49:52 2021 -0500 First pass on manual filter & path regex/negated filters Still needs: - Form structure on filter modal - Edit filter button - Filter dropdown UI improvement - Filter modal mount data collection - Tests - Potentially negating other filters * Fixes an issue between the updated React version and Flatpickr not showing up Reverting to v16 was the simplest fix without diving into the issue upstream with Flatpickr * Resolves comments on UI and code style Co-authored-by: Uku Taht <Uku.taht@gmail.com>
parent
883841f789
commit
30ac901141
@ -0,0 +1,97 @@
|
||||
.filter-list-text:hover ~ .filter-list-edit {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.filter-list-text:hover ~ .filter-list-remove {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.filter-select__control:focus-within {
|
||||
box-shadow: rgb(255, 255, 255) 0px 0px 0px 0px, rgb(99, 102, 241) 0px 0px 0px 1px, rgba(0, 0, 0, 0) 0px 0px 0px 0px; /* indigo-500 */
|
||||
}
|
||||
|
||||
.filter-select__value-container {
|
||||
padding-left: 1rem !important;
|
||||
}
|
||||
|
||||
.filter-select__control {
|
||||
@apply dark:bg-gray-900 border-gray-300 dark:border-gray-700 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 pr-8;
|
||||
border-radius: 0.375rem !important;
|
||||
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
|
||||
background-position: right 0.5rem center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 1.35rem 1.35rem;
|
||||
}
|
||||
|
||||
.filter-select__control:hover {
|
||||
@apply cursor-pointer;
|
||||
border-color: rgb(156, 163, 175) !important; /* gray-400 */
|
||||
}
|
||||
|
||||
.filter-select__indicator-separator {
|
||||
@apply hidden;
|
||||
}
|
||||
|
||||
.filter-select__dropdown-indicator {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.filter-select__input {
|
||||
@apply w-full text-base sm:text-sm;
|
||||
margin: 0 !important;
|
||||
}
|
||||
|
||||
.filter-select__input input {
|
||||
width: 100% !important;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.dark .filter-select__input input {
|
||||
color: rgb(209, 213, 219) !important; /* gray-300 */
|
||||
}
|
||||
|
||||
.filter-select__value-container > :not(.filter-select__single-value) {
|
||||
@apply w-full;
|
||||
padding-top: 0 !important;
|
||||
}
|
||||
|
||||
.filter-select__loading-indicator {
|
||||
color: rgb(79, 70, 229) !important; /* indigo-600 */
|
||||
}
|
||||
|
||||
.filter-select__loading-indicator > span {
|
||||
height: 1.5em;
|
||||
width: 1.5em;
|
||||
}
|
||||
|
||||
.filter-select__single-value {
|
||||
@apply dark:text-gray-400 text-base sm:text-sm;
|
||||
}
|
||||
|
||||
.filter-select__menu-list {
|
||||
@apply dark:bg-gray-900;
|
||||
}
|
||||
|
||||
.filter-select__option {
|
||||
@apply dark:text-gray-300;
|
||||
font-size: 1rem !important;
|
||||
line-height: 1.5rem !important;
|
||||
cursor: pointer !important;
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
.filter-select__option {
|
||||
font-size: 0.875rem !important;
|
||||
line-height: 1.25rem !important;
|
||||
}
|
||||
}
|
||||
|
||||
.filter-select__option--is-focused {
|
||||
background-color: rgb(99, 102, 241) !important; /* indigo-500 */
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.dark .filter-select__option--is-focused {
|
||||
background-color: rgb(79, 70, 229) !important; /* indigo-600 */
|
||||
}
|
||||
|
||||
@ -0,0 +1,234 @@
|
||||
import React from "react";
|
||||
import { withRouter, Redirect } from 'react-router-dom'
|
||||
|
||||
import Datamap from 'datamaps'
|
||||
import AsyncSelect from 'react-select/async'
|
||||
import debounce from 'lodash.debounce'
|
||||
import Modal from './modal'
|
||||
import { parseQuery, formattedFilters, navigateToQuery } from '../../query'
|
||||
import Transition from "../../../transition";
|
||||
import * as api from '../../api'
|
||||
|
||||
class FilterModal extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
query: parseQuery(props.location.search, props.site),
|
||||
selectedFilter: "",
|
||||
negated: false,
|
||||
updatedValue: "",
|
||||
inputValue: "",
|
||||
forceReloadSuggestions: 0,
|
||||
defaultOptions: []
|
||||
}
|
||||
|
||||
this.editableGoals = Object.keys(this.state.query.filters).filter(filter => !['props'].includes(filter))
|
||||
this.renderSelector = this.renderSelector.bind(this)
|
||||
this.fetchSuggestions = this.fetchSuggestions.bind(this)
|
||||
this.handleKeydown = this.handleKeydown.bind(this)
|
||||
this.handleSubmit = this.handleSubmit.bind(this)
|
||||
this.fieldSelectRef = React.createRef()
|
||||
this.debouncedFetchSuggestions = debounce((q, callback) => this.fetchSuggestions(q, callback), 150)
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.setState({ selectedFilter: this.props.match.params.field })
|
||||
this.fieldSelectRef.current.focus()
|
||||
document.addEventListener("keydown", this.handleKeydown)
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
const { query, selectedFilter, updatedValue, forceReloadSuggestions } = this.state
|
||||
|
||||
if (prevState.selectedFilter !== selectedFilter) {
|
||||
const negated = !!query.filters[selectedFilter] && query.filters[selectedFilter][0] == '!' && this.negationSupported(selectedFilter)
|
||||
let updatedValue = negated ? query.filters[selectedFilter].slice(1) : (query.filters[selectedFilter] || "")
|
||||
|
||||
if (selectedFilter == 'country') {
|
||||
const allCountries = Datamap.prototype.worldTopo.objects.world.geometries;
|
||||
const selectedCountry = allCountries.find((c) => c.id === updatedValue) || { properties: { name: updatedValue } };
|
||||
updatedValue = selectedCountry.properties.name
|
||||
}
|
||||
|
||||
if (selectedFilter) this.fetchSuggestions('', (defaultOptions) => this.setState({ defaultOptions }))
|
||||
this.setState({ updatedValue, inputValue: updatedValue, negated, forceReloadSuggestions: forceReloadSuggestions + 1 })
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
document.removeEventListener("keydown", this.handleKeydown);
|
||||
}
|
||||
|
||||
handleKeydown(e) {
|
||||
if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || e.isComposing || e.keyCode === 229) return
|
||||
|
||||
if (e.target.tagName == 'BODY' && e.key == 'Enter') {
|
||||
this.handleSubmit()
|
||||
}
|
||||
}
|
||||
|
||||
negationSupported(filter) {
|
||||
return ['page', 'entry_page', 'exit_page'].includes(filter)
|
||||
}
|
||||
|
||||
fetchSuggestions(searchQuery = "", callback) {
|
||||
const { query, selectedFilter } = this.state
|
||||
const updatedQuery = { ...query, filters: { ...query.filters, [selectedFilter]: null } }
|
||||
|
||||
if (selectedFilter == 'country') {
|
||||
const matchedCountries = Datamap.prototype.worldTopo.objects.world.geometries.filter(c => c.properties.name.includes(searchQuery.trim()))
|
||||
const matches = matchedCountries.map(c => c.id)
|
||||
|
||||
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/suggestions/country`, updatedQuery, { q: matches })
|
||||
.then((res) => {
|
||||
const result = res.map(code => matchedCountries.filter(c => c.id == code)[0].properties.name).map(r => ({ label: r, value: r }))
|
||||
callback(result)
|
||||
})
|
||||
} else {
|
||||
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/suggestions/${selectedFilter}`, updatedQuery, { q: searchQuery.trim() })
|
||||
.then((res) => {
|
||||
const result = res.map(r => ({ label: r, value: r }))
|
||||
callback(result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
renderSelector(filter) {
|
||||
const { updatedValue, selectedFilter, inputValue, forceReloadSuggestions, defaultOptions } = this.state;
|
||||
|
||||
if (!filter) return null
|
||||
|
||||
return (
|
||||
<AsyncSelect
|
||||
key={`select-${selectedFilter}-${forceReloadSuggestions}`}
|
||||
defaultOptions={inputValue == "" ? defaultOptions : true}
|
||||
cacheOptions
|
||||
loadOptions={(q, callback) => this.debouncedFetchSuggestions(q, callback)}
|
||||
placeholder='Filter value'
|
||||
maxMenuHeight={250}
|
||||
tabSelectsValue={false}
|
||||
classNamePrefix='filter-select'
|
||||
blurInputOnSelect
|
||||
noOptionsMessage={() => (
|
||||
<span className="text-red-500 text-md flex mt-2 px-3">
|
||||
<svg className="w-10 h-10 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
|
||||
<span className="">No results found in current dashboard, try removing some filters, checking your input and ensuring this {formattedFilters[selectedFilter].toLowerCase()} exists</span>
|
||||
</span>
|
||||
)}
|
||||
loadingMessage={() => (
|
||||
<span>
|
||||
Loading filter suggestions
|
||||
</span>
|
||||
)}
|
||||
value={inputValue == '' ? { label: 'Enter a filter value', value: '' } : { label: updatedValue, value: `${updatedValue } ` }}
|
||||
onChange={({ value }, a) => {
|
||||
this.setState({ updatedValue: value, inputValue: value, forceReloadSuggestions: forceReloadSuggestions + 1 })
|
||||
}}
|
||||
onInputChange={(value, { action }) => {
|
||||
if (action == 'input-change') this.setState({ inputValue: value })
|
||||
if (action == 'menu-close' || action == 'input-blur') this.setState(({inputValue}) => ({ updatedValue: inputValue }))
|
||||
}}
|
||||
inputValue={inputValue}
|
||||
onBlur={() => this.setState({ forceReloadSuggestions: forceReloadSuggestions + 1 })}
|
||||
/>)
|
||||
}
|
||||
|
||||
handleSubmit() {
|
||||
const { selectedFilter, negated, updatedValue } = this.state;
|
||||
const validFilter = this.editableGoals.includes(selectedFilter) && updatedValue.trim()
|
||||
|
||||
let finalFilterValue = (this.negationSupported(selectedFilter) && negated ? '!' : '') + updatedValue.trim()
|
||||
if (selectedFilter == 'country') {
|
||||
const allCountries = Datamap.prototype.worldTopo.objects.world.geometries;
|
||||
const selectedCountry = allCountries.find((c) => c.properties.name === finalFilterValue) || { id: finalFilterValue };
|
||||
finalFilterValue = selectedCountry.id
|
||||
}
|
||||
const finalizedQuery = new URLSearchParams(window.location.search)
|
||||
finalizedQuery.set(selectedFilter, finalFilterValue)
|
||||
|
||||
if (validFilter) {
|
||||
this.setState({ finalizedQuery })
|
||||
}
|
||||
}
|
||||
|
||||
renderBody() {
|
||||
const { selectedFilter, negated, updatedValue, query } = this.state;
|
||||
const validFilter = this.editableGoals.includes(selectedFilter) && updatedValue.trim()
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="text-xl font-bold dark:text-gray-100">{query.filters[selectedFilter] ? 'Edit' : 'Add'} Filter</h1>
|
||||
|
||||
<div className="my-4 border-b border-gray-300"></div>
|
||||
<main className="modal__content">
|
||||
<form className="flex flex-col" id="filter-form" onSubmit={this.handleSubmit}>
|
||||
<select
|
||||
value={selectedFilter || ""}
|
||||
className="my-2 block w-full py-2 pl-3 pr-10 text-base border-gray-300 dark:border-gray-700 hover:border-gray-400 dark:hover:border-gray-200 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:bg-gray-900 dark:text-gray-300 cursor-pointer"
|
||||
placeholder="Select a Filter"
|
||||
onChange={(e) => this.setState({ selectedFilter: e.target.value })}
|
||||
ref={this.fieldSelectRef}
|
||||
>
|
||||
<option disabled value="" className="hidden">Select a Filter</option>
|
||||
{this.editableGoals.map(filter => <option key={filter} value={filter}>{formattedFilters[filter]}</option>)}
|
||||
</select>
|
||||
|
||||
{this.negationSupported(selectedFilter) && (
|
||||
<div className="my-4 flex items-center">
|
||||
<label className="text-gray-700 dark:text-gray-300 text-sm cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="bg-gray-100 dark:bg-gray-900 text-indigo-600 border-gray-300 dark:border-gray-700 hover:border-gray-400 dark:hover:border-gray-200 mr-2 relative inline-flex flex-shrink-0 h-6 w-8 border-1 rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none"
|
||||
checked={negated}
|
||||
name="exclude"
|
||||
onChange={(e) => this.setState({ negated: e.target.checked })}
|
||||
/>
|
||||
Exclude pages matching this filter
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{this.renderSelector(selectedFilter)}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={!validFilter}
|
||||
className="button mt-4 w-2/3 mx-auto"
|
||||
>
|
||||
{query.filters[selectedFilter] ? 'Update' : 'Add'} Filter
|
||||
</button>
|
||||
|
||||
{query.filters[selectedFilter] && (
|
||||
<button
|
||||
className="button mt-8 px-4 mx-auto flex bg-red-500 dark:bg-red-500 hover:bg-red-600 dark:hover:bg-red-700 items-center"
|
||||
onClick={() => {
|
||||
const finalizedQuery = new URLSearchParams(window.location.search)
|
||||
finalizedQuery.delete(selectedFilter)
|
||||
this.setState({ finalizedQuery })
|
||||
}}
|
||||
>
|
||||
<svg className="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg>
|
||||
Remove Filter
|
||||
</button>
|
||||
)}
|
||||
</form>
|
||||
</main>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
render() {
|
||||
const { finalizedQuery } = this.state;
|
||||
|
||||
if (finalizedQuery)
|
||||
return <Redirect to={{ pathname: `/${encodeURIComponent(this.props.site.domain)}`, search: finalizedQuery.toString() }} />
|
||||
|
||||
return (
|
||||
<Modal site={this.props.site} maxWidth="460px">
|
||||
{ this.renderBody()}
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default withRouter(FilterModal)
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,133 @@
|
||||
defmodule PlausibleWeb.Api.StatsController.SuggestionsTest do
|
||||
use PlausibleWeb.ConnCase
|
||||
import Plausible.TestUtils
|
||||
|
||||
describe "GET /api/stats/:domain/suggestions/:filter_name" do
|
||||
setup [:create_user, :log_in, :create_site]
|
||||
|
||||
test "returns suggestions for pages without a query", %{conn: conn, site: site} do
|
||||
conn = get(conn, "/api/stats/#{site.domain}/suggestions/page?period=month&date=2019-01-01")
|
||||
|
||||
assert json_response(conn, 200) == ["/", "/register", "/contact", "/irrelevant"]
|
||||
end
|
||||
|
||||
test "returns suggestions for pages with a query", %{conn: conn, site: site} do
|
||||
conn =
|
||||
get(conn, "/api/stats/#{site.domain}/suggestions/page?period=month&date=2019-01-01&q=re")
|
||||
|
||||
assert json_response(conn, 200) == ["/register", "/irrelevant"]
|
||||
end
|
||||
|
||||
test "returns suggestions for pages without any suggestions", %{conn: conn, site: site} do
|
||||
conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/stats/#{site.domain}/suggestions/page?period=month&date=2019-01-01&q=/123"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == []
|
||||
end
|
||||
|
||||
test "returns suggestions for goals", %{conn: conn, site: site} do
|
||||
conn = get(conn, "/api/stats/#{site.domain}/suggestions/goal?period=month&date=2019-01-01")
|
||||
|
||||
assert json_response(conn, 200) == []
|
||||
end
|
||||
|
||||
test "returns suggestions for sources", %{conn: conn, site: site} do
|
||||
conn =
|
||||
get(conn, "/api/stats/#{site.domain}/suggestions/source?period=month&date=2019-01-01")
|
||||
|
||||
assert json_response(conn, 200) == ["10words", "Bing"]
|
||||
end
|
||||
|
||||
test "returns suggestions for countries", %{conn: conn, site: site} do
|
||||
conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/stats/#{site.domain}/suggestions/country?period=month&date=2019-01-01&q=GBR,UKR,URY,USA"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == ["USA"]
|
||||
end
|
||||
|
||||
test "returns suggestions for countries without country in search", %{conn: conn, site: site} do
|
||||
conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/stats/#{site.domain}/suggestions/country?period=month&date=2019-01-01&q=GBR,UKR,URY"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == []
|
||||
end
|
||||
|
||||
test "returns suggestions for screen sizes", %{conn: conn, site: site} do
|
||||
conn =
|
||||
get(conn, "/api/stats/#{site.domain}/suggestions/screen?period=month&date=2019-01-01")
|
||||
|
||||
assert json_response(conn, 200) == ["Desktop"]
|
||||
end
|
||||
|
||||
test "returns suggestions for browsers", %{conn: conn, site: site} do
|
||||
conn =
|
||||
get(conn, "/api/stats/#{site.domain}/suggestions/browser?period=month&date=2019-01-01")
|
||||
|
||||
assert json_response(conn, 200) == ["Chrome"]
|
||||
end
|
||||
|
||||
test "returns suggestions for browser versions", %{conn: conn, site: site} do
|
||||
filters = Jason.encode!(%{browser: "Chrome"})
|
||||
|
||||
conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/stats/#{site.domain}/suggestions/browser_version?period=month&date=2019-01-01&filters=#{
|
||||
filters
|
||||
}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == ["78.0"]
|
||||
end
|
||||
|
||||
test "returns suggestions for OS", %{conn: conn, site: site} do
|
||||
conn = get(conn, "/api/stats/#{site.domain}/suggestions/os?period=month&date=2019-01-01")
|
||||
|
||||
assert json_response(conn, 200) == ["Mac"]
|
||||
end
|
||||
|
||||
test "returns suggestions for OS versions", %{conn: conn, site: site} do
|
||||
filters = Jason.encode!(%{os: "Mac"})
|
||||
|
||||
conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/stats/#{site.domain}/suggestions/os_version?period=month&date=2019-01-01&filters=#{
|
||||
filters
|
||||
}"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == ["10.15"]
|
||||
end
|
||||
|
||||
test "returns suggestions for OS versions with search", %{conn: conn, site: site} do
|
||||
filters = Jason.encode!(%{os: "Mac"})
|
||||
|
||||
conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/stats/#{site.domain}/suggestions/os_version?period=month&date=2019-01-01&filters=#{
|
||||
filters
|
||||
}&q=11"
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == []
|
||||
end
|
||||
|
||||
test "returns suggestions for referrers", %{conn: conn, site: site} do
|
||||
conn =
|
||||
get(conn, "/api/stats/#{site.domain}/suggestions/referrer?period=month&date=2019-01-01")
|
||||
|
||||
assert json_response(conn, 200) == ["10words.com/page1"]
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue