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