Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/QueryOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ div
option(v-for="hostname in hostnameChoices")
| {{hostname}}
b-form-group(label="Start" label-cols=2)
b-form-datepicker(v-model="queryOptionsData.start")
input.form-control(type="date" v-model="queryOptionsData.start")
b-form-group(label="Stop" label-cols=2)
b-form-datepicker(v-model="queryOptionsData.stop")
input.form-control(type="date" v-model="queryOptionsData.stop")
Comment on lines +8 to +10

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Moment values blank date inputs

When Search or Category Builder opens, their Moment-valued defaults are copied directly into these native date inputs instead of being normalized to YYYY-MM-DD, causing the Start and Stop controls to render blank rather than showing the active query range.

Knowledge Base Used:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in b31bca3. mounted() now formats start/stop to YYYY-MM-DD before the native date inputs bind, so Moment-valued defaults from Search and Category Builder show the active range instead of blank controls.

b-form-group(label="Toggles" label-cols=2)
b-form-checkbox(type="checkbox" v-model="queryOptionsData.filter_afk" label="Filter AFK" description="")
label Exclude time away from computer
Expand Down
4 changes: 3 additions & 1 deletion src/views/Graph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ export default {
return { nodes, links };
},
extendByWeek() {
this.queryOptions.start = moment(this.queryOptions.start).subtract(1, 'week');
this.queryOptions.start = moment(this.queryOptions.start)
.subtract(1, 'week')
.format('YYYY-MM-DD');
this.generate();
},
},
Expand Down
4 changes: 3 additions & 1 deletion src/views/Report.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ export default {
},

extendByWeek() {
this.queryOptions.start = moment(this.queryOptions.start).subtract(1, 'week');
this.queryOptions.start = moment(this.queryOptions.start)
.subtract(1, 'week')
.format('YYYY-MM-DD');
this.generate();
},
},
Expand Down
8 changes: 5 additions & 3 deletions src/views/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export default {
// Options
show_options: false,
queryOptions: {
start: moment().subtract(1, 'day'),
stop: moment().add(1, 'day'),
start: moment().subtract(1, 'day').format('YYYY-MM-DD'),
stop: moment().add(1, 'day').format('YYYY-MM-DD'),
},
};
},
Expand Down Expand Up @@ -97,7 +97,9 @@ export default {
}
},
extendByWeek() {
this.queryOptions.start = moment(this.queryOptions.start).subtract(1, 'week');
this.queryOptions.start = moment(this.queryOptions.start)
.subtract(1, 'week')
.format('YYYY-MM-DD');
this.search();
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/views/settings/CategoryBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ export default {
show_options: false,
queryOptions: {
hostname: '',
start: moment().subtract(1, 'day'),
stop: moment().add(1, 'day'),
start: moment().subtract(1, 'day').format('YYYY-MM-DD'),
stop: moment().add(1, 'day').format('YYYY-MM-DD'),
},

// TODO: Support inspecting a different category than Uncategorized (e.g. to make some category more precise)
Expand Down
64 changes: 64 additions & 0 deletions test/unit/QueryOptions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import moment from 'moment';
import { createPinia, setActivePinia } from 'pinia';
import { shallowMount } from '@vue/test-utils';
import QueryOptions from '~/components/QueryOptions.vue';
import Search from '~/views/Search.vue';

const mockEnsureLoaded = jest.fn().mockResolvedValue(undefined);

jest.mock('~/stores/buckets', () => ({
useBucketsStore: () => ({
ensureLoaded: mockEnsureLoaded,
hosts: ['laptop'],
}),
}));

describe('QueryOptions', () => {
beforeEach(() => {
setActivePinia(createPinia());
mockEnsureLoaded.mockClear();
});

test('renders date range values in native date inputs', async () => {
const wrapper = shallowMount(QueryOptions, {
propsData: {
queryOptions: {
start: '2026-08-15',
stop: '2026-08-16',
},
},
stubs: {
'b-form-group': { template: '<div><slot /></div>' },
'b-form-select': true,
'b-form-checkbox': true,
},
});

await wrapper.vm.$nextTick();
await wrapper.vm.$nextTick();

const dateInputs = wrapper.findAll('input[type="date"]');
expect(dateInputs).toHaveLength(2);
expect(dateInputs.at(0).element.value).toBe('2026-08-15');
expect(dateInputs.at(1).element.value).toBe('2026-08-16');
});

test.each([Search])('initializes date ranges as YYYY-MM-DD strings', view => {
const data = view.data();

expect(data.queryOptions.start).toMatch(/^\d{4}-\d{2}-\d{2}$/);
expect(data.queryOptions.stop).toMatch(/^\d{4}-\d{2}-\d{2}$/);
});

test.each([Search])('keeps extended ranges compatible with date inputs', view => {
const vm = {
queryOptions: { start: moment('2026-08-15') },
search: jest.fn(),
generate: jest.fn(),
};

view.methods.extendByWeek.call(vm);

expect(vm.queryOptions.start).toBe('2026-08-08');
});
});
Loading