-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* translations atom * migrate Translate WIP * handle inline edit mode * stop event * adds update translations endpoint * wip modal form * get translations V2 WIP * Translate component using translationsAtom and loading correct values in to the trtanslation form * test new endpoint * correctly set form * context to post request * update translate atom after update * uses context by language * look & feel + socket events * ci fixes * migrate t and update cache reset strategy * update affected files * adjust zindex and use t function for texts inside * migrate I18Nmenu * remove icon dependency * cleanup * update import * fix issue with dropdown * update t function and move to v2 folder * update imports * remove unused afterEach * stories cleanup * remove redux provider from pdf unit test * remove commented * locale sensitve i18n link * remove legacy store * use new i18n link for breadcrumbs * reorganize files * unit test snapshot update * update import * avoid undefined when no classname and update snapshots * revert some unnecessary changes * do not return component in notification * fix type + wip fix test * fix export * fix multiple unit test by updating selectors, stores or mocking translate * more fixes * revert removal of redux translations * fix test and eslint errors * update snapshot * update selectors and e2e * more specific selector * wait for modal * attempt to stabilize * I18NMenu test update wip * use actual store for test * use real events * close modal after a11y check * more attempts at fixing e2e * more explicit steps * continued attempt at fixing test * install function handles modal closing * more specific install selector * restore workflow file * account for new languages in socket emit * wip update api * set translation modal's zindex to 10000 * propagation of thesaurus translations * socket events test update * update translations on language delete * udpate how the test updates component * translateModal test wip * test modal closes properly * update submit test * update response type * validate form and notify * fix lint error * stabilze e2e * disable modal elements while saving * update test description * update snapshot * more attempts at e2e stabiliation * cleanup * fix route duplication --------- Co-authored-by: mfacar <[email protected]> Co-authored-by: A happy cat <[email protected]> Co-authored-by: JoshuaD <[email protected]> Co-authored-by: Joan Gallego Girona <[email protected]>
- Loading branch information
1 parent
691ded0
commit 062a26f
Showing
150 changed files
with
3,114 additions
and
2,281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Application, Request } from 'express'; | ||
import { needsAuthorization } from 'api/auth'; | ||
import { validation } from 'api/utils'; | ||
import translations from 'api/i18n'; | ||
import { getTranslationsEntriesV2 } from 'api/i18n/v2_support'; | ||
|
||
const translationsRoutes = (app: Application) => { | ||
app.get('/api/v2/translations', async (_req: Request, res) => { | ||
const translationsV2 = await getTranslationsEntriesV2(); | ||
const translationList = await translationsV2.all(); | ||
res.json(translationList); | ||
}); | ||
|
||
app.post( | ||
'/api/v2/translations', | ||
needsAuthorization(), | ||
validation.validateRequest({ | ||
type: 'object', | ||
properties: { | ||
body: { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
properties: { | ||
_id: { type: 'string' }, | ||
language: { type: 'string' }, | ||
key: { type: 'string' }, | ||
value: { type: 'string' }, | ||
context: { | ||
type: 'object', | ||
properties: { | ||
id: { type: 'string' }, | ||
label: { type: 'string' }, | ||
type: { type: 'string' }, | ||
}, | ||
required: ['id', 'label', 'type'], | ||
}, | ||
}, | ||
required: ['language', 'key', 'value', 'context'], | ||
}, | ||
}, | ||
}, | ||
required: ['body'], | ||
}), | ||
async (req, res) => { | ||
await translations.v2StructureSave(req.body); | ||
req.sockets.emitToCurrentTenant('translationKeysChange', req.body); | ||
res.status(200); | ||
res.json({ success: true }); | ||
} | ||
); | ||
}; | ||
|
||
export { translationsRoutes }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import 'isomorphic-fetch'; | ||
import request from 'supertest'; | ||
|
||
import { TranslationDBO } from 'api/i18n.v2/schemas/TranslationDBO'; | ||
import { getFixturesFactory } from 'api/utils/fixturesFactory'; | ||
import { testingEnvironment } from 'api/utils/testingEnvironment'; | ||
import { TestEmitSources, iosocket, setUpApp } from 'api/utils/testingRoutes'; | ||
import { UserRole } from 'shared/types/userSchema'; | ||
import { translationsRoutes } from '..'; | ||
|
||
describe('i18n translations V2 routes', () => { | ||
const createTranslationDBO = getFixturesFactory().v2.database.translationDBO; | ||
const app = setUpApp(translationsRoutes, (req, _res, next) => { | ||
req.user = { | ||
username: 'admin', | ||
role: UserRole.ADMIN, | ||
email: '[email protected]', | ||
}; | ||
// @ts-ignore | ||
req.file = { path: 'filder/filename.ext' }; | ||
next(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
const translationsV2: TranslationDBO[] = [ | ||
createTranslationDBO('Search', 'Buscar', 'es', { | ||
id: 'System', | ||
type: 'Entity', | ||
label: 'User Interface', | ||
}), | ||
createTranslationDBO('Search', 'Search', 'en', { | ||
id: 'System', | ||
type: 'Uwazi UI', | ||
label: 'User Interface', | ||
}), | ||
]; | ||
await testingEnvironment.setUp( | ||
{ | ||
settings: [ | ||
{ | ||
languages: [ | ||
{ key: 'en', label: 'English', default: true }, | ||
{ key: 'es', label: 'Spanish', default: false }, | ||
], | ||
}, | ||
], | ||
translationsV2, | ||
}, | ||
'index_i18n_v2_routes' | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
iosocket.emit.mockReset(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testingEnvironment.tearDown(); | ||
}); | ||
|
||
describe('/api/v2/translations', () => { | ||
it('should update the translations and emit translationKeysChange event', async () => { | ||
const response = await request(app) | ||
.post('/api/v2/translations') | ||
.send([ | ||
{ | ||
language: 'es', | ||
key: 'Search', | ||
value: 'Búsqueda', | ||
context: { | ||
id: 'System', | ||
label: 'User Interface', | ||
type: 'Uwazi UI', | ||
}, | ||
}, | ||
]); | ||
expect(response.status).toEqual(200); | ||
expect(iosocket.emit).toHaveBeenCalledWith( | ||
'translationKeysChange', | ||
TestEmitSources.currentTenant, | ||
[ | ||
{ | ||
context: { id: 'System', label: 'User Interface', type: 'Uwazi UI' }, | ||
key: 'Search', | ||
language: 'es', | ||
value: 'Búsqueda', | ||
}, | ||
] | ||
); | ||
}); | ||
|
||
it('should handle invalid POST request payload', async () => { | ||
const response = await request(app) | ||
.post('/api/v2/translations') | ||
.send({ invalidKey: 'value' }); // Invalid payload | ||
expect(response.status).toBe(400); | ||
expect(response.body).toEqual( | ||
expect.objectContaining({ prettyMessage: 'validation failed' }) | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.