tweak routes of i18n management
This commit is contained in:
parent
86c39e6b12
commit
6568ed311d
|
|
@ -36,14 +36,14 @@ class TranslationsController extends Controller
|
|||
return redirect('/admin/i18n');
|
||||
}
|
||||
|
||||
public function update(Request $request, Application $app, JavaScript $js)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'id' => 'required|integer',
|
||||
'text' => 'required|string',
|
||||
]);
|
||||
public function update(
|
||||
Request $request,
|
||||
Application $app,
|
||||
JavaScript $js,
|
||||
LanguageLine $line
|
||||
) {
|
||||
$data = $request->validate(['text' => 'required|string']);
|
||||
|
||||
$line = LanguageLine::findOrFail($data['id']);
|
||||
$line->setTranslation($app->getLocale(), $data['text']);
|
||||
$line->save();
|
||||
|
||||
|
|
@ -54,10 +54,11 @@ class TranslationsController extends Controller
|
|||
return json(trans('admin.i18n.updated'), 0);
|
||||
}
|
||||
|
||||
public function delete(Request $request, Application $app, JavaScript $js)
|
||||
{
|
||||
['id' => $id] = $request->validate(['id' => 'required|integer']);
|
||||
$line = LanguageLine::findOrFail($id);
|
||||
public function delete(
|
||||
Application $app,
|
||||
JavaScript $js,
|
||||
LanguageLine $line
|
||||
) {
|
||||
$line->delete();
|
||||
|
||||
if ($line->group === 'front-end') {
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ const Translations: React.FC = () => {
|
|||
}
|
||||
|
||||
const { code, message } = await fetch.put<fetch.ResponseBody>(
|
||||
'/admin/i18n',
|
||||
{ id: line.id, text },
|
||||
`/admin/i18n/${line.id}`,
|
||||
{ text },
|
||||
)
|
||||
if (code === 0) {
|
||||
toast.success(message)
|
||||
|
|
@ -66,7 +66,7 @@ const Translations: React.FC = () => {
|
|||
return
|
||||
}
|
||||
|
||||
const { message } = await fetch.del('/admin/i18n', { id: line.id })
|
||||
const { message } = await fetch.del(`/admin/i18n/${line.id}`)
|
||||
toast.success(message)
|
||||
const { id } = line
|
||||
setLines((lines) => lines.filter((line) => line.id !== id))
|
||||
|
|
|
|||
|
|
@ -45,8 +45,7 @@ describe('edit line', () => {
|
|||
})
|
||||
fireEvent.click(getByText(t('general.confirm')))
|
||||
await waitFor(() =>
|
||||
expect(fetch.put).toBeCalledWith('/admin/i18n', {
|
||||
id: 1,
|
||||
expect(fetch.put).toBeCalledWith(`/admin/i18n/${fixtureLine.id}`, {
|
||||
text: 'finish',
|
||||
}),
|
||||
)
|
||||
|
|
@ -69,8 +68,7 @@ describe('edit line', () => {
|
|||
})
|
||||
fireEvent.click(getByText(t('general.confirm')))
|
||||
await waitFor(() =>
|
||||
expect(fetch.put).toBeCalledWith('/admin/i18n', {
|
||||
id: 1,
|
||||
expect(fetch.put).toBeCalledWith(`/admin/i18n/${fixtureLine.id}`, {
|
||||
text: 'finish',
|
||||
}),
|
||||
)
|
||||
|
|
@ -109,9 +107,7 @@ describe('delete line', () => {
|
|||
fireEvent.click(getByText(t('admin.i18n.delete')))
|
||||
fireEvent.click(getByText(t('general.confirm')))
|
||||
await waitFor(() =>
|
||||
expect(fetch.del).toBeCalledWith('/admin/i18n', {
|
||||
id: 1,
|
||||
}),
|
||||
expect(fetch.del).toBeCalledWith(`/admin/i18n/${fixtureLine.id}`),
|
||||
)
|
||||
expect(queryByText(fixtureLine.text.en)).not.toBeInTheDocument()
|
||||
expect(queryByText('ok')).toBeInTheDocument()
|
||||
|
|
|
|||
|
|
@ -168,8 +168,8 @@ Route::prefix('admin')
|
|||
Route::view('', 'admin.i18n');
|
||||
Route::get('list', 'TranslationsController@list');
|
||||
Route::post('', 'TranslationsController@create');
|
||||
Route::put('', 'TranslationsController@update');
|
||||
Route::delete('', 'TranslationsController@delete');
|
||||
Route::put('{line}', 'TranslationsController@update');
|
||||
Route::delete('{line}', 'TranslationsController@delete');
|
||||
});
|
||||
|
||||
Route::prefix('plugins')->group(function () {
|
||||
|
|
|
|||
|
|
@ -59,32 +59,25 @@ class TranslationsControllerTest extends TestCase
|
|||
|
||||
public function testUpdate()
|
||||
{
|
||||
// Request validation
|
||||
$this->putJson('/admin/i18n', [])->assertJsonValidationErrors('id');
|
||||
$this->putJson('/admin/i18n', ['id' => 'a'])
|
||||
->assertJsonValidationErrors('id');
|
||||
$this->putJson('/admin/i18n', ['id' => 1])
|
||||
->assertJsonValidationErrors('text');
|
||||
|
||||
$this->putJson('/admin/i18n', ['id' => 1, 'text' => 's'])->assertNotFound();
|
||||
|
||||
$this->spy(JavaScript::class, function ($spy) {
|
||||
$spy->shouldReceive('resetTime')->with('en')->once();
|
||||
});
|
||||
LanguageLine::create([
|
||||
$line1 = LanguageLine::create([
|
||||
'group' => 'general',
|
||||
'key' => 'submit',
|
||||
'text' => ['en' => 'submit'],
|
||||
]);
|
||||
LanguageLine::create([
|
||||
$line2 = LanguageLine::create([
|
||||
'group' => 'front-end',
|
||||
'key' => 'general.submit',
|
||||
'text' => ['en' => 'submit'],
|
||||
]);
|
||||
|
||||
$this->putJson('/admin/i18n', ['id' => 1, 'text' => 's'])
|
||||
$this->putJson('/admin/i18n/'.$line1->id)
|
||||
->assertJsonValidationErrors('text');
|
||||
$this->putJson('/admin/i18n/'.$line1->id, ['id' => 1, 'text' => 's'])
|
||||
->assertJson(['code' => 0, 'message' => trans('admin.i18n.updated')]);
|
||||
$this->putJson('/admin/i18n', ['id' => 2, 'text' => 's'])
|
||||
$this->putJson('/admin/i18n/'.$line2->id, ['id' => 2, 'text' => 's'])
|
||||
->assertJson(['code' => 0, 'message' => trans('admin.i18n.updated')]);
|
||||
$this->assertEquals('s', trans('general.submit'));
|
||||
$this->assertEquals('s', trans('front-end.general.submit'));
|
||||
|
|
@ -92,30 +85,23 @@ class TranslationsControllerTest extends TestCase
|
|||
|
||||
public function testDelete()
|
||||
{
|
||||
// Request validation
|
||||
$this->deleteJson('/admin/i18n', [])->assertJsonValidationErrors('id');
|
||||
$this->deleteJson('/admin/i18n', ['id' => 'a'])
|
||||
->assertJsonValidationErrors('id');
|
||||
|
||||
$this->deleteJson('/admin/i18n', ['id' => 1])->assertNotFound();
|
||||
|
||||
$this->spy(JavaScript::class, function ($spy) {
|
||||
$spy->shouldReceive('resetTime')->with('en')->once();
|
||||
});
|
||||
LanguageLine::create([
|
||||
$line1 = LanguageLine::create([
|
||||
'group' => 'general',
|
||||
'key' => 'submit',
|
||||
'text' => ['en' => 'submit'],
|
||||
]);
|
||||
LanguageLine::create([
|
||||
$line2 = LanguageLine::create([
|
||||
'group' => 'front-end',
|
||||
'key' => 'general.submit',
|
||||
'text' => ['en' => 'submit'],
|
||||
]);
|
||||
|
||||
$this->deleteJson('/admin/i18n', ['id' => 1])
|
||||
$this->deleteJson('/admin/i18n/'.$line1->id)
|
||||
->assertJson(['code' => 0, 'message' => trans('admin.i18n.deleted')]);
|
||||
$this->deleteJson('/admin/i18n', ['id' => 2])
|
||||
$this->deleteJson('/admin/i18n/'.$line2->id)
|
||||
->assertJson(['code' => 0, 'message' => trans('admin.i18n.deleted')]);
|
||||
$this->assertEquals('Submit', trans('general.submit'));
|
||||
$this->assertEquals('Submit', trans('front-end.general.submit'));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user