Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _test/images_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
referenced_images = Set.new

markdown_files.each do |file|
content = File.read(file)
content = File.read(file, encoding: 'UTF-8')
content.scan(/\!\[.*?\]\((.*?)\)/).each do |match| # Match Markdown image syntax ![alt](path)
referenced_images << match[0]
end
Expand Down
6 changes: 3 additions & 3 deletions _test/posts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
affected = []

Dir.glob('content/**/*.md').each do |path|
File.readlines(path).each do |line|
File.readlines(path, encoding: 'UTF-8').each do |line|
affected << [path, line] if regexp.match(line)
end
end
Expand All @@ -42,7 +42,7 @@
Dir.glob('content/**/*.md').each do |path|
next unless File.file?(path)

File.readlines(path).each do |line|
File.readlines(path, encoding: 'UTF-8').each do |line|
affected << [path, line] if regexp.match(line)
end
end
Expand All @@ -62,7 +62,7 @@
Dir.glob('content/articles/*.{md,markdown}').each do |path|
next unless File.file?(path)

File.readlines(path).each do |line|
File.readlines(path, encoding: 'UTF-8').each do |line|
line.scan(regexp) do |matches|
matches.each do |match|
next unless File.extname(match) == '' # linked to a file
Expand Down
6 changes: 5 additions & 1 deletion _widget/src/recently-visited.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { browserLocation } from './utils/browserLocation.js';

export default (widget) => {
const { origin, pathname, href } = window.location;
const href = browserLocation.getHref();
const url = new URL(href);
const { origin, pathname } = url;

if (!['https://support.dnsimple.com', 'https://developer.dnsimple.com'].includes(origin)) return;

Expand Down
11 changes: 11 additions & 0 deletions _widget/src/utils/browserLocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// We cannot longer mock the window.location behavior.
// See: https://github.com/dnsimple/dnsimple-app/pull/30841#issuecomment-2980551906

export const browserLocation = {
getHref: () => window.location.href,
setHref: (url) => { window.location.href = url; },
assign: (url) => window.location.assign(url),
reload: () => window.location.reload(),
getSearch: () => window.location.search,
setSearch: (search) => { window.location.search = search; },
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"eslint-plugin-vue": "^9.33.0",
"globals": "^16.4.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-environment-jsdom": "^30.2.0",
"rollup-plugin-css-only": "^4.5.5",
"sass-embedded": "^1.93.2",
"tachyons": "^4.12.0",
Expand Down
47 changes: 23 additions & 24 deletions spec/_widget/components/recently-visited.spec.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
import storeRecentlyVisited from '../../../_widget/src/recently-visited.js';
// Mock the browserLocation module first
const mockBrowserLocation = {
getHref: jest.fn(),
setHref: jest.fn(),
assign: jest.fn(),
reload: jest.fn(),
getSearch: jest.fn(() => ''),
setSearch: jest.fn(),
};

jest.mock('../../../_widget/src/utils/browserLocation.js', () => ({
browserLocation: mockBrowserLocation
}));

// Import after mocking
const storeRecentlyVisited = require('../../../_widget/src/recently-visited.js').default;

describe('storeRecentlyVisited', () => {
let widget;

beforeEach(() => {
widget = { storeRecentlyVisited: jest.fn() };
mockBrowserLocation.getHref.mockReturnValue('https://support.dnsimple.com/articles/example-article');
});

it('delegates to the widget if visiting a support article', () => {
const location = {
origin: 'https://support.dnsimple.com',
pathname: '/articles/example-article',
href: 'https://support.dnsimple.com/articles/example-article'
};
Object.defineProperty(window, "location", { value: location });
mockBrowserLocation.getHref.mockReturnValue('https://support.dnsimple.com/articles/example-article');

storeRecentlyVisited(widget);

expect(widget.storeRecentlyVisited).toHaveBeenCalledWith(location.href);
expect(widget.storeRecentlyVisited).toHaveBeenCalledWith('https://support.dnsimple.com/articles/example-article');
});

it('delegates to the widget if visiting a developer article', () => {
const location = {
origin: 'https://developer.dnsimple.com',
pathname: '/articles/example-article',
href: 'https://developer.dnsimple.com/articles/example-article'
};
Object.defineProperty(window, "location", { value: location });
mockBrowserLocation.getHref.mockReturnValue('https://developer.dnsimple.com/articles/example-article');

storeRecentlyVisited(widget);

expect(widget.storeRecentlyVisited).toHaveBeenCalledWith(location.href);
expect(widget.storeRecentlyVisited).toHaveBeenCalledWith('https://developer.dnsimple.com/articles/example-article');
});

it('does not delegate to the widget if not in the support or developer site', () => {
const location = {
origin: 'https://other.dnsimple.com',
};
Object.defineProperty(window, "location", { value: location });
mockBrowserLocation.getHref.mockReturnValue('https://other.dnsimple.com/articles/example-article');

storeRecentlyVisited(widget);

expect(widget.storeRecentlyVisited).not.toHaveBeenCalled();
});

it('does not delegate to the widget if not visiting a support article', () => {
const location = {
origin: 'https://support.dnsimple.com',
pathname: '/categories/example-category',
};
Object.defineProperty(window, "location", { value: location });
mockBrowserLocation.getHref.mockReturnValue('https://support.dnsimple.com/categories/example-category');

storeRecentlyVisited(widget);

Expand Down
14 changes: 14 additions & 0 deletions spec/utils/browserLocationStub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// We cannot longer mock the window.location behavior.
// See: https://github.com/dnsimple/dnsimple-app/pull/30841#issuecomment-2980551906

let currentHref = 'https://support.dnsimple.com/articles/example-article';
let currentSearch = '?hello=world';

export const browserLocation = {
getHref: jest.fn(() => currentHref),
setHref: jest.fn((url) => { currentHref = url; }),
assign: jest.fn(),
reload: jest.fn(),
getSearch: jest.fn(() => currentSearch),
setSearch: jest.fn((search) => { currentSearch = search; }),
};
Loading