Skip to content

Commit

Permalink
Merge pull request apex-enterprise-patterns#25 from OrtooApps/feature…
Browse files Browse the repository at this point in the history
…/updates-to-support-example-app-repo

Added passing through of labels into the buttons in the view and edit…
  • Loading branch information
rob-baillie-ortoo committed Mar 25, 2022
2 parents 69a9fea + 4e86c73 commit fc8c930
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('c-view-and-edit-form', () => {
expect( additionalEditButtons ).not.toBe( null );
});

it('When visible card and not inEditMode, has an edit button, but no save or cancel', () => {
it('When visible card and not inEditMode, has an edit button, but no save or cancel', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
});
Expand All @@ -51,7 +51,7 @@ describe('c-view-and-edit-form', () => {
expect( additionalEditButtons ).toBe( null );
});

it('When visible card and inEditMode, has an editForm slot but no viewForm slot', () => {
it('When visible card and inEditMode, has an editForm, title and info slot but no viewForm slot', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
});
Expand All @@ -64,9 +64,15 @@ describe('c-view-and-edit-form', () => {

const editForm = element.shadowRoot.querySelector( 'slot[name="edit-form"]' );
expect( editForm ).not.toBe( null );
});

it('When visible card and not inEditMode, has a viewForm slot but no editForm slot', () => {
const title = element.shadowRoot.querySelector( 'slot[name="title"]' );
expect( title ).not.toBe( null );

const info = element.shadowRoot.querySelector( 'slot[name="info"]' );
expect( info ).not.toBe( null );
});

it('When visible card and not inEditMode, has a viewForm, title and info slot but no editForm slot', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
});
Expand All @@ -79,6 +85,12 @@ describe('c-view-and-edit-form', () => {

const editForm = element.shadowRoot.querySelector( 'slot[name="edit-form"]' );
expect( editForm ).toBe( null );

const title = element.shadowRoot.querySelector( 'slot[name="title"]' );
expect( title ).not.toBe( null );

const info = element.shadowRoot.querySelector( 'slot[name="info"]' );
expect( info ).not.toBe( null );
});

it('When visible card, and inEditMode, clicking save will issue a save event', () => {
Expand Down Expand Up @@ -144,6 +156,21 @@ describe('c-view-and-edit-form', () => {
})
});

it('When visible card, inEditMode, and save and cancel button labels specified, will display those labels', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
});
element.visible = true;
element.inEditMode = true;
element.saveLabel = 'overridden-save';
element.cancelLabel = 'overridden-cancel';
document.body.appendChild(element);

const saveButtons = element.shadowRoot.querySelector( 'c-save-buttons' );
expect( saveButtons.saveLabel ).toBe( 'overridden-save' );
expect( saveButtons.cancelLabel ).toBe( 'overridden-cancel' );
});

it('When visible modal and inEditMode, has a save and cancel button, but no edit', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
Expand Down Expand Up @@ -188,7 +215,7 @@ describe('c-view-and-edit-form', () => {
expect( additionalEditButtons ).toBe( null );
});

it('When visible modal and inEditMode, has an editForm slot but no viewForm slot', () => {
it('When visible modal and inEditMode, has an editForm, title and info slot but no viewForm slot', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
});
Expand All @@ -202,9 +229,15 @@ describe('c-view-and-edit-form', () => {

const editForm = element.shadowRoot.querySelector( 'slot[name="edit-form"]' );
expect( editForm ).not.toBe( null );
});

it('When visible modal and not inEditMode, has a viewForm slot but no editForm slot', () => {
const title = element.shadowRoot.querySelector( 'slot[name="title"]' );
expect( title ).not.toBe( null );

const info = element.shadowRoot.querySelector( 'slot[name="info"]' );
expect( info ).not.toBe( null );
});

it('When visible modal and not inEditMode, has a viewForm, title and info slot but no editForm slot', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
});
Expand All @@ -218,6 +251,12 @@ describe('c-view-and-edit-form', () => {

const editForm = element.shadowRoot.querySelector( 'slot[name="edit-form"]' );
expect( editForm ).toBe( null );

const title = element.shadowRoot.querySelector( 'slot[name="title"]' );
expect( title ).not.toBe( null );

const info = element.shadowRoot.querySelector( 'slot[name="info"]' );
expect( info ).not.toBe( null );
});

it('When visible modal, and inEditMode, clicking save will issue a save event', () => {
Expand Down Expand Up @@ -286,6 +325,22 @@ describe('c-view-and-edit-form', () => {
})
});

it('When visible modal, inEditMode, and save and cancel button labels specified, will display those labels', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
});
element.mode = 'modal';
element.visible = true;
element.inEditMode = true;
element.saveLabel = 'overridden-save';
element.cancelLabel = 'overridden-cancel';
document.body.appendChild(element);

const saveButtons = element.shadowRoot.querySelector( 'c-save-buttons' );
expect( saveButtons.saveLabel ).toBe( 'overridden-save' );
expect( saveButtons.cancelLabel ).toBe( 'overridden-cancel' );
});

it('When configured with an invalid mode, will throw an error', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</div>

<div class="slds-p-around_small">
<slot name="info"></slot>
<slot name="view-form"></slot>
</div>
</lightning-card>
Expand All @@ -32,15 +33,19 @@
</div>

<div class="slds-p-around_small">
<lightning-messages></lightning-messages>
<slot name="info"></slot>

<lightning-messages></lightning-messages>

<slot name="edit-form"></slot>
</div>

<div slot="footer">

<c-save-buttons
onsave={handleSaveClick}
save-label={saveLabel}
cancel-label={cancelLabel}
onsave={handleSaveClick}
oncancel={handleCancelClick}
>
<span slot="additional-buttons">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
</lightning-button-group>

<div slot="contents">

<slot name="info"></slot>

<template if:false={inEditMode}>
<slot name="view-form"></slot>
</template>
Expand All @@ -37,7 +40,9 @@

<div slot="footer" if:true={inEditMode}>

<c-save-buttons
<c-save-buttons
cancel-label={cancelLabel}
save-label={saveLabel}
onsave={handleSaveClick}
oncancel={handleCancelClick}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ public class ortoo_FabricatedSObjectRegister {
SobjectField relationshipField = new sfab_ObjectDescriber().getFieldForChildRelationship( parent.getSobjectName(), relationship );
return new Relationship( child, relationshipField, parent );
}
}
}

0 comments on commit fc8c930

Please sign in to comment.