Skip to content

Commit

Permalink
Test and Select a Region default text
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Nov 1, 2024
1 parent 50c4b44 commit d80d17c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
7 changes: 5 additions & 2 deletions ui/app/templates/components/region-switcher.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
@tagName="div"
@triggerClass={{this.decoration}}
@options={{this.sortedRegions}}
@selected={{this.system.activeRegion}}
@selected={{or this.system.activeRegion 'Select a Region'}}
@searchEnabled={{false}}
@onChange={{action this.gotoRegion}} as |region|>
<span class="ember-power-select-prefix">Region: </span>{{region}}
{{#if this.system.activeRegion}}
<span class="ember-power-select-prefix">Region: </span>
{{/if}}
{{region}}
</PowerSelect>
</span>
{{else}}
Expand Down
7 changes: 6 additions & 1 deletion ui/mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,12 @@ export default function () {
return this.serialize(volume);
});

this.get('/agent/members', function ({ agents, regions }) {
this.get('/agent/members', function ({ agents, regions }, req) {
const tokenPresent = req.requestHeaders['X-Nomad-Token'];
if (!tokenPresent) {
return new Response(403, {}, 'Forbidden');
}

const firstRegion = regions.first();
return {
ServerRegion: firstRegion ? firstRegion.id : null,
Expand Down
23 changes: 23 additions & 0 deletions ui/tests/acceptance/regions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import JobsList from 'nomad-ui/tests/pages/jobs/list';
import ClientsList from 'nomad-ui/tests/pages/clients/list';
import Layout from 'nomad-ui/tests/pages/layout';
import Allocation from 'nomad-ui/tests/pages/allocations/detail';
import Tokens from 'nomad-ui/tests/pages/settings/tokens';

module('Acceptance | regions (only one)', function (hooks) {
setupApplicationTest(hooks);
Expand Down Expand Up @@ -218,4 +219,26 @@ module('Acceptance | regions (many)', function (hooks) {
}
});
});

test('Signing in sets the active region', async function (assert) {
window.localStorage.clear();
let managementToken = server.create('token');
await Tokens.visit();
assert.equal(
Layout.navbar.regionSwitcher.text,
'Select a Region',
'Region picker says "Select a Region" before signing in'
);
await Tokens.secret(managementToken.secretId).submit();
assert.equal(
window.localStorage.nomadActiveRegion,
'global',
'Region is set in localStorage after signing in'
);
assert.equal(
Layout.navbar.regionSwitcher.text,
'Region: global',
'Region picker says "Region: global" after signing in'
);
});
});

0 comments on commit d80d17c

Please sign in to comment.