Commit ff297aee authored by Robert Hunt's avatar Robert Hunt Committed by Andrew Fontaine

Pass the table QA selector down the stack

At the minute we have a QA selector being defined but it is never used.
This has been changed so we can customise the QA selector properly
parent 33a63ea4
...@@ -30,6 +30,16 @@ export default { ...@@ -30,6 +30,16 @@ export default {
type: Array, type: Array,
required: true, required: true,
}, },
filterQaSelector: {
type: String,
required: false,
default: undefined,
},
tableQaSelector: {
type: String,
required: false,
default: undefined,
},
}, },
data() { data() {
return { return {
...@@ -55,7 +65,7 @@ export default { ...@@ -55,7 +65,7 @@ export default {
class="filter-form d-flex justify-content-between audit-controls row" class="filter-form d-flex justify-content-between audit-controls row"
> >
<div class="col-lg-auto flex-fill form-group align-items-lg-center pr-lg-8"> <div class="col-lg-auto flex-fill form-group align-items-lg-center pr-lg-8">
<audit-events-filter v-bind="{ enabledTokenTypes }" /> <audit-events-filter v-bind="{ enabledTokenTypes, qaSelector: filterQaSelector }" />
</div> </div>
<div class="d-flex col-lg-auto flex-wrap pl-lg-0"> <div class="d-flex col-lg-auto flex-wrap pl-lg-0">
<div <div
...@@ -67,6 +77,6 @@ export default { ...@@ -67,6 +77,6 @@ export default {
</div> </div>
</form> </form>
</div> </div>
<audit-events-table v-bind="{ events, isLastPage }" /> <audit-events-table v-bind="{ events, isLastPage, qaSelector: tableQaSelector }" />
</div> </div>
</template> </template>
...@@ -15,6 +15,11 @@ export default { ...@@ -15,6 +15,11 @@ export default {
default: () => AVAILABLE_TOKEN_TYPES, default: () => AVAILABLE_TOKEN_TYPES,
validator: availableTokensValidator, validator: availableTokensValidator,
}, },
qaSelector: {
type: String,
required: false,
default: undefined,
},
}, },
data() { data() {
return { return {
...@@ -70,7 +75,11 @@ export default { ...@@ -70,7 +75,11 @@ export default {
</script> </script>
<template> <template>
<div class="input-group bg-white flex-grow-1" data-qa-selector="admin_audit_log_filter"> <div
class="input-group bg-white flex-grow-1"
data-testid="audit-events-filter"
:data-qa-selector="qaSelector"
>
<gl-filtered-search <gl-filtered-search
v-model="searchTerms" v-model="searchTerms"
:placeholder="__('Search')" :placeholder="__('Search')"
......
...@@ -23,6 +23,11 @@ export default { ...@@ -23,6 +23,11 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
qaSelector: {
type: String,
required: false,
default: undefined,
},
}, },
data() { data() {
return { return {
...@@ -81,7 +86,7 @@ export default { ...@@ -81,7 +86,7 @@ export default {
</script> </script>
<template> <template>
<div class="audit-log-table" data-qa-selector="admin_audit_log_table"> <div class="audit-log-table" data-testid="audit-events-table" :data-qa-selector="qaSelector">
<gl-table class="mt-3" :fields="$options.fields" :items="events" show-empty> <gl-table class="mt-3" :fields="$options.fields" :items="events" show-empty>
<template #cell(author)="{ value: { url, name } }"> <template #cell(author)="{ value: { url, name } }">
<url-table-cell :url="url" :name="name" /> <url-table-cell :url="url" :name="name" />
......
...@@ -4,7 +4,14 @@ import AuditEventsApp from './components/audit_events_app.vue'; ...@@ -4,7 +4,14 @@ import AuditEventsApp from './components/audit_events_app.vue';
export default selector => { export default selector => {
const el = document.querySelector(selector); const el = document.querySelector(selector);
const { events, isLastPage, formPath, enabledTokenTypes } = el.dataset; const {
events,
isLastPage,
formPath,
enabledTokenTypes,
filterQaSelector,
tableQaSelector,
} = el.dataset;
return new Vue({ return new Vue({
el, el,
...@@ -15,6 +22,8 @@ export default selector => { ...@@ -15,6 +22,8 @@ export default selector => {
isLastPage: parseBoolean(isLastPage), isLastPage: parseBoolean(isLastPage),
enabledTokenTypes: JSON.parse(enabledTokenTypes), enabledTokenTypes: JSON.parse(enabledTokenTypes),
formPath, formPath,
filterQaSelector,
tableQaSelector,
}, },
}), }),
}); });
......
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
#js-audit-log-app{ data: { form_path: admin_audit_logs_path, #js-audit-log-app{ data: { form_path: admin_audit_logs_path,
events: @table_events.to_json, events: @table_events.to_json,
is_last_page: @events.last_page?.to_json, is_last_page: @events.last_page?.to_json,
qa_selector: 'admin_audit_log_table', filter_qa_selector: 'admin_audit_log_filter',
table_qa_selector: 'admin_audit_log_table',
enabled_token_types: admin_audit_log_token_types } } enabled_token_types: admin_audit_log_token_types } }
...@@ -110,7 +110,7 @@ describe 'Admin::AuditLogs', :js do ...@@ -110,7 +110,7 @@ describe 'Admin::AuditLogs', :js do
it 'shows only 2 days old events' do it 'shows only 2 days old events' do
visit admin_audit_logs_path(created_after: 4.days.ago.to_date, created_before: 2.days.ago.to_date) visit admin_audit_logs_path(created_after: 4.days.ago.to_date, created_before: 2.days.ago.to_date)
find('.audit-log-table td', match: :first) find('[data-testid="audit-events-table"] td', match: :first)
expect(page).not_to have_content(audit_event_1.present.date) expect(page).not_to have_content(audit_event_1.present.date)
expect(page).to have_content(audit_event_2.present.date) expect(page).to have_content(audit_event_2.present.date)
...@@ -120,7 +120,7 @@ describe 'Admin::AuditLogs', :js do ...@@ -120,7 +120,7 @@ describe 'Admin::AuditLogs', :js do
it 'shows only yesterday events' do it 'shows only yesterday events' do
visit admin_audit_logs_path(created_after: 2.days.ago.to_date) visit admin_audit_logs_path(created_after: 2.days.ago.to_date)
find('.audit-log-table td', match: :first) find('[data-testid="audit-events-table"] td', match: :first)
expect(page).not_to have_content(audit_event_1.present.date) expect(page).not_to have_content(audit_event_1.present.date)
expect(page).not_to have_content(audit_event_2.present.date) expect(page).not_to have_content(audit_event_2.present.date)
......
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`AuditEventsApp when initialized matches the snapshot 1`] = ` exports[`AuditEventsApp when initialized matches the snapshot 1`] = `
<div <div>
dataqaselector="qa_selector"
>
<div <div
class="row-content-block second-block pb-0" class="row-content-block second-block pb-0"
> >
...@@ -17,7 +15,8 @@ exports[`AuditEventsApp when initialized matches the snapshot 1`] = ` ...@@ -17,7 +15,8 @@ exports[`AuditEventsApp when initialized matches the snapshot 1`] = `
> >
<div <div
class="input-group bg-white flex-grow-1" class="input-group bg-white flex-grow-1"
data-qa-selector="admin_audit_log_filter" data-qa-selector="filter_qa_selector"
data-testid="audit-events-filter"
> >
<gl-filtered-search-stub <gl-filtered-search-stub
availabletokens="[object Object],[object Object],[object Object]" availabletokens="[object Object],[object Object],[object Object]"
...@@ -59,6 +58,7 @@ exports[`AuditEventsApp when initialized matches the snapshot 1`] = ` ...@@ -59,6 +58,7 @@ exports[`AuditEventsApp when initialized matches the snapshot 1`] = `
<audit-events-table-stub <audit-events-table-stub
events="[object Object]" events="[object Object]"
islastpage="true" islastpage="true"
qaselector="table_qa_selector"
/> />
</div> </div>
`; `;
...@@ -11,13 +11,16 @@ describe('AuditEventsApp', () => { ...@@ -11,13 +11,16 @@ describe('AuditEventsApp', () => {
const events = [{ foo: 'bar' }]; const events = [{ foo: 'bar' }];
const enabledTokenTypes = AVAILABLE_TOKEN_TYPES; const enabledTokenTypes = AVAILABLE_TOKEN_TYPES;
const filterQaSelector = 'filter_qa_selector';
const tableQaSelector = 'table_qa_selector';
const initComponent = (props = {}) => { const initComponent = (props = {}) => {
wrapper = shallowMount(AuditEventsApp, { wrapper = shallowMount(AuditEventsApp, {
propsData: { propsData: {
formPath: 'form/path', formPath: 'form/path',
isLastPage: true, isLastPage: true,
dataQaSelector: 'qa_selector', filterQaSelector,
tableQaSelector,
enabledTokenTypes, enabledTokenTypes,
events, events,
...props, ...props,
...@@ -51,8 +54,16 @@ describe('AuditEventsApp', () => { ...@@ -51,8 +54,16 @@ describe('AuditEventsApp', () => {
expect(wrapper.find(AuditEventsTable).props('events')).toEqual(events); expect(wrapper.find(AuditEventsTable).props('events')).toEqual(events);
}); });
it('passes its avilable token types to the logs filter', () => { it('passes the tables QA selector to the logs table', () => {
expect(wrapper.find(AuditEventsTable).props('qaSelector')).toEqual(tableQaSelector);
});
it('passes its available token types to the logs filter', () => {
expect(wrapper.find(AuditEventsFilter).props('enabledTokenTypes')).toEqual(enabledTokenTypes); expect(wrapper.find(AuditEventsFilter).props('enabledTokenTypes')).toEqual(enabledTokenTypes);
}); });
it('passes the filters QA selector to the logs filter', () => {
expect(wrapper.find(AuditEventsFilter).props('qaSelector')).toEqual(filterQaSelector);
});
}); });
}); });
...@@ -131,4 +131,27 @@ describe('AuditEventsFilter', () => { ...@@ -131,4 +131,27 @@ describe('AuditEventsFilter', () => {
expect(getAvailableTokens()).toMatchObject([{ type }]); expect(getAvailableTokens()).toMatchObject([{ type }]);
}); });
}); });
describe('when setting the QA selector', () => {
beforeEach(() => {
initComponent();
});
it('should not set the QA selector if not provided', () => {
wrapper.vm.$nextTick(() => {
expect(
wrapper.find('[data-testid="audit-events-filter"]').attributes('data-qa-selector'),
).toBeUndefined();
});
});
it('should set the QA selector if provided', () => {
wrapper.setProps({ qaSelector: 'qa_selector' });
wrapper.vm.$nextTick(() => {
expect(
wrapper.find('[data-testid="audit-events-filter"]').attributes('data-qa-selector'),
).toEqual('qa_selector');
});
});
});
}); });
...@@ -51,6 +51,23 @@ describe('AuditEventsTable component', () => { ...@@ -51,6 +51,23 @@ describe('AuditEventsTable component', () => {
expect(getCell(0, 0).text()).toBe('There are no records to show'); expect(getCell(0, 0).text()).toBe('There are no records to show');
}); });
}); });
it('should not set the QA selector if not provided', () => {
wrapper.vm.$nextTick(() => {
expect(
wrapper.find('[data-testid="audit-events-table"]').attributes('data-qa-selector'),
).toBeUndefined();
});
});
it('should set the QA selector if provided', () => {
wrapper.setProps({ qaSelector: 'qa_selector' });
wrapper.vm.$nextTick(() => {
expect(
wrapper.find('[data-testid="audit-events-table"]').attributes('data-qa-selector'),
).toEqual('qa_selector');
});
});
}); });
describe('Pagination behaviour', () => { describe('Pagination behaviour', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment