vault/ui/tests/integration/components/config-ui/messages/page/create-and-edit-message-test.js
Kianna b85365e980
UI: [VAULT-19096] Customizable banners (#23945)
* UI: [VAULT-21521] Initial config-ui engine and routes set up (#23922)

* UI: [VAULT-21526] Create adapter, serializer, and model files (#23947)

* UI: [VAULT-21588] Add Custom Messages to the sidebar (#23946)

* UI: [VAULT-21527] Mirage setup (#24000)

* UI: [VAULT-21530] Custom Messages List View w/ Pagination and LazyPaginatedQuery (#24133)

* UI: Add list to adapter query param (#24187)

* UI: [VAULT-21532] Create message (#24407)

* WIP create message

* Add breadcrumns

* Create and edit form

* Add save to create/edit form

* Add cancel and todo

* Fix cancel route

* Fix breadcrumb label to be title case

* add start time logic

* Update breadcrumb

* Fix breadcrumbs and merge conflict test

* Update create form description

* Fix sidenav so it always highlights

* Fix up forms

* Mostly working create form

* Form cleanup

* Fix link title and href form fields

* Default startTime

* Fix messages

* Update dropdown to use the updated ConfirmAction component

* Update create and edit form

* Add wip tests

* Fix breadcrumb formatter

* Comment out test

* Update create message test

* Update more tests

* Add comment for fixing date on edit

* Update Message form

* Code cleanup!

* Add validation tests

* Remove authenticated from route model

* SOme more code cleanup

* Add controller so authenticated is parsed

* Working radio buttons

* Use an object instead of arrays

* Wip date form

* Fix license headers

* Fix license headers addition of files

* Fix copyright format issues and clean up code

* Fix tests

* Rename FormField radio getter and ay11 improvements

* Address feedback

* Fix specific date so it remembers the values

* Address feedback!

* Update more form fields

* Use formfield action instead

* Update to every

* Update syntax of onchange

* Fix tests

* Update willDestroy so it doesnt break tests

* Remove set and brodcast datetimelocal

* Put FormField back the way it was in favor of putting FormField to a seperate PR

* Remove getter in formfield component file

* Address more feedback

* Put back test

* Update datetime string format var name and location

* UI: [VAULT-21534 VAULT-21533 VAULT-21536] edit, preview, and delete custom message (#24603)

* Working edit

* VAULT-21536 update delete message and create/update flash message

* VAULT-21533 add preview modal

* Update serializer

* Preview refinements

* Move preview to its own component

* Move breadcrumbs to setupController

* Add more tests

* Address some feedback

* Address more feedback!

* Update serailizer

* Remove stylesheet

* Add comment

* UI: [VAULT-21435] Message details (#24645)

* WIP

* Fix timezone bug

* Fix date issues on create/edit form

* Add details screen

* Use allFields instead of formFields

* Fix tests

* Address comments!

* UI: VAULT-21538 unauth endpoint message display (#24665)

* WIP unauth display

* Add modal custom message

* Close multiple modals

* Update todo with ticket number

* On init make custom message request

* Use serializer

* Update fetchMessages

* Add copyright headers

* Add services and serializers

* Send null instead of empty strings

* Fix tests!

* Add copywrite headers

* Add some acceptance tests

* Test cleanup

* Put tests back

* pass hooks to module

* Move module out

* Seperate tests

* Copywrite

* Add aria-prohibited-attr runList options

* Code cleanup

* Add date-time-local transform

* Add copyright headers

* Remove comments

* Remove date transform stuff for now!

* Put getISODateFormat back into the serailize function

* UI: Date time local transform (#24694)

* Date time local

* Add deserialize

* Add copyright header

* check if date exists

* Use parseISO for date strings since datefns requires this in new update

* Update tests

* Ensure we cehck for an ISOString

* Add checks so tests wont fail

* Update parseISO

* Address feedback

* UI: multiple banner message on create and edit form (#24742)

* WIP multiple banner message on create and edit form

* Fix tests

* Put checks back

* Add try/catch to query

* Fix breadcrumbs

* Add page size to pagination

* Add multiple modal message tests

* Address feedback

* Check for valid form first

* Add extra checks

* Address feedback

* Move getter to the route

* Fix tests!

* Address more feedback

* Use still when cancelling

* Update multiple banner modal

* Fix tests

* Set user confirmation to empty string

* UI: VAULT-21539 auth messages display (#24842)

* WIP auth message display

* Move block to show only when authenticated

* VAULT-22046 working search by name

* Some code clean up

* Fix merge conflict

* Add tests

* Fetch messages again after creation

* UI: [VAULT-22908] Update kv object editor, add max number of messages reached modal, small improvements (#24918)

* Update kv object editor to only use a single row

* continute using kv editype

* Fix failing dashboard tests!

* Fix failing test on sidebranch

* Fix tests and update validations

* Add optional tag

* Address feedback

* Add documentation

* Clear messages when logging out

* Fix tests!

* Add 100 message limit modal

* Add max message modal test

* Do more checks!

* Pair with Claire on the refactor of validator!

* Only show validationerror for multiple rows

* Update pageSize to 100 since when paginations are active it causes accessbility errors

* Fix tests!

* Add links to test

* Make banners dismissable

* Add cancel button

* Address feedback!

* Update test selectors

* Update validator

* Remove validations check in kvobjecteditor

* Revert validationError in kvobjecteditor template

* Put back if/else statements for link

* Add changelog

* UI: fix link bug and add colors (#24977)

* Fix edit bug and put transform back

* Edit badgeColor

* Add tests

* Revert changes to transform

* Edit badge colors

* remove universal object transform

* Update changelog filename

* UI: Add form inline warning (#24986)

* Add form inline warning

* Remove title

* Only show form warning for unauth

* Address feedback!
2024-01-23 15:04:17 -08:00

228 lines
10 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupRenderingTest } from 'vault/tests/helpers';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { setupEngine } from 'ember-engines/test-support';
import { render, click, fillIn } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { datetimeLocalStringFormat } from 'core/utils/date-formatters';
import { format, addDays, startOfDay } from 'date-fns';
import { PAGE } from 'vault/tests/helpers/config-ui/message-selectors';
module('Integration | Component | messages/page/create-and-edit-message', function (hooks) {
setupRenderingTest(hooks);
setupEngine(hooks, 'config-ui');
setupMirage(hooks);
hooks.beforeEach(function () {
this.context = { owner: this.engine };
this.store = this.owner.lookup('service:store');
this.message = this.store.createRecord('config-ui/message');
});
test('it should display all the create form fields and default radio button values', async function (assert) {
await render(hbs`<Messages::Page::CreateAndEditMessageForm @message={{this.message}} />`, {
owner: this.engine,
});
assert.dom('[data-test-page-title]').hasText('Create message');
assert
.dom('[data-test-form-subtext]')
.hasText('Create a custom message for all users when they access a Vault system via the UI.');
assert.dom(PAGE.radio('authenticated')).exists();
assert.dom(PAGE.radio('unauthenticated')).exists();
assert.dom(PAGE.radio('authenticated')).isChecked();
assert.dom(PAGE.radio('unauthenticated')).isNotChecked();
assert.dom(PAGE.radio('banner')).exists();
assert.dom(PAGE.radio('modal')).exists();
assert.dom(PAGE.radio('banner')).isChecked();
assert.dom(PAGE.radio('modal')).isNotChecked();
assert.dom(PAGE.field('title')).exists();
assert.dom(PAGE.field('message')).exists();
assert.dom('[data-test-kv-key="0"]').exists();
assert.dom('[data-test-kv-value="0"]').exists();
assert.dom(PAGE.input('startTime')).exists();
assert
.dom(PAGE.input('startTime'))
.hasValue(format(addDays(startOfDay(new Date()), 1), datetimeLocalStringFormat));
assert.dom(PAGE.input('endTime')).exists();
assert.dom(PAGE.input('endTime')).hasValue('');
});
test('it should create new message', async function (assert) {
assert.expect(1);
this.server.post('/sys/config/ui/custom-messages', () => {
assert.ok(true, 'POST request made to create message');
});
await render(hbs`<Messages::Page::CreateAndEditMessageForm @message={{this.message}} />`, {
owner: this.engine,
});
await fillIn(PAGE.input('title'), 'Awesome custom message title');
await fillIn(
PAGE.input('message'),
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar mattis nunc sed blandit libero volutpat sed cras ornare.'
);
await fillIn(
PAGE.input('startTime'),
format(addDays(startOfDay(new Date('2023-12-12')), 1), datetimeLocalStringFormat)
);
await click('#specificDate');
await fillIn(
PAGE.input('endTime'),
format(addDays(startOfDay(new Date('2023-12-12')), 10), datetimeLocalStringFormat)
);
await fillIn('[data-test-kv-key="0"]', 'Learn more');
await fillIn('[data-test-kv-value="0"]', 'www.learn.com');
await click(PAGE.button('create-message'));
});
test('it should have form vaildations', async function (assert) {
await render(hbs`<Messages::Page::CreateAndEditMessageForm @message={{this.message}} />`, {
owner: this.engine,
});
await click(PAGE.button('create-message'));
assert.dom(PAGE.input('title')).hasClass('has-error-border', 'show error border for title field');
assert.dom(`${PAGE.fieldVaildation('title')} ${PAGE.inlineErrorMessage}`).hasText('Title is required.');
assert.dom(PAGE.input('message')).hasClass('has-error-border', 'show error border for message field');
assert
.dom(`${PAGE.fieldVaildation('message')} ${PAGE.inlineErrorMessage}`)
.hasText('Message is required.');
});
test('it should prepopulate form if form is in edit mode', async function (assert) {
this.store.pushPayload('config-ui/message', {
modelName: 'config-ui/message',
id: 'hhhhh-iiii-lllll-dddd',
type: 'modal',
authenticated: false,
title: 'Hello world',
message: 'Blah blah blah. Some super long message.',
start_time: '2023-12-12T08:00:00.000Z',
end_time: '2023-12-21T08:00:00.000Z',
link: { 'Learn more': 'www.learnmore.com' },
});
this.message = this.store.peekRecord('config-ui/message', 'hhhhh-iiii-lllll-dddd');
await render(hbs`<Messages::Page::CreateAndEditMessageForm @message={{this.message}} />`, {
owner: this.engine,
});
assert.dom('[data-test-page-title]').hasText('Edit message');
assert
.dom('[data-test-form-subtext]')
.hasText('Edit a custom message for all users when they access a Vault system via the UI.');
assert.dom(PAGE.radio('authenticated')).exists();
assert.dom(PAGE.radio('unauthenticated')).isChecked();
assert.dom(PAGE.radio('modal')).exists();
assert.dom(PAGE.radio('modal')).isChecked();
assert.dom(PAGE.input('title')).hasValue('Hello world');
assert.dom(PAGE.input('message')).hasValue('Blah blah blah. Some super long message.');
assert.dom('[data-test-kv-key="0"]').exists();
assert.dom('[data-test-kv-key="0"]').hasValue('Learn more');
assert.dom('[data-test-kv-value="0"]').exists();
assert.dom('[data-test-kv-value="0"]').hasValue('www.learnmore.com');
await click('#specificDate');
assert
.dom(PAGE.input('startTime'))
.hasValue(format(new Date(this.message.startTime), datetimeLocalStringFormat));
assert
.dom(PAGE.input('endTime'))
.hasValue(format(new Date(this.message.endTime), datetimeLocalStringFormat));
});
test('it should show a preview image modal when preview is clicked', async function (assert) {
await render(hbs`<Messages::Page::CreateAndEditMessageForm @message={{this.message}} />`, {
owner: this.engine,
});
await fillIn(PAGE.input('title'), 'Awesome custom message title');
await fillIn(
PAGE.input('message'),
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar mattis nunc sed blandit libero volutpat sed cras ornare.'
);
await click(PAGE.button('preview'));
assert.dom(PAGE.modal('preview modal')).doesNotExist();
assert.dom(PAGE.modal('preview image')).exists();
assert.dom(PAGE.alertTitle('Awesome custom message title')).hasText('Awesome custom message title');
assert
.dom(PAGE.alertDescription('Awesome custom message title'))
.hasText(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar mattis nunc sed blandit libero volutpat sed cras ornare.'
);
assert.dom('img').hasAttribute('src', '/ui/images/custom-messages-dashboard.png');
await click(PAGE.modalButton('Close'));
await click('#unauthenticated');
await click(PAGE.button('preview'));
assert.dom('img').hasAttribute('src', '/ui/images/custom-messages-login.png');
});
test('it should show a preview modal when preview is clicked', async function (assert) {
await render(hbs`<Messages::Page::CreateAndEditMessageForm @message={{this.message}} />`, {
owner: this.engine,
});
await click(PAGE.radio('modal'));
await fillIn(PAGE.input('title'), 'Preview modal title');
await fillIn(PAGE.input('message'), 'Some preview modal message thats super long.');
await click(PAGE.button('preview'));
assert.dom(PAGE.modal('preview modal')).exists();
assert.dom(PAGE.modal('preview image')).doesNotExist();
assert.dom(PAGE.modalTitle('Preview modal title')).hasText('Preview modal title');
assert.dom(PAGE.modalBody('Preview modal title')).hasText('Some preview modal message thats super long.');
});
test('it should show multiple modal message', async function (assert) {
this.store.pushPayload('config-ui/message', {
modelName: 'config-ui/message',
id: '01234567-89ab-cdef-0123-456789abcdef',
active: true,
type: 'modal',
authenticated: true,
title: 'Message title 1',
message: 'Some long long long message',
link: { here: 'www.example.com' },
startTime: '2021-08-01T00:00:00Z',
endTime: '',
});
this.store.pushPayload('config-ui/message', {
modelName: 'config-ui/message',
id: '01234567-89ab-vvvv-0123-456789abcdef',
active: true,
type: 'modal',
authenticated: false,
title: 'Message title 2',
message: 'Some long long long message',
link: { here: 'www.example.com' },
startTime: '2021-08-01T00:00:00Z',
endTime: '2090-08-01T00:00:00Z',
});
this.messages = this.store.peekAll('config-ui/message');
await render(
hbs`<Messages::Page::CreateAndEditMessageForm @message={{this.message}} @messages={{this.messages}} @hasSomeActiveModals={{true}} />`,
{
owner: this.engine,
}
);
await fillIn(PAGE.input('title'), 'Awesome custom message title');
await fillIn(
PAGE.input('message'),
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar mattis nunc sed blandit libero volutpat sed cras ornare.'
);
await click(PAGE.radio('modal'));
await click(PAGE.button('create-message'));
assert.dom(PAGE.modalTitle('Warning: more than one modal')).exists();
assert
.dom(PAGE.modalBody('Warning: more than one modal'))
.hasText(
'You have an active modal configured after the user logs in and are trying to create another one. It is recommended to avoid having more than one modal at once as it can be intrusive for users. Would you like to continue creating your message? Click “Confirm” to continue.'
);
await click(PAGE.modalButton('confirm'));
});
});