Skip to content

Commit

Permalink
fix: Access the nl version in decli
Browse files Browse the repository at this point in the history
Co-authored-by: Laura Bergoens <[email protected]>
Co-authored-by: Jérémie Jadé <[email protected]>
Co-authored-by: Fael Bassetti <[email protected]>
  • Loading branch information
4 people committed Oct 9, 2024
1 parent f6b7db6 commit 1db078d
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export default class SingleRoute extends Route {
return this.store.findRecord('challenge', params.alternative_id);
}

async afterModel(model) {
super.afterModel(...arguments);
await model.localizedChallenges;
await model?.files;
}

setupController(controller) {
super.setupController(...arguments);
controller.edition = false;
Expand Down
181 changes: 114 additions & 67 deletions pix-editor/tests/acceptance/localized-challenge-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,125 @@ module('Acceptance | Localized-Challenge', function(hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

hooks.beforeEach(function() {
this.server.create('config', 'default');
this.server.create('user', { trigram: 'ABC' });

this.server.create('challenge', { id: 'recChallenge1', airtableId: 'airtableId1', embedURL: 'https://mon-site.fr/my-link.html?lang=fr' });
this.server.create('localized-challenge', { id: 'recChallenge1', challengeId: 'recChallenge1', locale: 'fr' });
this.server.create('localized-challenge', { id: 'recChallenge1NL', challengeId: 'recChallenge1', locale: 'nl', defaultEmbedURL: 'https://mon-site.fr/my-link.html?lang=nl' });
this.server.create('skill', { id: 'recSkill1', challengeIds: ['recChallenge1'] });
this.server.create('tube', { id: 'recTube1', rawSkillIds: ['recSkill1'] });
this.server.create('theme', { id: 'recTheme1', name: 'theme1', rawTubeIds: ['recTube1'] });
this.server.create('competence', {
id: 'recCompetence1.1',
pixId: 'pixId recCompetence1.1',
rawThemeIds: ['recTheme1'],
rawTubeIds: ['recTube1'],
module('When interacting with a prototype', function(hooks) {
hooks.beforeEach(function() {
this.server.create('config', 'default');
this.server.create('user', { trigram: 'ABC' });

this.server.create('challenge', { id: 'recChallenge1', airtableId: 'airtableId1', embedURL: 'https://mon-site.fr/my-link.html?lang=fr', genealogy: 'Prototype 1', version: 1 });
this.server.create('localized-challenge', { id: 'recChallenge1', challengeId: 'recChallenge1', locale: 'fr' });
this.server.create('localized-challenge', { id: 'recChallenge1NL', challengeId: 'recChallenge1', locale: 'nl', defaultEmbedURL: 'https://mon-site.fr/my-link.html?lang=nl' });
this.server.create('skill', { id: 'recSkill1', challengeIds: ['recChallenge1'] });
this.server.create('tube', { id: 'recTube1', rawSkillIds: ['recSkill1'] });
this.server.create('theme', { id: 'recTheme1', name: 'theme1', rawTubeIds: ['recTube1'] });
this.server.create('competence', {
id: 'recCompetence1.1',
pixId: 'pixId recCompetence1.1',
rawThemeIds: ['recTheme1'],
rawTubeIds: ['recTube1'],
});
this.server.create('area', {
id: 'recArea1',
name: '1. Information et données',
code: '1',
competenceIds: ['recCompetence1.1'],
});
this.server.create('framework', { id: 'recFramework1', name: 'Pix', areaIds: ['recArea1'] });
return authenticateSession();
});
this.server.create('area', {
id: 'recArea1',
name: '1. Information et données',
code: '1',
competenceIds: ['recCompetence1.1'],

test('should display a default embedUrl if is empty but not for primary', async function(assert) {
// when
const screen = await visit('/');
await click(findAll('[data-test-area-item]')[0]);
await click(findAll('[data-test-competence-item]')[0]);
await click(findAll('[data-test-skill-cell-link]')[0]);
await clickByText('Version nl');

// then
assert.dom(await screen.queryByText('https://mon-site.fr/my-link.html?lang=nl', { exact: false })).exists();
});
this.server.create('framework', { id: 'recFramework1', name: 'Pix', areaIds: ['recArea1'] });
return authenticateSession();
});
test('should not display a default url if primary does not have any', async function(assert) {
// given
this.server.create('challenge', { id: 'recChallenge2', airtableId: 'airtableId1', embedURL: null });
this.server.create('localized-challenge', { id: 'recChallenge2', challengeId: 'recChallenge2', locale: 'fr' });
this.server.create('localized-challenge', { id: 'recChallenge2NL', challengeId: 'recChallenge2', locale: 'nl' });
this.server.create('skill', { id: 'recSkill2', challengeIds: ['recChallenge2'], level: 1, tubeId: 'recTube1' });

test('should display a default embedUrl if is empty but not for primary', async function(assert) {
// when
const screen = await visit('/');
await click(findAll('[data-test-area-item]')[0]);
await click(findAll('[data-test-competence-item]')[0]);
await click(findAll('[data-test-skill-cell-link]')[0]);
await clickByText('Version nl');
// when
const screen = await visit('/');
await click(findAll('[data-test-area-item]')[0]);
await click(findAll('[data-test-competence-item]')[0]);
await click(findAll('[data-test-skill-cell-link]')[0]);
await clickByText('Version nl');

// then
assert.dom(await screen.queryByText('Embed URL auto-générée', { exact: false })).doesNotExist();
});
test('should display an embed url if localized challenge has one', async function(assert) {
// given
this.server.create('challenge', { id: 'recChallenge2', airtableId: 'airtableId1' });
this.server.create('localized-challenge', { id: 'recChallenge2', challengeId: 'recChallenge2', locale: 'fr' });
this.server.create('localized-challenge', { id: 'recChallenge2NL', challengeId: 'recChallenge2', locale: 'nl', embedURL: 'https://mon-site.fr/my-nl-link.html' });
this.server.create('skill', { id: 'recSkill2', challengeIds: ['recChallenge2'], level: 1, tubeId: 'recTube1' });

// when
const screen = await visit('/');
await click(findAll('[data-test-area-item]')[0]);
await click(findAll('[data-test-competence-item]')[0]);
await click(findAll('[data-test-skill-cell-link]')[0]);
await clickByText('Version nl');

// then
const input = await screen.findByLabelText('Embed URL :');
assert.strictEqual(input.value, 'https://mon-site.fr/my-nl-link.html');
});

// then
assert.dom(await screen.queryByText('https://mon-site.fr/my-link.html?lang=nl', { exact: false })).exists();
});
test('should not display a default url if primary does not have any', async function(assert) {
// given
this.server.create('challenge', { id: 'recChallenge2', airtableId: 'airtableId1', embedURL: null });
this.server.create('localized-challenge', { id: 'recChallenge2', challengeId: 'recChallenge2', locale: 'fr' });
this.server.create('localized-challenge', { id: 'recChallenge2NL', challengeId: 'recChallenge2', locale: 'nl' });
this.server.create('skill', { id: 'recSkill2', challengeIds: ['recChallenge2'], level: 1, tubeId: 'recTube1' });

// when
const screen = await visit('/');
await click(findAll('[data-test-area-item]')[0]);
await click(findAll('[data-test-competence-item]')[0]);
await click(findAll('[data-test-skill-cell-link]')[0]);
await clickByText('Version nl');

// then
assert.dom(await screen.queryByText('Embed URL auto-générée', { exact: false })).doesNotExist();
});
test('should display an embed url if localized challenge has one', async function(assert) {
// given
this.server.create('challenge', { id: 'recChallenge2', airtableId: 'airtableId1' });
this.server.create('localized-challenge', { id: 'recChallenge2', challengeId: 'recChallenge2', locale: 'fr' });
this.server.create('localized-challenge', { id: 'recChallenge2NL', challengeId: 'recChallenge2', locale: 'nl', embedURL: 'https://mon-site.fr/my-nl-link.html' });
this.server.create('skill', { id: 'recSkill2', challengeIds: ['recChallenge2'], level: 1, tubeId: 'recTube1' });

// when
const screen = await visit('/');
await click(findAll('[data-test-area-item]')[0]);
await click(findAll('[data-test-competence-item]')[0]);
await click(findAll('[data-test-skill-cell-link]')[0]);
await clickByText('Version nl');

// then
const input = await screen.findByLabelText('Embed URL :');
assert.strictEqual(input.value, 'https://mon-site.fr/my-nl-link.html');
});

module('When interacting with an alternative', function(hooks) {
hooks.beforeEach(function() {
this.server.create('config', 'default');
this.server.create('user', { trigram: 'ABC' });

this.server.create('challenge', { id: 'recChallengeProto1', airtableId: 'airtableIdProto1', genealogy: 'Prototype 1', version: 1 });
this.server.create('challenge', { id: 'recChallenge1', airtableId: 'airtableId1', embedURL: 'https://mon-site.fr/my-link.html?lang=fr', genealogy: 'Décliné 1', version: 1, instruction: 'Instruction de la déclinaison' });
this.server.create('localized-challenge', { id: 'recChallenge1', challengeId: 'recChallenge1', locale: 'fr' });
this.server.create('localized-challenge', { id: 'recChallenge1NL', challengeId: 'recChallenge1', locale: 'nl', defaultEmbedURL: 'https://mon-site.fr/my-link.html?lang=nl' });
this.server.create('skill', { id: 'recSkill1', name: '@acquis2', challengeIds: ['recChallenge1', 'recChallengeProto1'] });
this.server.create('tube', { id: 'recTube1', rawSkillIds: ['recSkill1'] });
this.server.create('theme', { id: 'recTheme1', name: 'theme1', rawTubeIds: ['recTube1'] });
this.server.create('competence', {
id: 'recCompetence1.1',
title: 'Nom de compétence',
code: 1,
pixId: 'pixId recCompetence1.1',
rawThemeIds: ['recTheme1'],
rawTubeIds: ['recTube1'],
});
this.server.create('area', {
id: 'recArea1',
name: 'Nom du domaine',
code: '1',
competenceIds: ['recCompetence1.1'],
});
this.server.create('framework', { id: 'recFramework1', name: 'Pix', areaIds: ['recArea1'] });
return authenticateSession();
});

test('should display a default embedUrl if is empty but not for primary', async function(assert) {
// when
const screen = await visit('/');
await clickByText('Nom du domaine');
await clickByText('1 Nom de compétence');
await clickByText('@acquis2');
await clickByText('Déclinaisons >>');
await clickByText('Instruction de la déclinaison');
await clickByText('Version nl');

// then
assert.dom(await screen.queryByText('https://mon-site.fr/my-link.html?lang=nl', { exact: false })).exists();
});
});
});

0 comments on commit 1db078d

Please sign in to comment.