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

Improve webchat code tests #2389

Open
andysellick opened this issue Mar 10, 2022 · 0 comments
Open

Improve webchat code tests #2389

andysellick opened this issue Mar 10, 2022 · 0 comments

Comments

@andysellick
Copy link
Contributor

The webchat tests could be more comprehensive (discovered while removing the jQuery from webchat).

We don't test that the webchat has successfully been initialised. When the user clicks on the 'start webchat' button, the following code determines whether the webchat should open in a popup window, or redirect the current page to the webchat (the popup is the default action).

redirect === 'true' ? window.location.href = openUrl : window.open(openUrl, 'newwin', 'width=366,height=516')

We should be able to test this by using a jasmine spyOn the window object, but this doesn't appear to work (a limitation of jasmine or the uniqueness of the window object, perhaps). Instead, we could abstract the calls that do this into separate functions, something like this:

redirect === 'true' ? this.changeWindowHref(openUrl) : this.windowOpen(openUrl, 'newwin', 'width=366,height=516')

...

this.changeWindowHref = function (url) {
   window.location.href = url
}

this.windowOpen = function (url, name, options) {
  window.open(url, name, options)
}

...and then spying on these two new functions in the test. Spying automatically blocks the function from executing, so we'd test that the correct thing had happened (either redirecting or opening a popup) in the right context, but not actually do anything.

Unfortunately this won't work because the webchat code isn't structured as a module, so we can't do spyOn(module, 'changeWindowHref'). In order to write this test we would need to rewrite the webchat code as a structured module where this is possible.

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

1 participant