mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-25 02:40:22 -10:00
- mochitest folder is renamed browser. - unit folder is rename xpcshell. - all the file and folder for mocha are put in a node folder. We take this as an opportunity to revist our stub-generating mochitests. Previously we had 2 tests for each kind of stubs, one for check, the other one for updating. It was not ideal when you wanted to update all the stubs at once because you add either to mention every 5 files, or unskip the update test files. We now merge the update and the check files in a single test. By default, the test that the stubs are up to date, and if you pass the --setenv WEBCONSOLE_STUBS_UPDATE=true param, it will update the stubs. This allow us to move the function that actually generate the stub in the test file, and have a helper file for multi-purpose functions. Because these tests are failing on TRY, let's disabled them so we can land the test re-organization (we'll re-enable them in Bug 1572667). Differential Revision: https://phabricator.services.mozilla.com/D41344
119 lines
3.4 KiB
JavaScript
119 lines
3.4 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||
"use strict";
|
||
|
||
// Test utils.
|
||
const expect = require("expect");
|
||
const { render, mount } = require("enzyme");
|
||
const sinon = require("sinon");
|
||
|
||
// React
|
||
const { createFactory } = require("devtools/client/shared/vendor/react");
|
||
const Provider = createFactory(require("react-redux").Provider);
|
||
const { setupStore } = require("devtools/client/webconsole/test/node/helpers");
|
||
|
||
// Components under test.
|
||
const CSSWarning = require("devtools/client/webconsole/components/Output/message-types/CSSWarning");
|
||
const {
|
||
MESSAGE_OPEN,
|
||
MESSAGE_CLOSE,
|
||
} = require("devtools/client/webconsole/constants");
|
||
|
||
// Test fakes.
|
||
const {
|
||
stubPreparedMessages,
|
||
} = require("devtools/client/webconsole/test/node/fixtures/stubs/index");
|
||
const serviceContainer = require("devtools/client/webconsole/test/node/fixtures/serviceContainer");
|
||
|
||
describe("CSSWarning component:", () => {
|
||
it("renders", () => {
|
||
const message = stubPreparedMessages.get(
|
||
"Unknown property ‘such-unknown-property’. Declaration dropped."
|
||
);
|
||
const wrapper = render(
|
||
CSSWarning({
|
||
message,
|
||
serviceContainer,
|
||
timestampsVisible: true,
|
||
})
|
||
);
|
||
const {
|
||
timestampString,
|
||
} = require("devtools/client/webconsole/utils/l10n");
|
||
|
||
expect(wrapper.find(".timestamp").text()).toBe(
|
||
timestampString(message.timeStamp)
|
||
);
|
||
|
||
expect(wrapper.find(".message-body").text()).toBe(
|
||
"Unknown property ‘such-unknown-property’. Declaration dropped."
|
||
);
|
||
|
||
// There shouldn't be a matched elements label rendered by default.
|
||
const elementLabel = wrapper.find(`.elements-label`);
|
||
expect(elementLabel.length).toBe(0);
|
||
|
||
// There should be a location.
|
||
const locationLink = wrapper.find(`.message-location`);
|
||
expect(locationLink.length).toBe(1);
|
||
expect(locationLink.text()).toBe("test-css-message.html:3:27");
|
||
});
|
||
|
||
it("closes an open message when the collapse button is clicked", () => {
|
||
const store = setupStore();
|
||
store.dispatch = sinon.spy();
|
||
const message = stubPreparedMessages.get(
|
||
"Unknown property ‘such-unknown-property’. Declaration dropped."
|
||
);
|
||
|
||
const wrapper = mount(
|
||
Provider(
|
||
{ store },
|
||
CSSWarning({
|
||
message,
|
||
open: true,
|
||
dispatch: store.dispatch,
|
||
serviceContainer,
|
||
})
|
||
)
|
||
);
|
||
|
||
wrapper.find(".collapse-button[aria-expanded='true']").simulate("click");
|
||
|
||
const call = store.dispatch.getCall(0);
|
||
expect(call.args[0]).toEqual({
|
||
id: message.id,
|
||
type: MESSAGE_CLOSE,
|
||
});
|
||
});
|
||
|
||
it("opens a closed message when the collapse button is clicked", () => {
|
||
const store = setupStore();
|
||
store.dispatch = sinon.spy();
|
||
const message = stubPreparedMessages.get(
|
||
"Unknown property ‘such-unknown-property’. Declaration dropped."
|
||
);
|
||
|
||
const wrapper = mount(
|
||
Provider(
|
||
{ store },
|
||
CSSWarning({
|
||
message,
|
||
open: false,
|
||
payload: {}, // fake the existence of a payload to test just MESSAGE_OPEN action
|
||
dispatch: store.dispatch,
|
||
serviceContainer,
|
||
})
|
||
)
|
||
);
|
||
|
||
wrapper.find(".collapse-button[aria-expanded='false']").simulate("click");
|
||
|
||
const call = store.dispatch.getCall(0);
|
||
expect(call.args[0]).toEqual({
|
||
id: message.id,
|
||
type: MESSAGE_OPEN,
|
||
});
|
||
});
|
||
});
|