commit
e0ef89c73f
@ -0,0 +1,59 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component, Fragment } from 'react';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
|
||||
export default class SectionHeadline extends Component {
|
||||
|
||||
static propTypes = {
|
||||
timelineId: PropTypes.string.isRequired,
|
||||
to: PropTypes.string.isRequired,
|
||||
pinned: PropTypes.bool.isRequired,
|
||||
onlyMedia: PropTypes.bool.isRequired,
|
||||
onClick: PropTypes.func,
|
||||
};
|
||||
|
||||
shouldComponentUpdate (nextProps) {
|
||||
return (
|
||||
this.props.onlyMedia !== nextProps.onlyMedia ||
|
||||
this.props.pinned !== nextProps.pinned ||
|
||||
this.props.to !== nextProps.to ||
|
||||
this.props.timelineId !== nextProps.timelineId
|
||||
);
|
||||
}
|
||||
|
||||
handleClick = e => {
|
||||
const { onClick } = this.props;
|
||||
|
||||
if (typeof onClick === 'function') {
|
||||
e.preventDefault();
|
||||
|
||||
onClick.call(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
const { timelineId, to, pinned, onlyMedia } = this.props;
|
||||
|
||||
return (
|
||||
<div className={`${timelineId}-timeline__section-headline`}>
|
||||
{pinned ? (
|
||||
<Fragment>
|
||||
<a href={to} className={!onlyMedia ? 'active' : undefined} onClick={this.handleClick}>
|
||||
<FormattedMessage id='timeline.posts' defaultMessage='Toots' />
|
||||
</a>
|
||||
<a href={`${to}/media`} className={onlyMedia ? 'active' : undefined} onClick={this.handleClick}>
|
||||
<FormattedMessage id='timeline.media' defaultMessage='Media' />
|
||||
</a>
|
||||
</Fragment>
|
||||
) : (
|
||||
<Fragment>
|
||||
<NavLink exact to={to} replace><FormattedMessage id='timeline.posts' defaultMessage='Toots' /></NavLink>
|
||||
<NavLink exact to={`${to}/media`} replace><FormattedMessage id='timeline.media' defaultMessage='Media' /></NavLink>
|
||||
</Fragment>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::ReportNotesController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, admin: true) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
subject { post :create, params: params }
|
||||
|
||||
let(:report) { Fabricate(:report, action_taken: action_taken, action_taken_by_account_id: account_id) }
|
||||
|
||||
context 'when parameter is valid' do
|
||||
|
||||
context 'when report is unsolved' do
|
||||
let(:action_taken) { false }
|
||||
let(:account_id) { nil }
|
||||
|
||||
context 'when create_and_resolve flag is on' do
|
||||
let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_resolve: nil } }
|
||||
|
||||
it 'creates a report note and resolves report' do
|
||||
expect{ subject }.to change{ ReportNote.count }.by(1)
|
||||
expect(report.reload).to be_action_taken
|
||||
expect(subject).to redirect_to admin_reports_path
|
||||
end
|
||||
end
|
||||
|
||||
context 'when create_and_resolve flag is false' do
|
||||
let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
|
||||
|
||||
it 'creates a report note and does not resolve report' do
|
||||
expect{ subject }.to change{ ReportNote.count }.by(1)
|
||||
expect(report.reload).not_to be_action_taken
|
||||
expect(subject).to redirect_to admin_report_path(report)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when report is resolved' do
|
||||
let(:action_taken) { true }
|
||||
let(:account_id) { user.account.id }
|
||||
|
||||
context 'when create_and_unresolve flag is on' do
|
||||
let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_unresolve: nil } }
|
||||
|
||||
it 'creates a report note and unresolves report' do
|
||||
expect{ subject }.to change{ ReportNote.count }.by(1)
|
||||
expect(report.reload).not_to be_action_taken
|
||||
expect(subject).to redirect_to admin_report_path(report)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when create_and_unresolve flag is false' do
|
||||
let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
|
||||
|
||||
it 'creates a report note and does not unresolve report' do
|
||||
expect{ subject }.to change{ ReportNote.count }.by(1)
|
||||
expect(report.reload).to be_action_taken
|
||||
expect(subject).to redirect_to admin_report_path(report)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when parameter is invalid' do
|
||||
let(:params) { { report_note: { content: '', report_id: report.id } } }
|
||||
let(:action_taken) { false }
|
||||
let(:account_id) { nil }
|
||||
|
||||
it 'renders admin/reports/show' do
|
||||
expect(subject).to render_template 'admin/reports/show'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
subject { delete :destroy, params: { id: report_note.id } }
|
||||
|
||||
let!(:report_note) { Fabricate(:report_note) }
|
||||
|
||||
it 'deletes note' do
|
||||
expect{ subject }.to change{ ReportNote.count }.by(-1)
|
||||
expect(subject).to redirect_to admin_report_path(report_note.report)
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
Fabricator(:report_note) do
|
||||
report
|
||||
account { Fabricate(:account) }
|
||||
content "Test Content"
|
||||
end
|
Loading…
Reference in new issue