summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/changes/test/browser_changes_declaration_rename.js
blob: 245ce5012129415010091d601aad44fefb57d0dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that renaming the property of a CSS declaration in the Rule view is tracked.

const TEST_URI = `
  <style type='text/css'>
    div {
      color: red;
    }
  </style>
  <div></div>
`;

add_task(async function () {
  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
  const { inspector, view: ruleView } = await openRuleView();
  const { document: doc, store } = selectChangesView(inspector);

  await selectNode("div", inspector);
  const prop = getTextProperty(ruleView, 1, { color: "red" });

  let onTrackChange;

  const oldPropertyName = "color";
  const newPropertyName = "background-color";

  info(`Rename the CSS declaration name to ${newPropertyName}`);
  onTrackChange = waitForDispatch(store, "TRACK_CHANGE");
  await renameProperty(ruleView, prop, newPropertyName);
  info("Wait for the change to be tracked");
  await onTrackChange;

  const removeDecl = getRemovedDeclarations(doc);
  const addDecl = getAddedDeclarations(doc);

  is(removeDecl.length, 1, "One declaration tracked as removed");
  is(
    removeDecl[0].property,
    oldPropertyName,
    `Removed declaration has old property name: ${oldPropertyName}`
  );
  is(addDecl.length, 1, "One declaration tracked as added");
  is(
    addDecl[0].property,
    newPropertyName,
    `Added declaration has new property name: ${newPropertyName}`
  );

  info(
    `Reverting the CSS declaration name to ${oldPropertyName} should clear changes.`
  );
  onTrackChange = waitForDispatch(store, "TRACK_CHANGE");
  await renameProperty(ruleView, prop, oldPropertyName);
  info("Wait for the change to be tracked");
  await onTrackChange;

  await waitFor(
    () => !getRemovedDeclarations(doc).length,
    "No declaration tracked as removed"
  );
  await waitFor(
    () => !getAddedDeclarations(doc).length,
    "No declaration tracked as added"
  );
});