Add test coverage (#23341)

This commit is contained in:
Michael Telatynski 2022-09-23 09:42:03 +01:00 committed by GitHub
parent 31b4dae26b
commit 5ec96f5abe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 729 additions and 15 deletions

View file

@ -14,7 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { mocked } from "jest-mock";
import PWAPlatform from "../../../../src/vector/platform/PWAPlatform";
import WebPlatform from "../../../../src/vector/platform/WebPlatform";
jest.mock("../../../../src/vector/platform/WebPlatform");
describe('PWAPlatform', () => {
beforeEach(() => {
@ -29,5 +34,29 @@ describe('PWAPlatform', () => {
platform.setNotificationCount(123);
expect(navigator.setAppBadge).toHaveBeenCalledWith(123);
});
it("should no-op if the badge count isn't changing", () => {
navigator.setAppBadge = jest.fn().mockResolvedValue(undefined);
const platform = new PWAPlatform();
platform.setNotificationCount(123);
expect(navigator.setAppBadge).toHaveBeenCalledTimes(1);
platform.setNotificationCount(123);
expect(navigator.setAppBadge).toHaveBeenCalledTimes(1);
});
it("should fall back to WebPlatform::setNotificationCount if no Navigator::setAppBadge", () => {
navigator.setAppBadge = undefined;
const platform = new PWAPlatform();
const superMethod = mocked(WebPlatform.prototype.setNotificationCount);
expect(superMethod).not.toHaveBeenCalled();
platform.setNotificationCount(123);
expect(superMethod).toHaveBeenCalledWith(123);
});
it("should handle Navigator::setAppBadge rejecting gracefully", () => {
navigator.setAppBadge = jest.fn().mockRejectedValue(new Error);
const platform = new PWAPlatform();
expect(() => platform.setNotificationCount(123)).not.toThrow();
});
});
});