ironstar-io / testcafe-drupal

A repo containing basic TestCafe config and tests for Drupal installations
MIT License
1 stars 1 forks source link

Reliable test for confirming that a node has been saved #2

Open Benjen opened 5 years ago

Benjen commented 5 years ago

It would be good to have a generic test which can be used to determine if a node has been saved. The default behaviour in Drupal is to take the user to the view node page (e.g. /node/123) after the saving the node.

In the original Drupal Testcafe (DT) prototype, I created a Node.checkOnNodePage() method which looks for body level classes to confirm the user is on the view node page.

async checkOnNodePage() {
  const nodePageExists = Selector(
    "body.page-node-type-" + this.nodeType.replace(/_/g, "-")
  ).exists;

  await this.t.expect(nodePageExists).ok();
}

However, I have found that this class is not always present.

I was considering changing this to check the URI instead:

async checkOnViewNodePage() {
  const viewNodePagePathPattern = /\/node\/[0-9]*$/;

  await this.t.expect(system.getPath()).match(viewNodePagePathPattern);
}

However, this introduces its own problems. For example is URL aliases are enabled for the content type then after saving the, the user is redirected to the alias URI (e.g. /my/new/article).

Need to consider other options

Benjen commented 5 years ago

One option could be to use the shortlink property in the response or the <head> element:

<link rel="shortlink" href="https://172.31.0.10:8443/node/4">