Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to distinguish editor vs viewer #57

Open
donquixote opened this issue Nov 14, 2024 · 5 comments
Open

Add tests to distinguish editor vs viewer #57

donquixote opened this issue Nov 14, 2024 · 5 comments

Comments

@donquixote
Copy link
Collaborator

Hello @hfiguiere
I would like to add more tests that verify that the embedded editor works.
To do this, I need to distinguish readonly vs edit, using selenium javascript.

You can see examples of this here, https://github.com/CollaboraOnline/collabora-drupal/blob/main/tests/src/ExistingSiteJavascript/CollaboraIntegrationTest.php#L38

What I found so far when opening in a regular browser:

  • There is an element with id="document-container".
  • In readonly mode, this element has a "readonly" class, and no "notebookbar-active" class.
  • In edit mode, this element has a "notebookbar-active" class, and no "readonly" class.

However, for some reason, in a test, the 'readonly' class won't go away when I open in edit mode, even though the "notebookbar-active" class does appear.

Is there a more reliable way to make this distinction?
Ideally a way that appears immediately on page load, without too much waiting.

@donquixote
Copy link
Collaborator Author

@hfiguiere Any thoughts on this one?

@donquixote
Copy link
Collaborator Author

I figured out how to do it :)

        // Verify the read-only mode.
        $readonly_indicator = $this->assertWaitForElement('.status-readonly-mode');
        $this->assertSame('Read-only', $readonly_indicator->getText());
        // Verify the edit mode.
        // The button is always present when in edit mode, but it is only
        // visible on a mobile / touch device.
        $this->assertWaitForElement('#mobile-edit-button');
    protected function assertWaitForElement(string|array $locator, string $selector = 'css'): NodeElement {
        $element = $this->assertSession()->waitForElement($selector, $locator);
        $this->assertNotNull($element, "The '$selector' element was not found after 10 seconds.");
        return $element;
    }

@hfiguiere
Copy link
Collaborator

This is probably subject to breaking in future versions.

@donquixote
Copy link
Collaborator Author

This is probably subject to breaking in future versions.

When it happens we can change the tests accordingly.
Even better would be to have a more reliable marker that is designed for this purpose.

@hfiguiere
Copy link
Collaborator

I have added this to the list. So yes, in the meantime this is probably the best way to go about it.

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

No branches or pull requests

2 participants