Skip to content

Commit

Permalink
Move some view form text over to labels
Browse files Browse the repository at this point in the history
Started the view form unit tests
  • Loading branch information
rob-baillie-ortoo committed Dec 14, 2021
1 parent 61a02a3 commit b39e23c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 5 deletions.
4 changes: 3 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ Look at:
* Once you add it, it cannot be removed
* Always qualify the record page target with the sobject types it's appropriate for


* use standard validation techniques
* Add the property data-validatable
* call reportValidity, binding it to the LWC

* To finalise the core architecture:
* Do we need to have a non all-or-nothing version of commitWork?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@
<shortDescription>The word 'Save', capitalised.</shortDescription>
<value>Save</value>
</labels>
<labels>
<fullName>ortoo_core_edit</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>The word 'Edit', capitalised.</shortDescription>
<value>Edit</value>
</labels>
<labels>
<fullName>ortoo_core_error_title</fullName>
<language>en_US</language>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { createElement } from 'lwc';
import ViewAndEditForm from 'c/viewAndEditForm';

describe('c-view-and-edit-form', () => {
afterEach(() => {
// The jsdom instance is shared across test cases in a single file so reset the DOM
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
});

it('When inEditMode, has a save and cancel button, but no edit', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
});
element.inEditMode = true;
document.body.appendChild(element);

const saveButton = element.shadowRoot.querySelector( '[data-name="save"]' );
expect( saveButton ).not.toBe( null );

const cancelButton = element.shadowRoot.querySelector( '[data-name="cancel"]' );
expect( cancelButton ).not.toBe( null );

const editButton = element.shadowRoot.querySelector( '[data-name="edit"]' );
expect( editButton ).toBe( null );
});

it('When not inEditMode, has an edit button, but no save or cancel', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
});
element.inEditMode = false;
document.body.appendChild(element);

const saveButton = element.shadowRoot.querySelector( '[data-name="save"]' );
expect( saveButton ).toBe( null );

const cancelButton = element.shadowRoot.querySelector( '[data-name="cancel"]' );
expect( cancelButton ).toBe( null );

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

it('When inEditMode, has an editForm slot but no viewForm slot', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
});
element.inEditMode = true;
document.body.appendChild(element);

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

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

it('When not inEditMode, has a viewForm slot but no editForm slot', () => {
const element = createElement('c-view-and-edit-form', {
is: ViewAndEditForm
});
element.inEditMode = false;
document.body.appendChild(element);

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

const editForm = element.shadowRoot.querySelector( 'slot[name="editForm"]' );
expect( editForm ).toBe( null );
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class="slds-m-top_small slds-float_right"
variant="default"
name="edit"
data-name="edit"
label={editButtonLabel}
onclick={handleEditClick}
></lightning-button>
Expand Down Expand Up @@ -43,6 +44,7 @@
<lightning-button
variant="default"
name="cancel"
data-name="cancel"
label={cancelButtonLabel}
onclick={handleCancelClick}
></lightning-button>
Expand All @@ -52,6 +54,7 @@
<lightning-button
variant="brand"
name="save"
data-name="save"
label={saveButtonLabel}
onclick={handleSaveClick}
></lightning-button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { LightningElement, api } from 'lwc';

import SAVE_LABEL from '@salesforce/label/c.ortoo_core_save';
import CANCEL_LABEL from '@salesforce/label/c.ortoo_core_cancel';
import EDIT_LABEL from '@salesforce/label/c.ortoo_core_edit';

/**
* Provides a standard format for a dual mode, view and edit form, including the rendering of edit / save and cancel buttons
*/
export default class ViewAndEditForm extends LightningElement {

@api inEditMode = false;

// TODO: labels
@api editButtonLabel = 'Edit';
@api cancelButtonLabel = 'Cancel';
@api saveButtonLabel = 'Save';
@api editButtonLabel = EDIT_LABEL;
@api cancelButtonLabel = CANCEL_LABEL;
@api saveButtonLabel = SAVE_LABEL;

@api displayDensity;

Expand Down

0 comments on commit b39e23c

Please sign in to comment.