Skip to content

Conversation

the-t-in-rtf
Copy link
Contributor

See C2LC-248 for details.

@the-t-in-rtf
Copy link
Contributor Author

Quick notes on this:

First, I didn't even try to position the share button. I'll merge with upstream once https://issues.fluidproject.org/browse/C2LC-246 is merged and put it next to the speed controls.

Second, I used a Modal for now, I wanted to discuss perhaps using a Toast instead.

Third, obviously I'll add tests, since we can read the clipboard using the same API and confirm that the value was set.

@the-t-in-rtf
Copy link
Contributor Author

@simonbates, as discussed I just committed my work in progress on new tests for the ShareButton component. There are two failures I could use help with.

 FAIL  src/ShareButton.test.js
  ● displays modal on click

    TypeError: Cannot read property 'writeText' of undefined

      38 |         // Copy the URL to the clipboard, see:
      39 |         // https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText
    > 40 |         navigator.clipboard.writeText(currentUrl).then(() => {

I made an attempt at mocking that part of the API, but somehow what I did isn't exposed to the component itself, i.e. my tests can access my fake readText method, but the component can't access the similar writeText method.

I also commented out the rendering tests, which fail because I don't seem to have wired up the i18n stuff correctly. I'll commit that as well shortly, but here's the error:

    Invariant Violation: [React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.

      37 | it('renders without crashing', () => {
      38 |     const div = document.createElement('div');
    > 39 |     ReactDOM.render(<ShareButton intl={intl}/>, div);
         |              ^
      40 |     ReactDOM.unmountComponentAtNode(div);
      41 | });
      42 | 

I can break these down and research them on my own, but I figured you might be able to at least point me in the right direction.

the-t-in-rtf and others added 4 commits November 11, 2020 15:51
- Use the async form of Jest's test() for the tests which click on the
  Share button, to manage the use of Promises in accessing the clipboard

- Add a callback to ShareButton to receive notification when the modal
  is shown

- Update the test names to use Given, When, Then style

- Add a FakeClipboard class to test interaction with the clipboard
@simonbates
Copy link
Contributor

I've updated the tests for ShareButton in this commit: simonbates@4de7c92

Changes:

  • Use the async form of Jest's test() for the tests which click on the Share button, to manage the use of Promises in accessing the clipboard
  • Add a callback to ShareButton to receive notification when the modal is shown
    • This was necessary due to the use of Promises: we need to wait until the state has been changed before inspecting it
    • I don't love adding a property to ShareButton just to support testing, but it's the best I could think of without making larger changes to the structure of the code
  • Update the test names to use Given, When, Then style
  • I packaged your clipboard implementation up into a new class FakeClipboard, to make it easier to use in multiple tests; I also updated the names to match those in the Flow type definition for clipboard: https://github.com/facebook/flow/blob/f4a9d2634bbe7f4b417289d5bcfaaddc481d192d/lib/bom.js#L314-L318

@the-t-in-rtf
Copy link
Contributor Author

Thanks, @simonbates, for the fix and the links. I copied the it style from the rendering tests I was reading through, the other syntax makes more sense to me. Jest has a really wide range of strategies for handling async calls, that's good to know.

I still need to fix up the rendering test, I'll give that a go on my own a bit later today.

return wrapper;
}

// TODO: Figure how to do this properly with the required intl infrastructure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this comment any longer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 2 to 3
margin-top: 1rem;
height: 2.25rem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need the margin-top and height properties here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@@ -41,6 +41,7 @@ type ProgramBlockEditorProps = {

type ProgramBlockEditorState = {
showConfirmDeleteAll: boolean,
showShareComplete: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the changes in ProgramBlockEditor.js are left over from previous work and can be reverted?

Copy link
Contributor Author

@the-t-in-rtf the-t-in-rtf Nov 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this line and reviewed the changes, what's left now seems appropriate (the new state variable).

src/App.scss Outdated
background-color: #F1F1F1;
display: grid;
grid-template-columns: 1fr 1fr 1fr;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.


type ShareButtonProps = {
intl: IntlShape,
disabled: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The disabled property is never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

class ShareButton extends React.Component<ShareButtonProps, ShareButtonState> {
static defaultProps = {
disabled: false,
showShareComplete: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

showShareComplete is a state value, rather than props.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@simonbates simonbates merged commit edf6288 into codelearncreate:develop-0.5 Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants