2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2018-11-14 00:55:07 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2022-06-23 18:19:27 +00:00
|
|
|
import { find, render, waitUntil } from '@ember/test-helpers';
|
2018-11-14 00:55:07 +00:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2022-06-29 22:09:08 +00:00
|
|
|
import { addMinutes, subMinutes } from 'date-fns';
|
2018-11-14 00:55:07 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Integration | Component | token-expire-warning', function (hooks) {
|
2018-11-14 00:55:07 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders a warning when the token is expired', async function (assert) {
|
2022-06-29 22:09:08 +00:00
|
|
|
const expirationDate = subMinutes(Date.now(), 30);
|
2018-11-14 00:55:07 +00:00
|
|
|
this.set('expirationDate', expirationDate);
|
|
|
|
|
2022-10-18 15:46:02 +00:00
|
|
|
await render(hbs`<TokenExpireWarning @expirationDate={{this.expirationDate}}/>`);
|
2022-06-23 18:19:27 +00:00
|
|
|
await waitUntil(() => find('#modal-overlays'));
|
2018-11-14 00:55:07 +00:00
|
|
|
assert.dom().includesText('Your auth token expired on');
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it does not render a warning when the token is not expired', async function (assert) {
|
2018-11-14 00:55:07 +00:00
|
|
|
const expirationDate = addMinutes(Date.now(), 30);
|
|
|
|
this.set('expirationDate', expirationDate);
|
|
|
|
|
|
|
|
await render(hbs`
|
2022-10-18 15:46:02 +00:00
|
|
|
<TokenExpireWarning @expirationDate={{this.expirationDate}}>
|
2018-11-14 00:55:07 +00:00
|
|
|
<p>Do not worry, your token has not expired.</p>
|
|
|
|
</TokenExpireWarning>
|
|
|
|
`);
|
2022-06-23 18:19:27 +00:00
|
|
|
await waitUntil(() => find('#modal-overlays'));
|
2018-11-14 00:55:07 +00:00
|
|
|
assert.dom().doesNotIncludeText('Your auth token expired on');
|
|
|
|
assert.dom().includesText('Do not worry');
|
|
|
|
});
|
|
|
|
});
|